# Path: locksmith/hub/models.py
# class Api(models.Model):
#     '''
#         API that Keys are issued to and Reports come from
#     '''
#     name = models.CharField(max_length=30)
#     signing_key = models.CharField(max_length=32)
#     url = models.URLField()
#     push_enabled = models.BooleanField(default=True)
#     description = models.TextField('Description', blank=True)
#     status = models.IntegerField(choices=API_OPERATING_STATUSES, default=1)
#     mode = models.IntegerField(choices=list(API_STATUSES), default=1)
#     status_message = models.TextField('A more detailed status message', null=True, blank=True)
#     display_name = models.TextField('Display name of the API', blank=False, null=True)
#     documentation_link = models.TextField('Link to this API\'s documentation', null=True, blank=True)
#     tools_text = models.TextField('Tools this API powers', null=True, blank=True)
#     tags = TaggableManager(blank=True)
#     querybuilder_link = models.TextField('Link to this API\'s query builder page', null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         db_table = 'locksmith_hub_api'
# 
# class Key(models.Model):
#     '''
#         API key to be handed out to Apis
#     '''
#     user = models.OneToOneField(User, null=True, blank=True, related_name='api_key')
# 
#     key = models.CharField(max_length=32, db_index=True)
#     email = models.EmailField(unique=True)
#     alternate_email = models.EmailField(blank=True, null=True) #
#     status = models.CharField(max_length=1, choices=KEY_STATUSES, default='U')
# 
#     name = models.CharField('Name', max_length=100, blank=True, null=True,
#                             db_index=True)
#     org_name = models.CharField('Organization Name', max_length=100,
#                                 blank=True, null=True, db_index=True)
#     org_url = models.CharField('Organization URL', blank=True, null=True,
#                                max_length=200, db_index=True)
#     usage = models.TextField('Intended Usage', blank=True, null=True)
# 
#     promotable = models.BooleanField(default=False)
#     issued_on = models.DateTimeField(default=datetime.datetime.now, editable=False)
# 
#     def __unicode__(self):
#         return '%s %s [%s]' % (self.key, self.email, self.status)
# 
#     def mark_for_update(self):
#         '''
#             Note that a change has been made so all Statuses need update
#         '''
#         self.pub_statuses.exclude(status=UNPUBLISHED).update(status=NEEDS_UPDATE)
#         push_key.delay(self)
# 
#     class Meta:
#         db_table = 'locksmith_hub_key'


from django.contrib import admin
from locksmith.hub.models import Api, Key

class ApiAdmin(admin.ModelAdmin):
    list_display = ('name', 'url', 'push_enabled')

admin.site.register(Api, ApiAdmin)

class KeyAdmin(admin.ModelAdmin):
    list_display = ('key', 'status', 'email', 'name', 'org_name', 'org_url')
    search_fields = ('key', 'email', 'name', 'org_name')

    def save_model(self, request, obj, form, change):
        obj.save()
        obj.mark_for_update()


# Path: locksmith/hub/models.py
# class Api(models.Model):
#     '''
#         API that Keys are issued to and Reports come from
#     '''
#     name = models.CharField(max_length=30)
#     signing_key = models.CharField(max_length=32)
#     url = models.URLField()
#     push_enabled = models.BooleanField(default=True)
#     description = models.TextField('Description', blank=True)
#     status = models.IntegerField(choices=API_OPERATING_STATUSES, default=1)
#     mode = models.IntegerField(choices=list(API_STATUSES), default=1)
#     status_message = models.TextField('A more detailed status message', null=True, blank=True)
#     display_name = models.TextField('Display name of the API', blank=False, null=True)
#     documentation_link = models.TextField('Link to this API\'s documentation', null=True, blank=True)
#     tools_text = models.TextField('Tools this API powers', null=True, blank=True)
#     tags = TaggableManager(blank=True)
#     querybuilder_link = models.TextField('Link to this API\'s query builder page', null=True, blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         db_table = 'locksmith_hub_api'
# 
# class Key(models.Model):
#     '''
#         API key to be handed out to Apis
#     '''
#     user = models.OneToOneField(User, null=True, blank=True, related_name='api_key')
# 
#     key = models.CharField(max_length=32, db_index=True)
#     email = models.EmailField(unique=True)
#     alternate_email = models.EmailField(blank=True, null=True) #
#     status = models.CharField(max_length=1, choices=KEY_STATUSES, default='U')
# 
#     name = models.CharField('Name', max_length=100, blank=True, null=True,
#                             db_index=True)
#     org_name = models.CharField('Organization Name', max_length=100,
#                                 blank=True, null=True, db_index=True)
#     org_url = models.CharField('Organization URL', blank=True, null=True,
#                                max_length=200, db_index=True)
#     usage = models.TextField('Intended Usage', blank=True, null=True)
# 
#     promotable = models.BooleanField(default=False)
#     issued_on = models.DateTimeField(default=datetime.datetime.now, editable=False)
# 
#     def __unicode__(self):
#         return '%s %s [%s]' % (self.key, self.email, self.status)
# 
#     def mark_for_update(self):
#         '''
#             Note that a change has been made so all Statuses need update
#         '''
#         self.pub_statuses.exclude(status=UNPUBLISHED).update(status=NEEDS_UPDATE)
#         push_key.delay(self)
# 
#     class Meta:
#         db_table = 'locksmith_hub_key'


# Path: locksmith/hub/admin.py
from django.contrib import admin
from locksmith.hub.models import Api, Key


class ApiAdmin(admin.ModelAdmin):
    list_display = ('name', 'url', 'push_enabled')

admin.site.register(Api, ApiAdmin)

class KeyAdmin(admin.ModelAdmin):
    list_display = ('key', 'status', 'email', 'name', 'org_name', 'org_url')
    search_fields = ('key', 'email', 'name', 'org_name')

    def save_model(self, request, obj, form, change):
        obj.save()
        obj.mark_for_update()


admin.site.register(Key, KeyAdmin)