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
|
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)")
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")
popular = models.ManyToManyField(Post, related_name="popular")
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)
|