# Path: oembed/models.py
# class StoredProvider(models.Model, HTTPProvider):
#     """
#     Essentially, a stored proxy provider that mimics the interface of a python
#     HTTPProvider - used for autodiscovery
#     """
#     endpoint_url = models.CharField(max_length=255)
#     regex = models.CharField(max_length=255)
#     wildcard_regex = models.CharField(max_length=255, blank=True,
#         help_text='Wild-card version of regex')
#     resource_type = models.CharField(choices=RESOURCE_CHOICES, max_length=8)
#     active = models.BooleanField(default=False)
#     provides = models.BooleanField(default=False, help_text='Provide upstream')
#     scheme_url = models.CharField(max_length=255, blank=True)
# 
#     objects = StoredProviderManager()
# 
#     class Meta:
#         ordering = ('endpoint_url', 'resource_type', 'wildcard_regex')
# 
#     def __unicode__(self):
#         return self.wildcard_regex
# 
#     def save(self, *args, **kwargs):
#         if not self.regex:
#             # convert wildcard to non-greedy 'match anything' regex
#             self.regex = self.wildcard_regex.replace('*', '.+?')
#         super(StoredProvider, self).save(*args, **kwargs)
# 
#     @property
#     def url_scheme(self):
#         if self.provides and self.wildcard_regex:
#             return self.wildcard_regex
# 
# class StoredOEmbed(models.Model):
#     match = models.TextField()
#     response_json = models.TextField()
#     resource_type = models.CharField(choices=RESOURCE_CHOICES, editable=False, max_length=8)
#     date_added = models.DateTimeField(auto_now_add=True)
#     date_expires = models.DateTimeField(blank=True, null=True)
#     maxwidth = models.IntegerField(blank=True, null=True)
#     maxheight = models.IntegerField(blank=True, null=True)
# 
#     # generic bits
#     object_id = models.IntegerField(blank=True, null=True)
#     content_type = models.ForeignKey(ContentType, blank=True, null=True,
#             related_name="related_%(class)s")
#     content_object = GenericForeignKey()
# 
#     class Meta:
#         ordering = ('-date_added',)
#         verbose_name = 'stored OEmbed'
#         verbose_name_plural = 'stored OEmbeds'
#         if 'mysql' not in db_engine:
#             unique_together = ('match', 'maxwidth', 'maxheight')
# 
#     def __unicode__(self):
#         return self.match
#     
#     @property
#     def response(self):
#         return simplejson.loads(self.response_json)


from django.contrib import admin
from oembed.models import StoredProvider, StoredOEmbed


class StoredProviderAdmin(admin.ModelAdmin):
    list_display = ('wildcard_regex', 'endpoint_url', 'active', 'provides')
    list_filter = ('active', 'provides')

    actions = ['activate', 'deactivate']

    def activate(self, request, queryset):
        for item in queryset:
            item.active = True
            item.save()
    activate.short_description = "Activate selected Stored Providers"

    def deactivate(self, request, queryset):
        for item in queryset:
            item.active = False

# Path: oembed/models.py
# class StoredProvider(models.Model, HTTPProvider):
#     """
#     Essentially, a stored proxy provider that mimics the interface of a python
#     HTTPProvider - used for autodiscovery
#     """
#     endpoint_url = models.CharField(max_length=255)
#     regex = models.CharField(max_length=255)
#     wildcard_regex = models.CharField(max_length=255, blank=True,
#         help_text='Wild-card version of regex')
#     resource_type = models.CharField(choices=RESOURCE_CHOICES, max_length=8)
#     active = models.BooleanField(default=False)
#     provides = models.BooleanField(default=False, help_text='Provide upstream')
#     scheme_url = models.CharField(max_length=255, blank=True)
# 
#     objects = StoredProviderManager()
# 
#     class Meta:
#         ordering = ('endpoint_url', 'resource_type', 'wildcard_regex')
# 
#     def __unicode__(self):
#         return self.wildcard_regex
# 
#     def save(self, *args, **kwargs):
#         if not self.regex:
#             # convert wildcard to non-greedy 'match anything' regex
#             self.regex = self.wildcard_regex.replace('*', '.+?')
#         super(StoredProvider, self).save(*args, **kwargs)
# 
#     @property
#     def url_scheme(self):
#         if self.provides and self.wildcard_regex:
#             return self.wildcard_regex
# 
# class StoredOEmbed(models.Model):
#     match = models.TextField()
#     response_json = models.TextField()
#     resource_type = models.CharField(choices=RESOURCE_CHOICES, editable=False, max_length=8)
#     date_added = models.DateTimeField(auto_now_add=True)
#     date_expires = models.DateTimeField(blank=True, null=True)
#     maxwidth = models.IntegerField(blank=True, null=True)
#     maxheight = models.IntegerField(blank=True, null=True)
# 
#     # generic bits
#     object_id = models.IntegerField(blank=True, null=True)
#     content_type = models.ForeignKey(ContentType, blank=True, null=True,
#             related_name="related_%(class)s")
#     content_object = GenericForeignKey()
# 
#     class Meta:
#         ordering = ('-date_added',)
#         verbose_name = 'stored OEmbed'
#         verbose_name_plural = 'stored OEmbeds'
#         if 'mysql' not in db_engine:
#             unique_together = ('match', 'maxwidth', 'maxheight')
# 
#     def __unicode__(self):
#         return self.match
#     
#     @property
#     def response(self):
#         return simplejson.loads(self.response_json)


# Path: oembed/admin.py
from django.contrib import admin
from oembed.models import StoredProvider, StoredOEmbed



class StoredProviderAdmin(admin.ModelAdmin):
    list_display = ('wildcard_regex', 'endpoint_url', 'active', 'provides')
    list_filter = ('active', 'provides')

    actions = ['activate', 'deactivate']

    def activate(self, request, queryset):
        for item in queryset:
            item.active = True
            item.save()
    activate.short_description = "Activate selected Stored Providers"

    def deactivate(self, request, queryset):
        for item in queryset:
            item.active = False

            item.save()