bgneal@277: """ bgneal@277: Models for the podcast application. bgneal@277: bgneal@277: """ bgneal@277: import datetime gremmie@1: gremmie@1: from django.db import models gremmie@1: bgneal@277: gremmie@1: EXPLICIT_CHOICES = ( bgneal@224: ('yes', 'Yes'), bgneal@224: ('no', 'No'), bgneal@224: ('clean', 'Clean'), bgneal@224: ) gremmie@1: gremmie@1: gremmie@1: class Channel(models.Model): bgneal@224: """Model to represent the Channel properties""" gremmie@1: bgneal@224: title = models.CharField(max_length=255) bgneal@572: link = models.URLField() bgneal@224: language = models.CharField(max_length=16) bgneal@224: copyright = models.CharField(max_length=255) bgneal@224: subtitle = models.CharField(max_length=255) bgneal@224: author = models.CharField(max_length=64) bgneal@224: description = models.CharField(max_length=255) bgneal@224: owner_name = models.CharField(max_length=64) bgneal@224: owner_email = models.EmailField() bgneal@224: image = models.ImageField(upload_to='podcast') bgneal@224: category = models.CharField(max_length=64) bgneal@224: explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) bgneal@224: keywords = models.CharField(max_length=255) gremmie@1: bgneal@224: def __unicode__(self): bgneal@224: return self.title gremmie@1: gremmie@1: gremmie@1: class Item(models.Model): bgneal@224: """Model to represent a channel item""" bgneal@224: channel = models.ForeignKey(Channel) bgneal@224: title = models.CharField(max_length=255) bgneal@224: author = models.CharField(max_length=255) bgneal@224: subtitle = models.CharField(max_length=255) bgneal@224: summary = models.TextField() bgneal@572: enclosure_url = models.URLField() bgneal@572: alt_enclosure_url = models.URLField(blank=True) bgneal@224: enclosure_length = models.IntegerField() bgneal@224: enclosure_type = models.CharField(max_length=32) bgneal@224: guid = models.CharField(max_length=255) bgneal@277: pubdate = models.DateTimeField(db_index=True) bgneal@224: duration = models.CharField(max_length=16) bgneal@224: keywords = models.CharField(max_length=255) bgneal@224: explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES) bgneal@277: update_date = models.DateTimeField(db_index=True, blank=True) gremmie@1: bgneal@224: @models.permalink bgneal@224: def get_absolute_url(self): bgneal@224: return ('podcast.views.detail', [str(self.id)]) gremmie@1: bgneal@224: def __unicode__(self): bgneal@224: return self.title gremmie@1: bgneal@224: class Meta: bgneal@224: ordering = ('-pubdate', ) bgneal@226: verbose_name = 'podcast' bgneal@226: verbose_name_plural = 'podcasts' gremmie@1: bgneal@277: def save(self, *args, **kwargs): bgneal@277: if not self.id: bgneal@277: if not self.pubdate: bgneal@277: self.pubdate = datetime.datetime.now() bgneal@277: self.update_date = self.pubdate bgneal@277: else: bgneal@277: self.update_date = datetime.datetime.now() bgneal@277: super(Item, self).save(*args, **kwargs) bgneal@277: bgneal@224: def search_title(self): bgneal@224: return "%s: %s" % (self.title, self.subtitle) bgneal@224: bgneal@224: def search_summary(self): bgneal@224: return u"\n".join((self.subtitle, self.summary, self.keywords)) bgneal@487: bgneal@487: def ogp_tags(self): bgneal@487: """ bgneal@487: Returns a dict of Open Graph Protocol meta tags. bgneal@487: bgneal@487: """ bgneal@487: title = "%s: %s; %s" % (self.channel.title, self.title, self.subtitle) bgneal@487: return { bgneal@487: 'og:title': title, bgneal@487: 'og:type': 'article', bgneal@487: 'og:url': self.get_absolute_url(), bgneal@487: 'og:description': self.subtitle, bgneal@487: 'og:audio': self.enclosure_url, bgneal@487: 'og:audio:title': title, bgneal@487: 'og:audio:artist': 'Various', bgneal@487: 'og:audio:type': self.enclosure_type, bgneal@487: }