summaryrefslogtreecommitdiff
path: root/app/posts/build.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/posts/build.py')
-rw-r--r--app/posts/build.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/app/posts/build.py b/app/posts/build.py
new file mode 100644
index 0000000..47a6efe
--- /dev/null
+++ b/app/posts/build.py
@@ -0,0 +1,110 @@
+from django.urls import reverse
+from django.apps import apps
+from builder.base import BuildNew
+from itertools import chain
+
+from django.conf import settings
+from .models import PostType
+
+
+class BuildSrc(BuildNew):
+
+ def get_model_queryset(self):
+ return self.model.objects.filter(post_type=PostType.SRC).filter(status__exact=1).order_by('-pub_date')
+
+ def build(self):
+ self.build_list_view(
+ base_path=reverse("src:list"),
+ paginate_by=50
+ )
+ self.build_detail_view()
+
+
+class BuildGuide(BuildNew):
+
+ def get_model_queryset(self):
+ return self.model.objects.filter(post_type__in=[PostType.FIELD_TEST, PostType.REVIEW]).filter(status__exact=1).order_by('-pub_date')
+
+ def build(self):
+ self.build_list_view(
+ base_path=reverse("guides:guide-base"),
+ paginate_by=50
+ )
+ self.build_detail_view()
+
+
+class BuildFieldNotes(BuildNew):
+
+ def get_model_queryset(self):
+ return self.model.objects.filter(post_type=PostType.FIELD_NOTE).filter(status__exact=1).order_by('-pub_date')
+
+ def build(self):
+ self.build_detail_view()
+ self.build_list_view(
+ base_path=reverse("fieldnotes:list"),
+ paginate_by=24
+ )
+ self.build_year_view("fieldnotes:list_year")
+ self.build_month_view("fieldnotes:list_month")
+
+
+class BuildJrnl(BuildNew):
+ '''
+ Write jrnl to disk
+ '''
+ def get_model_queryset(self):
+ return self.model.objects.filter(post_type=PostType.JRNL).filter(status__exact=1).order_by('-pub_date')
+
+ def build(self):
+ self.build_list_view(
+ base_path=reverse("jrnl:list"),
+ 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_latest()
+
+ def build_arc(self):
+ self.build_list_view(
+ base_path=reverse("jrnl:list"),
+ 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,
+ post_type=PostType.JRNL,
+ location__state__country=c
+ )
+ except:
+ qs = self.model.objects.filter(
+ status__exact=1,
+ post_type=PostType.JRNL,
+ location__state__country__lux_region=c.id
+ )
+ print(c)
+ 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)
+ print(response.content)
+ if page == 0:
+ self.write_file(base_path, response.content)
+ else:
+ self.write_file(base_path, response.content)
+
+ def build_latest(self):
+ response = self.client.get('/jrnl/latest/')
+ self.write_file(reverse("jrnl:latest"), response.content)