Mercurial > public > sg101
comparison news/models.py @ 997:19b86e684cc2
WIP on news v2.0.
Initial model changes and submit news functions.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 17 Nov 2015 21:01:20 -0600 |
parents | 76525f5ac2b1 |
children | e2c3d7ecfa30 |
comparison
equal
deleted
inserted
replaced
996:ec28e9d1e82a | 997:19b86e684cc2 |
---|---|
1 """ | 1 """ |
2 Models for the news application. | 2 Models for the news application. |
3 """ | 3 """ |
4 import datetime | |
4 | 5 |
5 import datetime | |
6 from django.db import models | 6 from django.db import models |
7 from django.contrib.auth.models import User | 7 from django.contrib.auth.models import User |
8 from tagging.fields import TagField | 8 from tagging.fields import TagField |
9 | |
10 from core.markup import site_markup | |
11 | |
12 | |
13 # News App versions | |
14 NEWS_VERSION = 2 | |
9 | 15 |
10 | 16 |
11 class Category(models.Model): | 17 class Category(models.Model): |
12 """News stories belong to categories""" | 18 """News stories belong to categories""" |
13 title = models.CharField(max_length=64) | 19 title = models.CharField(max_length=64) |
37 tags = TagField() | 43 tags = TagField() |
38 front_page_expiration = models.DateField(null=True, blank=True) | 44 front_page_expiration = models.DateField(null=True, blank=True) |
39 update_date = models.DateTimeField(db_index=True, blank=True) | 45 update_date = models.DateTimeField(db_index=True, blank=True) |
40 priority = models.IntegerField(db_index=True, default=0, blank=True) | 46 priority = models.IntegerField(db_index=True, default=0, blank=True) |
41 meta_description = models.TextField(blank=True) | 47 meta_description = models.TextField(blank=True) |
48 short_markup = models.TextField(default='') | |
49 long_markup = models.TextField(default='', blank=True) | |
50 admin_content = models.TextField(default='', blank=True) | |
51 version = models.SmallIntegerField(default=NEWS_VERSION) | |
42 | 52 |
43 class Meta: | 53 class Meta: |
44 abstract = True | 54 abstract = True |
55 | |
56 def save(self, *args, **kwargs): | |
57 if not self.pk: | |
58 self.date_submitted = datetime.datetime.now() | |
59 self.update_date = self.date_submitted | |
60 else: | |
61 self.update_date = datetime.datetime.now() | |
62 | |
63 self.short_text = kwargs.pop('short_text', None) | |
64 if self.short_text is None and self.short_markup: | |
65 self.short_text = site_markup(self.short_markup) | |
66 | |
67 self.long_text = kwargs.pop('long_text', None) | |
68 if self.long_text is None and self.long_markup: | |
69 self.long_text = site_markup(self.long_markup) | |
70 | |
71 super(StoryBase, self).save(*args, **kwargs) | |
45 | 72 |
46 | 73 |
47 class PendingStory(StoryBase): | 74 class PendingStory(StoryBase): |
48 """Stories submitted by users are held pending admin approval""" | 75 """Stories submitted by users are held pending admin approval""" |
49 | 76 |
50 def save(self, *args, **kwargs): | |
51 if not self.pk: | |
52 if not self.date_submitted: | |
53 self.date_submitted = datetime.datetime.now() | |
54 self.update_date = self.date_submitted | |
55 else: | |
56 self.update_date = datetime.datetime.now() | |
57 | |
58 super(PendingStory, self).save(*args, **kwargs) | |
59 | |
60 def __unicode__(self): | 77 def __unicode__(self): |
61 return self.title | 78 return self.title |
62 | 79 |
63 class Meta: | 80 class Meta: |
64 ordering = ('-date_submitted', ) | 81 ordering = ['-date_submitted'] |
65 verbose_name_plural = 'Pending Stories' | 82 verbose_name_plural = 'Pending Stories' |
66 | 83 |
67 | 84 |
68 class Story(StoryBase): | 85 class Story(StoryBase): |
69 """Model for news stories""" | 86 """Model for news stories""" |
74 | 91 |
75 def __unicode__(self): | 92 def __unicode__(self): |
76 return self.title | 93 return self.title |
77 | 94 |
78 class Meta: | 95 class Meta: |
79 ordering = ('-date_submitted', ) | 96 ordering = ['-date_submitted'] |
80 verbose_name = 'news story' | 97 verbose_name = 'news story' |
81 verbose_name_plural = 'news stories' | 98 verbose_name_plural = 'news stories' |
82 | |
83 def save(self, *args, **kwargs): | |
84 if not self.pk: | |
85 self.date_submitted = datetime.datetime.now() | |
86 self.update_date = self.date_submitted | |
87 else: | |
88 self.update_date = datetime.datetime.now() | |
89 | |
90 super(Story, self).save(*args, **kwargs) | |
91 | 99 |
92 def can_comment_on(self): | 100 def can_comment_on(self): |
93 now = datetime.datetime.now() | 101 now = datetime.datetime.now() |
94 delta = now - self.date_submitted | 102 delta = now - self.date_submitted |
95 return self.allow_comments and delta.days < 30 | 103 return self.allow_comments and delta.days < 30 |