bgneal@285: """ bgneal@285: Models for the oembed application. bgneal@285: """ bgneal@285: import datetime bgneal@285: bgneal@285: from django.db import models bgneal@285: bgneal@285: bgneal@285: class Provider(models.Model): bgneal@285: """ bgneal@285: This model described an oEmbed provider. bgneal@285: """ bgneal@285: JSON, XML = range(2) bgneal@285: FORMAT_CHOICES = ( bgneal@285: (JSON, "json"), bgneal@285: (XML, "xml"), bgneal@285: ) bgneal@285: bgneal@285: name = models.CharField(max_length=128) bgneal@285: api_endpoint = models.URLField(max_length=255, verify_exists=False, bgneal@285: verbose_name='API endpoint') bgneal@285: url_regex = models.CharField(max_length=255, verbose_name='URL regex') bgneal@285: format = models.IntegerField(choices=FORMAT_CHOICES) bgneal@285: bgneal@285: def __unicode__(self): bgneal@285: return self.name bgneal@285: bgneal@285: bgneal@285: class Oembed(models.Model): bgneal@285: """ bgneal@285: This model represents stored embedded content retrieved from an oEmbed bgneal@285: provider. bgneal@285: """ bgneal@285: PHOTO, VIDEO, LINK, RICH = range(4) bgneal@285: MEDIA_TYPE_CHOICES = ( bgneal@285: (PHOTO, "photo"), bgneal@285: (VIDEO, "video"), bgneal@285: (LINK, "link"), bgneal@285: (RICH, "rich"), bgneal@285: ) bgneal@285: bgneal@285: url = models.URLField(max_length=255, verify_exists=False, db_index=True) bgneal@285: type = models.IntegerField(choices=MEDIA_TYPE_CHOICES) bgneal@285: title = models.CharField(max_length=255, blank=True, default='') bgneal@285: width = models.IntegerField() bgneal@285: height = models.IntegerField() bgneal@285: html = models.TextField() bgneal@285: date_added = models.DateTimeField() bgneal@285: bgneal@285: def __unicode__(self): bgneal@285: return self.title or self.url bgneal@285: bgneal@285: def save(self, *args, **kwargs): bgneal@285: if not self.pk: bgneal@285: self.date_added = datetime.datetime.now() bgneal@285: bgneal@285: super(Oembed, self).save(*args, **kwargs) bgneal@285: