import datetime from django.core.urlresolvers import reverse from django.utils.encoding import force_text from django.db import models from django.contrib.sitemaps import Sitemap from django.contrib.syndication.views import Feed from taggit.managers import TaggableManager import markdown RATINGS = ( ('1', "1 Star"), ('2', "2 Stars"), ('3', "3 Stars"), ('4', "4 Stars"), ('5', "5 Stars"), ) class Link(models.Model): title = models.CharField(max_length=400) url = models.CharField(max_length=400) description = models.TextField(blank=True, null=True) pub_date = models.DateTimeField() PUB_STATUS = ( (0, 'Private'), (1, 'Public'), ) status = models.IntegerField(choices=PUB_STATUS, default=0) tags = TaggableManager(blank=True) class Meta: ordering = ['-pub_date'] def __unicode__(self): return self.title def get_absolute_url(self): return reverse("links:detail", kwargs={"slug": self.pk}) def render_description(self): return markdown.markdown(self.description, extensions=['extra'], safe_mode=False) def get_previous_published(self): return self.get_previous_by_pub_date(status__exact=1) def get_next_published(self): return self.get_next_by_pub_date(status__exact=1) def get_thumbnail_url(self): return "http://images.luxagraf.net/magnolia_thumbs/%s" % (self.screen_url) def comment_period_open(self): return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date def admin_link(self): return force_text('Visit Site' % (self.url)) admin_link.allow_tags = True admin_link.short_description = 'Link' class LinkSitemap(Sitemap): changefreq = "never" priority = 0.4 def items(self): return Link.objects.filter(status=1) def lastmod(self, obj): return obj.pub_date class LatestLinks(Feed): title = "Luxagraf: Links" link = "http://ma.gnolia.com/people/luxagraf/bookmarks" description = "Links to interesting stuff" description_template = 'feeds/links_description.html' def items(self): return Link.objects.filter(status__exact=1).order_by('-pub_date')[:10]