summaryrefslogtreecommitdiff
path: root/app/pages/models.py
blob: 198e1860a71e57cf267a1b2b03427c1fe983d9d9 (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 datetime
from django.db import models
from django.conf import settings
from django.contrib.sitemaps import Sitemap
 
from utils import markdown2 as markdown

def markdown_processor(md):    
    return markdown.markdown(md, ['footnotes'],safe_mode = False)

TEMPLATES = (
        (0, 'single'),
        (1, 'double'),
        (2, 'single-dark'),
        (3, 'double-dark'),
    )
               
class Page(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField()
    body_html = models.TextField(blank=True)
    body_markdown = models.TextField()
    meta_description = models.CharField(max_length=256, null=True, blank=True)
  
    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/%s/" % (self.slug)
    
    def save(self): 
        #run markdown
        self.body_html = markdown_processor(self.body_markdown)
        super(Page, self).save()

class PageSitemap(Sitemap):
    changefreq = "never"
    priority = 1.0

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