summaryrefslogtreecommitdiff
path: root/app/pages/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/pages/models.py')
-rw-r--r--app/pages/models.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/pages/models.py b/app/pages/models.py
new file mode 100644
index 0000000..7198d59
--- /dev/null
+++ b/app/pages/models.py
@@ -0,0 +1,61 @@
+import re
+from django.db import models
+from django.contrib.sitemaps import Sitemap
+from django.contrib.sites.models import Site
+
+from media.models import LuxImage
+from posts.models import Post
+from utils.util import markdown_to_html, render_images
+
+
+class Page(models.Model):
+ title = models.CharField(max_length=200)
+ sub_title = models.CharField(max_length=300, blank=True)
+ slug = models.SlugField()
+ body_html = models.TextField(blank=True)
+ body_markdown = models.TextField()
+ meta_description = models.CharField(max_length=256, blank=True)
+ path = models.CharField(max_length=200, blank=True)
+ app = models.CharField(max_length=50, blank=True)
+ build = models.BooleanField(default=True)
+ enable_comments = models.BooleanField(default=False)
+ site = models.ForeignKey(Site, on_delete=models.CASCADE)
+ featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE, null=True, blank=True)
+ pub_date = models.DateTimeField('Date published', null=True, blank=True)
+
+ def __str__(self):
+ return self.title
+
+ def get_absolute_url(self):
+ if self.path:
+ return "/%s/%s" % (self.path, self.slug)
+ else:
+ return "/%s" % (self.slug)
+
+ def save(self):
+ # run markdown
+ md = render_images(self.body_markdown)
+ self.body_html = markdown_to_html(md)
+ super(Page, self).save()
+
+
+class HomePage(models.Model):
+ """
+ simple model to control the featured article on the homepage
+ also allows me to fudge the "popular" section to be what I want
+ """
+ image_offset_vertical = models.CharField(max_length=20, help_text="add negative top margin to shift image (include css unit)", blank=True, null=True)
+ featured_image = models.ForeignKey(LuxImage, on_delete=models.CASCADE)
+ tag_line = models.CharField(max_length=200, null=True, blank=True)
+ featured = models.ForeignKey(Post, on_delete=models.CASCADE, related_name="banner", null=True, blank=True)
+ popular = models.ManyToManyField(Post, related_name="popular", null=True, blank=True)
+ template_name = models.CharField(max_length=200, help_text="full path", null=True, blank=True)
+
+
+class PageSitemap(Sitemap):
+ changefreq = "never"
+ priority = 1.0
+ protocol = "https"
+
+ def items(self):
+ return Page.objects.filter(build=True)