view podcast/models.py @ 693:ad69236e8501

For issue #52, update many 3rd party Javascript libraries. Updated to jquery 1.10.2, jquery ui 1.10.3. This broke a lot of stuff. - Found a newer version of the jquery cycle all plugin (3.0.3). - Updated JPlayer to 2.4.0. - Updated to MarkItUp 1.1.14. This also required me to add multiline attributes set to true on various buttons in the markdown set. - As per a stackoverflow post, added some code to get multiline titles in a jQuery UI dialog. They removed that functionality but allow you to put it back. Tweaked the MarkItUp preview CSS to show blockquotes in italic. Did not update TinyMCE at this time. I'm not using the JQuery version and this version appears to work ok for now. What I should do is make a repo for MarkItUp and do a vendor branch thing so I don't have to futz around diffing directories to figure out if I'll lose changes when I update.
author Brian Neal <bgneal@gmail.com>
date Wed, 04 Sep 2013 19:55:20 -0500
parents ee87ea74d46b
children e932f2ecd4a7
line wrap: on
line source
"""
Models for the podcast application.

"""
import datetime

from django.db import models


EXPLICIT_CHOICES = (
        ('yes', 'Yes'),
        ('no', 'No'),
        ('clean', 'Clean'),
    )


class Channel(models.Model):
    """Model to represent the Channel properties"""

    title = models.CharField(max_length=255)
    link = models.URLField()
    language = models.CharField(max_length=16)
    copyright = models.CharField(max_length=255)
    subtitle = models.CharField(max_length=255)
    author = models.CharField(max_length=64)
    description = models.CharField(max_length=255)
    owner_name = models.CharField(max_length=64)
    owner_email = models.EmailField()
    image = models.ImageField(upload_to='podcast')
    category = models.CharField(max_length=64)
    explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
    keywords = models.CharField(max_length=255)

    def __unicode__(self):
        return self.title


class Item(models.Model):
    """Model to represent a channel item"""
    channel = models.ForeignKey(Channel)
    title = models.CharField(max_length=255)
    author = models.CharField(max_length=255)
    subtitle = models.CharField(max_length=255)
    summary = models.TextField()
    enclosure_url = models.URLField()
    alt_enclosure_url = models.URLField(blank=True)
    enclosure_length = models.IntegerField()
    enclosure_type = models.CharField(max_length=32)
    guid = models.CharField(max_length=255)
    pubdate = models.DateTimeField(db_index=True)
    duration = models.CharField(max_length=16)
    keywords = models.CharField(max_length=255)
    explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)
    update_date = models.DateTimeField(db_index=True, blank=True)

    @models.permalink
    def get_absolute_url(self):
        return ('podcast.views.detail', [str(self.id)])

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ('-pubdate', )
        verbose_name = 'podcast'
        verbose_name_plural = 'podcasts'

    def save(self, *args, **kwargs):
        if not self.id:
            if not self.pubdate:
                self.pubdate = datetime.datetime.now()
            self.update_date = self.pubdate
        else:
            self.update_date = datetime.datetime.now()
        super(Item, self).save(*args, **kwargs)

    def search_title(self):
        return "%s: %s" % (self.title, self.subtitle)

    def search_summary(self):
        return u"\n".join((self.subtitle, self.summary, self.keywords))

    def ogp_tags(self):
        """
        Returns a dict of Open Graph Protocol meta tags.

        """
        title = "%s: %s; %s" % (self.channel.title, self.title, self.subtitle)
        return {
            'og:title': title,
            'og:type': 'article',
            'og:url': self.get_absolute_url(),
            'og:description': self.subtitle,
            'og:audio': self.enclosure_url,
            'og:audio:title': title,
            'og:audio:artist': 'Various',
            'og:audio:type': self.enclosure_type,
        }