Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
284:df2c81f705a8 | 285:8fd4984d5c3b |
---|---|
1 """ | |
2 Models for the oembed application. | |
3 """ | |
4 import datetime | |
5 | |
6 from django.db import models | |
7 | |
8 | |
9 class Provider(models.Model): | |
10 """ | |
11 This model described an oEmbed provider. | |
12 """ | |
13 JSON, XML = range(2) | |
14 FORMAT_CHOICES = ( | |
15 (JSON, "json"), | |
16 (XML, "xml"), | |
17 ) | |
18 | |
19 name = models.CharField(max_length=128) | |
20 api_endpoint = models.URLField(max_length=255, verify_exists=False, | |
21 verbose_name='API endpoint') | |
22 url_regex = models.CharField(max_length=255, verbose_name='URL regex') | |
23 format = models.IntegerField(choices=FORMAT_CHOICES) | |
24 | |
25 def __unicode__(self): | |
26 return self.name | |
27 | |
28 | |
29 class Oembed(models.Model): | |
30 """ | |
31 This model represents stored embedded content retrieved from an oEmbed | |
32 provider. | |
33 """ | |
34 PHOTO, VIDEO, LINK, RICH = range(4) | |
35 MEDIA_TYPE_CHOICES = ( | |
36 (PHOTO, "photo"), | |
37 (VIDEO, "video"), | |
38 (LINK, "link"), | |
39 (RICH, "rich"), | |
40 ) | |
41 | |
42 url = models.URLField(max_length=255, verify_exists=False, db_index=True) | |
43 type = models.IntegerField(choices=MEDIA_TYPE_CHOICES) | |
44 title = models.CharField(max_length=255, blank=True, default='') | |
45 width = models.IntegerField() | |
46 height = models.IntegerField() | |
47 html = models.TextField() | |
48 date_added = models.DateTimeField() | |
49 | |
50 def __unicode__(self): | |
51 return self.title or self.url | |
52 | |
53 def save(self, *args, **kwargs): | |
54 if not self.pk: | |
55 self.date_added = datetime.datetime.now() | |
56 | |
57 super(Oembed, self).save(*args, **kwargs) | |
58 |