Commit 40194903 authored by Stefano Rivera's avatar Stefano Rivera

Replace medusa renderers with bakery buildable views

django-medusa was pretty dead upstream.
wafer replaced it with django-bakery, which is conceptually a bit nicer,
but a little more manual to drive.
parent bf2f2de0
......@@ -7,6 +7,7 @@
/localstatic/
/node_modules/
/static/
/static_mirror/
/ve/
/pip-log.txt
......
from django_medusa.renderers import StaticSiteRenderer
class RootRenderer(StaticSiteRenderer):
def get_paths(self):
return ['/']
renderers = [RootRenderer]
from bakery.views import BuildableTemplateView
class IndexView(BuildableTemplateView):
template_name = 'wafer/index.html'
build_path = 'index.html'
from django_medusa.renderers import StaticSiteRenderer
from django.core.urlresolvers import reverse
from news.models import NewsItem
class NewsRenderer(StaticSiteRenderer):
def get_paths(self):
paths = []
items = NewsItem.objects.all()
for item in items:
paths.append(item.get_absolute_url())
paths.append(reverse('news'))
return paths
renderers = [NewsRenderer, ]
import datetime
import logging
import os
from django.conf import settings
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.syndication.views import Feed
from django.http import Http404
from django.urls import reverse_lazy
from django.urls import reverse, reverse_lazy
from django.utils.feedgenerator import Atom1Feed
from django.utils.timezone import make_aware
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView
from bakery.feeds import BuildableFeed
from bakery.views import BuildableTemplateView
from markitup.fields import render_func
from news.models import NewsItem
log = logging.getLogger(__name__)
class NewsItemView(TemplateView):
class NewsItemView(BuildableTemplateView):
template_name = 'news/item.html'
def get_context_data(self, date, slug):
......@@ -25,9 +30,30 @@ class NewsItemView(TemplateView):
raise Http404
return context
@property
def build_method(self):
return self.build_news_items
def build_news_items(self):
[self.build_news_item(item) for item in NewsItem.objects.all()]
def build_news_item(self, item):
log.debug("Building %s", item)
path = item.get_absolute_url().lstrip('/') + 'index.html'
self.request = self.create_request(item.get_absolute_url())
self.kwargs = {
'date': item.date,
'slug': item.slug,
}
content = self.get(self.request, **self.kwargs).render().content
self.prep_directory(path)
target_path = os.path.join(settings.BUILD_DIR, path)
self.build_file(target_path, content)
class NewsFeedView(TemplateView):
class NewsFeedView(BuildableTemplateView):
template_name = 'news/feed.html'
build_path = '/news/index.html'
def get_context_data(self, page=0):
context = super(NewsFeedView, self).get_context_data()
......@@ -35,7 +61,7 @@ class NewsFeedView(TemplateView):
return context
class NewsRSSView(Feed):
class NewsRSSView(BuildableFeed):
title = _('News')
link = reverse_lazy('news')
description = _('Conference News')
......@@ -65,6 +91,10 @@ class NewsRSSView(Feed):
def item_updateddate(self, item):
return self.item_pubdate(item)
@property
def build_path(self):
return reverse('news_rss').lstrip('/')
class NewsAtomView(NewsRSSView):
feed_type = Atom1Feed
......@@ -72,3 +102,7 @@ class NewsAtomView(NewsRSSView):
def item_author_name(self, item):
return self.title
@property
def build_path(self):
return reverse('news_atom').lstrip('/')
......@@ -213,3 +213,12 @@ WAFER_PUBLIC_ATTENDEE_LIST = False
PAGE_DIR = '%s/' % (root / 'pages')
NEWS_DIR = '%s/' % (root / 'news' / 'stories')
SPONSORS_DIR = '%s/' % (root / 'sponsors')
BAKERY_VIEWS += (
'dc19.views.IndexView',
'news.views.NewsItemView',
'news.views.NewsFeedView',
'news.views.NewsRSSView',
'news.views.NewsAtomView',
)
BUILD_DIR = '%s/' % (root / 'static_mirror')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment