summaryrefslogtreecommitdiff
path: root/app/src/build.py
blob: a60f80c0a07ca97f5f9074c0de7c288552542e92 (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
42
43
44
45
46
47
48
49
50
51
from builder.base import *
from .models import Topic, Entry


class BuildSrc(Build):
    def build(self):
        self.build_archive()
        self.build_topic_archive()
        self.build_detail_pages()
        self.build_feed()

    def build_detail_pages(self):
        '''
        Grab all the notes, render them to a template string and write that out to the filesystem
        '''
        for entry in Entry.objects.filter(status__exact=1):
            c = Context({'object': entry, 'MEDIA_URL': settings.BAKED_MEDIA_URL, 'IMAGES_URL': settings.BAKED_IMAGES_URL, 'SITE_URL':settings.SITE_URL})
            t = render_to_string('details/src_entry.html', c).encode('utf-8')
            path = 'src/' 
            self.write_file(path, t, 'html', entry.slug)
            s = render_to_string('details/note.txt', c).encode('utf-8')
            self.write_file(path, s, 'txt', entry.slug)

    def build_archive(self):
        path = 'src/'
        c = Context({
            'object_list': Entry.objects.filter(status__exact=1),
            'MEDIA_URL': settings.BAKED_MEDIA_URL,
            'IMAGES_URL': settings.BAKED_IMAGES_URL
        })
        t = render_to_string('archives/src_home.html', c).encode('utf-8')
        self.write_file(path, t)

    def build_topic_archive(self):
        for topic in Topic.objects.all():
            path = 'src/topic/' 
            c = Context({
                'object_list': Entry.objects.filter(topics__slug=topic.slug),
                'topic': topic,
                'MEDIA_URL': settings.BAKED_MEDIA_URL,
                'IMAGES_URL': settings.BAKED_IMAGES_URL
            })
            t = render_to_string('archives/src_home.html', c).encode('utf-8')
            self.write_file(path, t, 'html', topic.slug)
    
    def build_feed(self):
        qs = Entry.objects.filter(status__exact=1)
        c = Context({'object_list': qs, 'SITE_URL': settings.SITE_URL})
        t = render_to_string('feed.xml', c).encode('utf-8')
        fpath = '%s' % ('/src/rss/',)
        self.write_file(fpath, t, 'xml')