view gpp/podcast/models.py @ 265:1ba2c6bf6eb7

Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author Brian Neal <bgneal@gmail.com>
date Fri, 24 Sep 2010 02:12:09 +0000
parents 405468b8e3b9
children d424b8bae71d
line wrap: on
line source
"""Models for the podcast application."""

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(verify_exists=False)
    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(verify_exists=False)
    alt_enclosure_url = models.URLField(verify_exists=False, blank=True)
    enclosure_length = models.IntegerField()
    enclosure_type = models.CharField(max_length=32)
    guid = models.CharField(max_length=255)
    pubdate = models.DateTimeField()
    duration = models.CharField(max_length=16)
    keywords = models.CharField(max_length=255)
    explicit = models.CharField(max_length=8, choices=EXPLICIT_CHOICES)

    @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 search_title(self):
        return "%s: %s" % (self.title, self.subtitle)

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