summaryrefslogtreecommitdiff
path: root/app/jrnl/build.py
blob: 6d5b0f6d7a2e4d0fa47a64451eebf78cfd351725 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
from django.core.urlresolvers import reverse
from django.apps import apps
from builder.base import BuildNew
from itertools import chain


class BuildJrnl(BuildNew):

    def build(self):
        self.build_list_view(
            base_path=reverse("jrnl:live_redirect"),
            paginate_by=24
        )
        self.build_year_view("jrnl:list_year")
        self.build_month_view("jrnl:list_month")
        self.build_detail_view()
        self.build_location_view()
        self.build_feed("jrnl:feed")

    def build_arc(self):
        self.build_list_view(
            base_path=reverse("jrnl:live_redirect"),
            paginate_by=24
        )
        self.build_year_view("jrnl:list_year")
        self.build_month_view("jrnl:list_month")
        self.build_location_view()


    def build_location_view(self):
        c = apps.get_model('locations', 'Country')
        r = apps.get_model('locations', 'Region')
        countries = c.objects.filter(visited=True)
        regions = r.objects.all()
        locations = list(chain(countries, regions))
        for c in locations:
            try:
                qs = self.model.objects.filter(
                    status__exact=1,
                    location__state__country=c
                )
            except:
                qs = self.model.objects.filter(
                    status__exact=1,
                    location__state__country__lux_region=c.id
                )
            pages = self.get_pages(qs, 24)
            for page in range(pages):
                base_path = reverse("jrnl:list_country", kwargs={'slug': c.slug, 'page': page + 1})
                response = self.client.get(base_path, HTTP_HOST='127.0.0.1')
                if page == 0:
                    self.write_file(base_path[:-2], response.content)
                else:
                    self.write_file(base_path, response.content)


def build_arc():
    j = BuildJrnl("jrnl", "entry")
    j.build_arc()


def build_detail():
    j = BuildJrnl("jrnl", "entry")
    j.build_detail_view()