from django.db import models

from django.db import models
from django.utils.translation import ugettext as _
# from django.core.urlresolvers import reverse_lazy, reverse
from django.conf import settings

from projects.models import Project, Customer

class Report (models.Model):

    HIGHLIGHT  = 'HL'
    LOWLIGHT   = 'LL'
    ESCALATION = 'XS'

    LIGHTS = (
        (HIGHLIGHT, _('Highlight')),
        (LOWLIGHT,  _('Lowlight')), 
        (ESCALATION,_('Escalation')),
    )    


    year     = models.PositiveIntegerField (null=False, blank=False,
        verbose_name=_("year"))

    period   = models.PositiveIntegerField (null=False, blank=False,
        verbose_name=_("period"))

    light    = models.CharField (max_length=2, choices=LIGHTS, default=HIGHLIGHT)

    description = models.TextField (null=False, blank=True, verbose_name=_("description"))

    created     = models.DateTimeField (auto_now_add=True)
    created_by  = models.ForeignKey (settings.AUTH_USER_MODEL, related_name='+',  editable=False)
    modified    = models.DateTimeField (auto_now=True)
    modified_by = models.ForeignKey (settings.AUTH_USER_MODEL, related_name='+', editable=False)

    class Meta:
        verbose_name = _('Report')
        verbose_name_plural = _('Reports')
        ordering = ['light','project','category']
        unique_together = ("target", "year", "period")

        abstract = True

    def __str__(self):
        return self.title
        return mark_safe("<b>%s</b>: %s" % (self.project, self.title))

    # def get_absolute_url (self):
    #     return reverse('reporting-detail', args=[str(self.id)])

class ProjectReport (Report):
    target  = models.ForeignKey (Project, related_name='reports')

    class Meta:
        verbose_name = _('Project report')
        verbose_name_plural = _('Project reports')

class CustomerReport (Report):
    target = models.ForeignKey (Customer, related_name='reports')

    class Meta:
        verbose_name = _('Customer report')
        verbose_name_plural = _('Customer reports')
        #return str(self.project) + (self.title if len(self.title) < 30 else (self.title[:27]+'...'))
