summaryrefslogtreecommitdiff
path: root/app/pages/models.py
blob: fa2bbc3e445d2bcd5acdcbd287deda91aad7d7da (plain)
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
import re
from django.db import models
from django.contrib.sitemaps import Sitemap

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)

    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 PageSitemap(Sitemap):
    changefreq = "never"
    priority = 1.0
    protocol = "https"

    def items(self):
        return Page.objects.all()