# Path: status/models.py
# class Status(BaseModel):
#     """ Status of an incident or event """
#     name = models.CharField(max_length=50)
#     type = models.CharField(max_length=20, choices=STATUS_CHOICES, default='Information')
#     icon = models.CharField(max_length=255, help_text='Font Awesome icon name', default='fa-warning')
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = 'Status'
#         verbose_name_plural = 'Statuses'
# 
# class Incident(BaseModel):
#     """ Creates an incident.  Incidents are displayed at the top of the page until closed. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     name = models.CharField(max_length=255)
#     hidden = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.user, self.name)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.pk, ])
# 
#     def get_first_update(self):
#         try:
#             first = self.incidentupdate_set.first()
#         except IncidentUpdate.DoesNotExist:
#             first = None
#         return first
# 
#     def get_latest_update(self):
#         try:
#             latest = self.incidentupdate_set.latest()
#         except IncidentUpdate.DoesNotExist:
#             latest = None
#         return latest
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident'
#         verbose_name_plural = 'Incidents'
#         ordering = ['-created', ]
# 
# class IncidentUpdate(BaseModel):
#     """ Updates about an incident. """
#     incident = models.ForeignKey(Incident)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     status = models.ForeignKey(Status)
#     description = models.TextField()
# 
#     def __unicode__(self):
#         return "%s - %s: %s" % (self.user, self.status, self.description)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.incident.pk, ])
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident Update'
#         verbose_name_plural = 'Incident Updates'
#         ordering = ['created', ]
# 
#     def save(self, *args, **kwargs):
#         """ Update the parent incident update time too. """
#         self.incident.updated = timezone.now()
#         self.incident.save()
#         super(IncidentUpdate, self).save(*args, **kwargs)


from django.contrib import admin
from status.models import Status, Incident, IncidentUpdate


class BaseAdmin(admin.ModelAdmin):

    """ Base module inherited by all other admin modules to save time setting various defaults. """

    actions_on_top = True
    actions_on_bottom = True
    save_as = True
    save_on_top = True


@admin.register(Status)
class StatusAdmin(BaseAdmin):
    list_display = ['pk', 'name', 'type', 'icon']


class IncidentUpdateInline(admin.TabularInline):
    model = IncidentUpdate


@admin.register(Incident)
class IncidentAdmin(BaseAdmin):
    list_display = ['pk', 'created', 'updated', 'user', 'name', 'hidden']
    list_filter = ['user', 'hidden']
    inlines = [IncidentUpdateInline, ]



# Path: status/models.py
# class Status(BaseModel):
#     """ Status of an incident or event """
#     name = models.CharField(max_length=50)
#     type = models.CharField(max_length=20, choices=STATUS_CHOICES, default='Information')
#     icon = models.CharField(max_length=255, help_text='Font Awesome icon name', default='fa-warning')
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = 'Status'
#         verbose_name_plural = 'Statuses'
# 
# class Incident(BaseModel):
#     """ Creates an incident.  Incidents are displayed at the top of the page until closed. """
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     name = models.CharField(max_length=255)
#     hidden = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return "%s - %s" % (self.user, self.name)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.pk, ])
# 
#     def get_first_update(self):
#         try:
#             first = self.incidentupdate_set.first()
#         except IncidentUpdate.DoesNotExist:
#             first = None
#         return first
# 
#     def get_latest_update(self):
#         try:
#             latest = self.incidentupdate_set.latest()
#         except IncidentUpdate.DoesNotExist:
#             latest = None
#         return latest
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident'
#         verbose_name_plural = 'Incidents'
#         ordering = ['-created', ]
# 
# class IncidentUpdate(BaseModel):
#     """ Updates about an incident. """
#     incident = models.ForeignKey(Incident)
#     user = models.ForeignKey(settings.AUTH_USER_MODEL)
#     status = models.ForeignKey(Status)
#     description = models.TextField()
# 
#     def __unicode__(self):
#         return "%s - %s: %s" % (self.user, self.status, self.description)
# 
#     def get_absolute_url(self):
#         return reverse('status:incident_detail', args=[self.incident.pk, ])
# 
#     class Meta:
#         get_latest_by = 'created'
#         verbose_name = 'Incident Update'
#         verbose_name_plural = 'Incident Updates'
#         ordering = ['created', ]
# 
#     def save(self, *args, **kwargs):
#         """ Update the parent incident update time too. """
#         self.incident.updated = timezone.now()
#         self.incident.save()
#         super(IncidentUpdate, self).save(*args, **kwargs)


# Path: status/admin.py
from django.contrib import admin
from status.models import Status, Incident, IncidentUpdate



class BaseAdmin(admin.ModelAdmin):

    """ Base module inherited by all other admin modules to save time setting various defaults. """

    actions_on_top = True
    actions_on_bottom = True
    save_as = True
    save_on_top = True


@admin.register(Status)
class StatusAdmin(BaseAdmin):
    list_display = ['pk', 'name', 'type', 'icon']


class IncidentUpdateInline(admin.TabularInline):
    model = IncidentUpdate


@admin.register(Incident)
class IncidentAdmin(BaseAdmin):
    list_display = ['pk', 'created', 'updated', 'user', 'name', 'hidden']
    list_filter = ['user', 'hidden']
    inlines = [IncidentUpdateInline, ]



@admin.register(IncidentUpdate)