<commit_before>from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
import datetime

FEED_TYPE_CHOICES = (
    (u'rss', u'RSS'),
    (u'rss-0.90',  u'RSS 0.90'),
    (u'rss-0.91', u'RSS 0.91'),
    (u'rss-1.0', u'RSS 1.0'),
    (u'rss-2.0', u'RSS 2.0 by <NAME>'),
    (u'rss-2.0.10', u'RSS 2.0 by RSS Advisory Board'),
    (u'atom', u'Atom'),
    (u'atom-0.3', u'Atom 0.3'),
    (u'atom-1.0', u'Atom 1.0'),
)

class Feed(models.Model):
    url = models.URLField(verify_exists=False)
    codename = models.CharField(max_length=128, blank=True)
    type = models.CharField(max_length=16, choices=FEED_TYPE_CHOICES, blank=True, null=True)
    title = models.CharField(max_length=225)
    link = models.URLField(verify_exists=False, blank=True)
    description = models.TextField(blank=True)
    ttl = models.IntegerField(default=60)
    date_added = models.DateTimeField(auto_now_add=True)
    last_fetched = models.DateTimeField(blank=True, null=True)
    next_fetch = models.DateTimeField()
    
    def __unicode__(self):
        return self.title

    def save(self, *args, **kwargs):
        if not self.last_fetched:
            self.last_fetched = datetime.datetime.now()
            self.next_fetch = self.last_fetched
        else:
            self.next_fetch = self.last_fetched + datetime.timedelta(0, 0, 0, 0, self.ttl)
        super(Feed, self).save(*args, **kwargs)
        
class Subscription(models.Model):
    feed = models.ForeignKey(Feed, related_name='subscriptions')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    subscriber = generic.GenericForeignKey()

    def __unicode__(self):
        return '%s to %s' % (self.subscriber, self.feed)

class FeedEntryManager(models.Manager):
    pass
    
class FeedEntry(models.Model):
    objects = FeedEntryManager()
    uid = models.CharField(max_length=255)
    feed = models.ForeignKey(Feed, related_name="entries")
    title = models.CharField(max_length=255)
    link = models.URLField(verify_exists=False, blank=True)
    summary = models.TextField(blank=True)
    content = models.TextField(blank=True)
    author_name = models.CharField(max_length=255, blank=True)
    author_email = models.EmailField(blank=True, null=True)
    author_uri = models.URLField(verify_exists=False, blank=True, null=True)
    date_published = models.DateTimeField(blank=True, null=True)
    date_updated = models.DateTimeField(blank=True, null=True)
    last_fetched = models.DateTimeField()
    
    class Meta:
        ordering = ['-date_published']
        
    def __unicode__(self):
        return u"%s: %s" % (self.feed.title, self.title)
        
class Tag(models.Model):
    name = models.CharField(max_length=128)
    feed_entry = models.ForeignKey(FeedEntry, related_name="tags")
    
    class Meta:
        ordering = ['name']
    
    def __unicode__(self):
        return self.name
<commit_msg>changes for django 1.4's new timezone features<commit_after>import datetime

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from pytz import common_timezones

FEED_TYPE_CHOICES = (
    (u'rss', u'RSS'),
    (u'rss-0.90',  u'RSS 0.90'),
    (u'rss-0.91', u'RSS 0.91'),
    (u'rss-1.0', u'RSS 1.0'),
    (u'rss-2.0', u'RSS 2.0 by <NAME>'),
    (u'rss-2.0.10', u'RSS 2.0 by RSS Advisory Board'),
    (u'atom', u'Atom'),
    (u'atom-0.3', u'Atom 0.3'),
    (u'atom-1.0', u'Atom 1.0'),
)

TIMEZONE_CHOICES = [(tz, tz) for tz in common_timezones]


class Feed(models.Model):
    url = models.URLField(verify_exists=False)
    codename = models.CharField(max_length=128, blank=True)
    type = models.CharField(max_length=16, choices=FEED_TYPE_CHOICES, blank=True, null=True)
    title = models.CharField(max_length=225)
    link = models.URLField(verify_exists=False, blank=True)
    timezone = models.CharField(max_length=32, choices=TIMEZONE_CHOICES, default='UTC')
    description = models.TextField(blank=True)
    ttl = models.IntegerField(default=60)
    date_added = models.DateTimeField(auto_now_add=True)
    last_fetched = models.DateTimeField(blank=True, null=True)
    next_fetch = models.DateTimeField()

    def __unicode__(self):
        return self.title

    def save(self, *args, **kwargs):
        if not self.last_fetched:
            self.last_fetched = datetime.datetime.now()
            self.next_fetch = self.last_fetched
        else:
            self.next_fetch = self.last_fetched + datetime.timedelta(0, 0, 0, 0, self.ttl)
        super(Feed, self).save(*args, **kwargs)


class Subscription(models.Model):
    feed = models.ForeignKey(Feed, related_name='subscriptions')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    subscriber = generic.GenericForeignKey()

    def __unicode__(self):
        return '%s to %s' % (self.subscriber, self.feed)


class FeedEntryManager(models.Manager):
    pass


class FeedEntry(models.Model):
    objects = FeedEntryManager()
    uid = models.CharField(max_length=255)
    feed = models.ForeignKey(Feed, related_name="entries")
    title = models.CharField(max_length=255)
    link = models.URLField(verify_exists=False, blank=True)
    summary = models.TextField(blank=True)
    content = models.TextField(blank=True)
    author_name = models.CharField(max_length=255, blank=True)
    author_email = models.EmailField(blank=True, null=True)
    author_uri = models.URLField(verify_exists=False, blank=True, null=True)
    date_published = models.DateTimeField(blank=True, null=True)
    date_updated = models.DateTimeField(blank=True, null=True)
    last_fetched = models.DateTimeField()

    class Meta:
        ordering = ['-date_published']

    def __unicode__(self):
        return u"%s: %s" % (self.feed.title, self.title)


class Tag(models.Model):
    name = models.CharField(max_length=128)
    feed_entry = models.ForeignKey(FeedEntry, related_name="tags")

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name

{'fraction_non_alphanumeric': 0.1303783081669102, 'fraction_numerical': 0.020133138496509172, 'mean_word_length': 3.7348193697156034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2930334', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2037, 'n_words': 389}