summaryrefslogtreecommitdiff
path: root/apps/links/models.py
blob: e8fee4320f1f0abc618a935620fefd068a2a51de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import datetime

from django.db import models
from django.contrib.syndication.feeds import Feed
from django.contrib.sitemaps import Sitemap

from tagging.fields import TagField
from tagging.models import Tag


RATINGS = (
    ('1', "1 Star"),
    ('2', "2 Stars"),
    ('3', "3 Stars"),
    ('4', "4 Stars"),
    ('5', "5 Stars"),
)

DEBUG = 1
 
class Link(models.Model):
    title = models.CharField(max_length=400)
    magnolia_id = models.CharField(max_length=60, blank=True, null=True)
    url = models.CharField(max_length=400)
    description = models.TextField(blank=True, null=True)
    screen_url = models.CharField(max_length=400, blank=True)
    rating = models.CharField(max_length=1, choices=RATINGS)
    pub_date = models.DateTimeField()
    enable_comments = models.NullBooleanField(default=False)
    PUB_STATUS = (
        (0, 'Private'),
        (1, 'Public'),
    )
    status = models.IntegerField(choices=PUB_STATUS, default=0)
    tags = TagField()

    class Meta:
        ordering = ['-pub_date']
       
    def __unicode__(self):
        return self.title
    
    def get_absolute_url(self):
        return self.url
        
    def get_model_name(self):
        return 'link'
        
    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_tags(self):
        return Tag.objects.get_for_object(self)
    
    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
    
        
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]