annotate podcast/models.py @ 1094:110bbc78a482

GCalendar V3 conversion in progress.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 May 2016 23:09:23 -0500
parents e932f2ecd4a7
children
rev   line source
bgneal@277 1 """
bgneal@277 2 Models for the podcast application.
bgneal@277 3
bgneal@277 4 """
bgneal@277 5 import datetime
gremmie@1 6
bgneal@1032 7 from django.core.urlresolvers import reverse
gremmie@1 8 from django.db import models
gremmie@1 9
bgneal@277 10
bgneal@1032 11 EXPLICIT_CHOICES = [
bgneal@1032 12 ('yes', 'Yes'),
bgneal@1032 13 ('no', 'No'),
bgneal@1032 14 ('clean', 'Clean'),
bgneal@1032 15 ]
gremmie@1 16
gremmie@1 17
gremmie@1 18 class Channel(models.Model):
bgneal@224 19 """Model to represent the Channel properties"""
gremmie@1 20
bgneal@224 21 title = models.CharField(max_length=255)
bgneal@572 22 link = models.URLField()
bgneal@224 23 language = models.CharField(max_length=16)
bgneal@224 24 copyright = models.CharField(max_length=255)
bgneal@224 25 subtitle = models.CharField(max_length=255)
bgneal@224 26 author = models.CharField(max_length=64)
bgneal@224 27 description = models.CharField(max_length=255)
bgneal@224 28 owner_name = models.CharField(max_length=64)
bgneal@224 29 owner_email = models.EmailField()
bgneal@224 30 image = models.ImageField(upload_to='podcast')
bgneal@224 31 category = models.CharField(max_length=64)
bgneal@224 32 explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
bgneal@224 33 keywords = models.CharField(max_length=255)
gremmie@1 34
bgneal@224 35 def __unicode__(self):
bgneal@224 36 return self.title
gremmie@1 37
gremmie@1 38
gremmie@1 39 class Item(models.Model):
bgneal@224 40 """Model to represent a channel item"""
bgneal@224 41 channel = models.ForeignKey(Channel)
bgneal@224 42 title = models.CharField(max_length=255)
bgneal@224 43 author = models.CharField(max_length=255)
bgneal@224 44 subtitle = models.CharField(max_length=255)
bgneal@224 45 summary = models.TextField()
bgneal@572 46 enclosure_url = models.URLField()
bgneal@572 47 alt_enclosure_url = models.URLField(blank=True)
bgneal@224 48 enclosure_length = models.IntegerField()
bgneal@224 49 enclosure_type = models.CharField(max_length=32)
bgneal@224 50 guid = models.CharField(max_length=255)
bgneal@277 51 pubdate = models.DateTimeField(db_index=True)
bgneal@224 52 duration = models.CharField(max_length=16)
bgneal@224 53 keywords = models.CharField(max_length=255)
bgneal@224 54 explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
bgneal@277 55 update_date = models.DateTimeField(db_index=True, blank=True)
gremmie@1 56
bgneal@224 57 def get_absolute_url(self):
bgneal@1032 58 return reverse('podcast-detail', args=[str(self.id)])
gremmie@1 59
bgneal@224 60 def __unicode__(self):
bgneal@224 61 return self.title
gremmie@1 62
bgneal@224 63 class Meta:
bgneal@1032 64 ordering = ['-pubdate']
bgneal@226 65 verbose_name = 'podcast'
bgneal@226 66 verbose_name_plural = 'podcasts'
gremmie@1 67
bgneal@277 68 def save(self, *args, **kwargs):
bgneal@277 69 if not self.id:
bgneal@277 70 if not self.pubdate:
bgneal@277 71 self.pubdate = datetime.datetime.now()
bgneal@277 72 self.update_date = self.pubdate
bgneal@277 73 else:
bgneal@277 74 self.update_date = datetime.datetime.now()
bgneal@277 75 super(Item, self).save(*args, **kwargs)
bgneal@277 76
bgneal@224 77 def search_title(self):
bgneal@224 78 return "%s: %s" % (self.title, self.subtitle)
bgneal@224 79
bgneal@224 80 def search_summary(self):
bgneal@224 81 return u"\n".join((self.subtitle, self.summary, self.keywords))
bgneal@487 82
bgneal@487 83 def ogp_tags(self):
bgneal@487 84 """
bgneal@487 85 Returns a dict of Open Graph Protocol meta tags.
bgneal@487 86
bgneal@487 87 """
bgneal@487 88 title = "%s: %s; %s" % (self.channel.title, self.title, self.subtitle)
bgneal@487 89 return {
bgneal@487 90 'og:title': title,
bgneal@487 91 'og:type': 'article',
bgneal@487 92 'og:url': self.get_absolute_url(),
bgneal@487 93 'og:description': self.subtitle,
bgneal@487 94 'og:audio': self.enclosure_url,
bgneal@487 95 'og:audio:title': title,
bgneal@487 96 'og:audio:artist': 'Various',
bgneal@487 97 'og:audio:type': self.enclosure_type,
bgneal@487 98 }