diff gpp/oembed/models.py @ 285:8fd4984d5c3b

This is a first rough commit for #95, adding the ability to embed YouTube videos in forum posts. Some more polish and testing needs to happen at this point. I wanted to get all these changes off my hard drive and into the repository.
author Brian Neal <bgneal@gmail.com>
date Thu, 14 Oct 2010 02:39:35 +0000
parents
children 368d731af479
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/oembed/models.py	Thu Oct 14 02:39:35 2010 +0000
@@ -0,0 +1,58 @@
+"""
+Models for the oembed application.
+"""
+import datetime
+
+from django.db import models
+
+
+class Provider(models.Model):
+    """
+    This model described an oEmbed provider.
+    """
+    JSON, XML = range(2)
+    FORMAT_CHOICES = (
+        (JSON, "json"),
+        (XML, "xml"),
+    )
+
+    name = models.CharField(max_length=128)
+    api_endpoint = models.URLField(max_length=255, verify_exists=False,
+            verbose_name='API endpoint')
+    url_regex = models.CharField(max_length=255, verbose_name='URL regex')
+    format = models.IntegerField(choices=FORMAT_CHOICES)
+
+    def __unicode__(self):
+        return self.name
+
+
+class Oembed(models.Model):
+    """
+    This model represents stored embedded content retrieved from an oEmbed
+    provider.
+    """
+    PHOTO, VIDEO, LINK, RICH = range(4)
+    MEDIA_TYPE_CHOICES = (
+        (PHOTO, "photo"),
+        (VIDEO, "video"),
+        (LINK, "link"),
+        (RICH, "rich"),
+    )
+
+    url = models.URLField(max_length=255, verify_exists=False, db_index=True)
+    type = models.IntegerField(choices=MEDIA_TYPE_CHOICES)
+    title = models.CharField(max_length=255, blank=True, default='')
+    width = models.IntegerField()
+    height = models.IntegerField()
+    html = models.TextField()
+    date_added = models.DateTimeField()
+
+    def __unicode__(self):
+        return self.title or self.url
+
+    def save(self, *args, **kwargs):
+        if not self.pk:
+            self.date_added = datetime.datetime.now()
+
+        super(Oembed, self).save(*args, **kwargs)
+