diff options
author | lxf <sng@luxagraf.net> | 2021-10-30 17:18:57 -0400 |
---|---|---|
committer | lxf <sng@luxagraf.net> | 2021-10-30 17:18:57 -0400 |
commit | 7b628e9cde7fe2babe16523b7d1d44df0c468203 (patch) | |
tree | d2303d4b6fb316ff32bf58c2afebc6fcd7f30a1e /app/posts/models.py | |
parent | 940da61accfd124a2dfc90fb585434203f39685b (diff) |
posts: made podcast posttype and templates
Diffstat (limited to 'app/posts/models.py')
-rw-r--r-- | app/posts/models.py | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/app/posts/models.py b/app/posts/models.py index 0d93482..37c4c9b 100644 --- a/app/posts/models.py +++ b/app/posts/models.py @@ -25,7 +25,7 @@ from django_comments.moderation import CommentModerator, moderator from taggit.managers import TaggableManager from normalize.models import RelatedPost -from media.models import LuxImage, LuxImageSize +from media.models import LuxImage, LuxImageSize, LuxAudio from books.models import Book #from fieldnotes.models import FieldNote from taxonomy.models import TaggedItems, Category @@ -37,16 +37,12 @@ def get_upload_path(self, filename): class PostType(models.IntegerChoices): - FIELD_TEST = 0, ('field test') - REVIEW = 1, ('review') - ESSAY = 2, ('essay') - SRC = 3, ('src') - JRNL = 4, ('jrnl') - FIELD_NOTE = 5, ('field note') + PODCAST = 0, ('Podcast') + JRNL = 1, ('jrnl') + FIELD_NOTE = 2, ('field note') class Post(models.Model): - site = models.ForeignKey(Site, on_delete=models.CASCADE) title = models.CharField(max_length=200) short_title = models.CharField(max_length=200, blank=True, null=True) subtitle = models.CharField(max_length=200, blank=True) @@ -68,16 +64,8 @@ class Post(models.Model): ) status = models.IntegerField(choices=PUB_STATUS, default=0) featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) - TEMPLATES = ( - (0, 'single'), - (1, 'double'), - (2, 'single-dark'), - (3, 'double-dark'), - (4, 'single-black'), - (5, 'double-black'), - ) + featured_audio = models.ForeignKey(LuxAudio, on_delete=models.CASCADE, null=True, blank=True) post_type = models.IntegerField(choices=PostType.choices, default=PostType.JRNL) - template_name = models.IntegerField(choices=TEMPLATES, default=0) has_video = models.BooleanField(blank=True, default=False) has_code = models.BooleanField(blank=True, default=False) disclaimer = models.BooleanField(blank=True, default=False) @@ -86,6 +74,7 @@ class Post(models.Model): topics = models.ManyToManyField(Category, blank=True) originally_published_by = models.CharField(max_length=400, null=True, blank=True) originally_published_by_url = models.CharField(max_length=400, null=True, blank=True) + issue = models.PositiveIntegerField(null=True) class Meta: ordering = ('-pub_date',) @@ -95,8 +84,10 @@ class Post(models.Model): return self.title def get_absolute_url(self): - if self.post_type == 0: - return reverse('guides:reviews:review-detail', kwargs={"slug": self.slug}) + if self.post_type == PostType.JRNL: + return reverse('jrnl:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) + if self.post_type == PostType.PODCAST: + return reverse('podcasts:detail', kwargs={"episode": self.get_issue_str(), "slug": self.slug}) if self.post_type == 1: return reverse('guides:reviews:review-detail', kwargs={"slug": self.slug}) if self.post_type == 2: @@ -105,8 +96,6 @@ class Post(models.Model): return reverse('src:detail', kwargs={"slug": self.slug}) if self.post_type == 5: return reverse('fieldnote:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) - if self.post_type == PostType.JRNL: - return reverse('jrnl:detail', kwargs={"year": self.pub_date.year, "month": self.pub_date.strftime("%m"), "slug": self.slug}) def comment_period_open(self): return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date @@ -117,6 +106,14 @@ class Post(models.Model): def get_content_type(self): return ContentType.objects.get(app_label="posts", model="post") + def get_issue_str(self): + issue = self.issue + if self.issue < 100: + issue = "0%s" % self.issue + if self.issue < 10: + issue = "00%s" % self.issue + return issue + @property def get_previous_published(self): return self.get_previous_by_pub_date(status__exact=1,post_type=self.post_type) @@ -179,19 +176,19 @@ class Post(models.Model): if self.prologue_html: self.prologue_html = markdown_to_html(self.prologue_markdown) self.has_video = parse_video(self.body_html) - if created and not self.featured_image: - if self.post_type == PostType.FIELD_NOTE: - self.featured_image = extract_main_image(self.body_markdown) - else: - self.featured_image = LuxImage.objects.latest() + #if created and not self.featured_image: + # if self.post_type == PostType.FIELD_NOTE: + # self.featured_image = extract_main_image(self.body_markdown) + # else: + # self.featured_image = LuxImage.objects.latest() old = type(self).objects.get(pk=self.pk) if self.pk else None - if old and old.featured_image != self.featured_image: # Field has changed - if self.featured_image: - s = LuxImageSize.objects.get(name="featured_jrnl") - ss = LuxImageSize.objects.get(name="picwide-med") - self.featured_image.sizes.add(s) - self.featured_image.sizes.add(ss) - self.featured_image.save() + #if old and old.featured_image != self.featured_image: # Field has changed + # if self.featured_image: + # s = LuxImageSize.objects.get(name="featured_jrnl") + # ss = LuxImageSize.objects.get(name="picwide-med") + # self.featured_image.sizes.add(s) + # self.featured_image.sizes.add(ss) + # self.featured_image.save() if old and old.title != self.title or old and old.slug != self.slug: related, c = RelatedPost.objects.get_or_create(model_name=self.get_content_type(), entry_id = self.id, pub_date=self.pub_date) related.title = self.title |