# Path: status/models.py
# 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 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'


from tastypie.authentication import ApiKeyAuthentication
from tastypie.authorization import Authorization
from tastypie.resources import NamespacedModelResource, fields, ALL, ALL_WITH_RELATIONS
from django.contrib.auth.models import User #BUG: Import the correct user object from settings.py
from .models import Incident, Status
import logging


logger = logging.getLogger(__name__)


class ReadOnlyFieldNamespacedModelResource(NamespacedModelResource):
    """ Allows you to add a 'readonly_fields' setting on a ModelResource """
    def __init__(self, **kwargs):
        super(ReadOnlyFieldNamespacedModelResource, self).__init__(**kwargs)
        for fld in getattr(self.Meta, 'readonly_fields', []):
            self.fields[fld].readonly = True


class StatusResource(ReadOnlyFieldNamespacedModelResource):
    class Meta:
        detail_uri_name = 'name'

# Path: status/models.py
# 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 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'


# Path: status/api.py
from tastypie.authentication import ApiKeyAuthentication
from tastypie.authorization import Authorization
from tastypie.resources import NamespacedModelResource, fields, ALL, ALL_WITH_RELATIONS
from django.contrib.auth.models import User #BUG: Import the correct user object from settings.py
from .models import Incident, Status
import logging



logger = logging.getLogger(__name__)


class ReadOnlyFieldNamespacedModelResource(NamespacedModelResource):
    """ Allows you to add a 'readonly_fields' setting on a ModelResource """
    def __init__(self, **kwargs):
        super(ReadOnlyFieldNamespacedModelResource, self).__init__(**kwargs)
        for fld in getattr(self.Meta, 'readonly_fields', []):
            self.fields[fld].readonly = True


class StatusResource(ReadOnlyFieldNamespacedModelResource):
    class Meta:
        detail_uri_name = 'name'

        queryset = Status.objects.all()