summaryrefslogtreecommitdiff
path: root/app/jrnl
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2015-11-06 14:41:58 -0500
committerluxagraf <sng@luxagraf.net>2015-11-06 14:41:58 -0500
commit78dc05f455f234da32c8c4d60b1b074755758d1c (patch)
treeb72a1cfb93d5b0315a5e16f1338f8a6793b21242 /app/jrnl
parent2311ea934932cf791a83f6c6264063a26468e98c (diff)
rewrote jrnl builder to be self contained in jrnl and based entirely off
url patterns/ views, refactored URLs/views to be class based and fixed a few django warning in URL files
Diffstat (limited to 'app/jrnl')
-rw-r--r--app/jrnl/build.py48
-rw-r--r--app/jrnl/models.py2
-rw-r--r--app/jrnl/urls.py16
-rw-r--r--app/jrnl/views.py33
4 files changed, 88 insertions, 11 deletions
diff --git a/app/jrnl/build.py b/app/jrnl/build.py
new file mode 100644
index 0000000..504e288
--- /dev/null
+++ b/app/jrnl/build.py
@@ -0,0 +1,48 @@
+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()
+
+ 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 builder():
+ j = BuildJrnl("jrnl", "entry")
+ j.build()
diff --git a/app/jrnl/models.py b/app/jrnl/models.py
index fe7f274..2f84798 100644
--- a/app/jrnl/models.py
+++ b/app/jrnl/models.py
@@ -31,7 +31,7 @@ def image_url_replace(s):
def extract_images(s):
- soup = BeautifulSoup(s)
+ soup = BeautifulSoup(s, "lxml")
imgs = []
for img in soup.find_all('img'):
imgs.append(img['src'])
diff --git a/app/jrnl/urls.py b/app/jrnl/urls.py
index d8fa395..2b17033 100644
--- a/app/jrnl/urls.py
+++ b/app/jrnl/urls.py
@@ -5,12 +5,22 @@ from . import views
urlpatterns = [
url(
+ regex=r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+).txt$',
+ view=views.EntryDetailViewTXT.as_view(),
+ name="detail-txt"
+ ),
+ url(
+ regex=r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+).amp$',
+ view=views.EntryDetailViewAMP.as_view(),
+ name="detail-amp"
+ ),
+ url(
regex=r'(?P<year>\d{4})/(?P<month>\d{2})/(?P<slug>[-\w]+)$',
view=views.EntryDetailView.as_view(),
name="detail"
),
url(
- regex=r'^(?P<year>[0-9]{4})/(?P<month>[0-9]+)/$',
+ regex=r'^(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$',
view=views.EntryMonthArchiveView.as_view(month_format='%m'),
name="list_month"
),
@@ -32,13 +42,13 @@ urlpatterns = [
# redirect /slug/ to /slug/1/ for live server
url(
regex=r'(?P<slug>[-\w]+)/$',
- view=RedirectView.as_view(url="/jrnl/%(slug)s/1/"),
+ view=RedirectView.as_view(url="/jrnl/%(slug)s/1/", permanent=False),
name="live_location_redirect"
),
# redirect / to /1/ for live server
url(
regex=r'',
- view=RedirectView.as_view(url="/jrnl/1/"),
+ view=RedirectView.as_view(url="/jrnl/1/", permanent=False),
name="live_redirect"
),
]
diff --git a/app/jrnl/views.py b/app/jrnl/views.py
index 7dd755b..634a375 100644
--- a/app/jrnl/views.py
+++ b/app/jrnl/views.py
@@ -6,7 +6,7 @@ from django.conf import settings
from .models import Entry, HomepageCurrator
-from locations.models import Country
+from locations.models import Country, Region
class EntryList(ListView):
@@ -38,15 +38,26 @@ class EntryCountryList(ListView):
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(EntryCountryList, self).get_context_data(**kwargs)
- context['region'] = Country.objects.get(slug__exact=self.kwargs['slug'])
+ try:
+ context['region'] = Country.objects.get(slug__exact=self.kwargs['slug'])
+ except:
+ context['region'] = Region.objects.get(slug__exact=self.kwargs['slug'])
return context
def get_queryset(self):
- country = Country.objects.get(slug__exact=self.kwargs['slug'])
- return Entry.objects.filter(
- status__exact=1,
- location__state__country=country
- ).order_by('-pub_date')
+ try:
+ region= Country.objects.get(slug__exact=self.kwargs['slug'])
+ qs = Entry.objects.filter(
+ status__exact=1,
+ location__state__country=region
+ ).order_by('-pub_date')
+ except:
+ region = Region.objects.get(slug__exact=self.kwargs['slug'])
+ qs = Entry.objects.filter(
+ status__exact=1,
+ location__state__country__lux_region=region.id
+ ).order_by('-pub_date')
+ return qs
class EntryYearArchiveView(YearArchiveView):
@@ -70,6 +81,14 @@ class EntryDetailView(DetailView):
slug_field = "slug"
+class EntryDetailViewTXT(EntryDetailView):
+ template_name = "details/entry.txt"
+
+
+class EntryDetailViewAMP(EntryDetailView):
+ template_name = "details/entry.amp"
+
+
class HomepageList(ListView):
"""
Return a main entry and list of Entries in reverse chronological order