diff options
Diffstat (limited to 'app/lttr/models.py')
-rw-r--r-- | app/lttr/models.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/app/lttr/models.py b/app/lttr/models.py index e39b3b0..f1125d0 100644 --- a/app/lttr/models.py +++ b/app/lttr/models.py @@ -21,6 +21,7 @@ from utils.util import render_images, parse_video, markdown_to_html from taxonomy.models import TaggedItems from media.models import LuxImage, LuxImageSize from books.models import Book +from posts.models import Post # Possible actions that user can perform @@ -125,7 +126,7 @@ class Newsletter(models.Model): return None -class NewsletterMailing(models.Model): +class OldNewsletterMailing(models.Model): """ A model for Newletter Mailings, the things actually sent out """ newsletter = models.ForeignKey(Newsletter, on_delete=models.CASCADE) title = models.CharField(max_length=250) @@ -206,6 +207,55 @@ class NewsletterMailing(models.Model): super(NewsletterMailing, self).save() +class NewsletterMailing(models.Model): + """ A model for Newletter Mailings, the things actually sent out """ + newsletter = models.ForeignKey(Newsletter, on_delete=models.CASCADE) + post = models.ForeignKey(Post, null=True, blank=True, on_delete=models.SET_NULL) + title = models.CharField(max_length=250, blank=True) + subtitle = models.CharField(max_length=250, null=True, blank=True) + body_html = models.TextField(blank=True) + body_email_html = models.TextField(blank=True) + body_markdown = models.TextField(blank=True) + pub_date = models.DateTimeField(blank=True) + featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True) + issue = models.PositiveIntegerField(blank=True) + + class Meta: + ordering = ('-title', '-pub_date') + + def __str__(self): + return self.title + + def email_encode(self): + return self.body_markdown + + 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 + + def save(self, *args, **kwargs): + created = self.pk is None + if created and self.post: + self.title = self.post.title + self.subtitle = self.post.subtitle + self.body_markdown = self.post.body_markdown + self.pub_date = self.post.pub_date + self.featured_image = self.post.featured_image + self.issue = self.post.issue + if not created: + md = render_images(self.body_markdown) + self.body_html = markdown_to_html(md) + self.body_email_html = markdown_to_emailhtml(self.body_html) + self.date_created = timezone.now() + if created and not self.featured_image: + self.featured_image = LuxImage.objects.latest() + super(NewNewsletterMailing, self).save() + + class Subscriber(models.Model): """ A model for Newletter Subscriber """ email_field = models.EmailField(db_column='email', db_index=True, blank=True, null=True) |