From a15bfb9cfaf31ffc71703665422ffc6da1df57b2 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Tue, 20 Dec 2011 19:17:33 +0000 Subject: [PATCH] Replace direct_to_template generic view with class-based TemplateView This is done as a part of migration to django 1.3. See https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/ for additional info. --- pyi2phosts/lib/generic.py | 14 ++++++++++++++ pyi2phosts/urls.py | 12 ++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100755 pyi2phosts/lib/generic.py diff --git a/pyi2phosts/lib/generic.py b/pyi2phosts/lib/generic.py new file mode 100755 index 0000000..68945a1 --- /dev/null +++ b/pyi2phosts/lib/generic.py @@ -0,0 +1,14 @@ +from django.views.generic.base import TemplateView +from pyi2phosts.lib.utils import get_b32 +import settings + +class LocalTemplateView(TemplateView): + def get_context_data(self, **kwargs): + context = super(LocalTemplateView, self).get_context_data(**kwargs) + context.update({ + 'title': settings.SITE_NAME, + 'domain': settings.DOMAIN, + 'b64': settings.MY_B64, + 'b32': get_b32(settings.MY_B64) + }) + return context diff --git a/pyi2phosts/urls.py b/pyi2phosts/urls.py index 9405f2a..155a13a 100644 --- a/pyi2phosts/urls.py +++ b/pyi2phosts/urls.py @@ -1,5 +1,4 @@ from django.conf.urls.defaults import * -from django.views.generic.simple import direct_to_template from django.views.generic.list_detail import object_list # Uncomment the next two lines to enable the admin: @@ -8,6 +7,7 @@ admin.autodiscover() from pyi2phosts.lib.rss import AliveHostsFeed from pyi2phosts.lib.utils import get_b32 +from pyi2phosts.lib.generic import LocalTemplateView from pyi2phosts.extsources.models import ExternalSource from pyi2phosts.postkey.models import i2phost import settings @@ -32,15 +32,7 @@ browse_hosts = { } urlpatterns = patterns('', - url(r'^$', direct_to_template, { - 'template': 'index.html', - 'extra_context': { - 'title': settings.SITE_NAME, - 'domain': settings.DOMAIN, - 'b64': settings.MY_B64, - 'b32': get_b32(settings.MY_B64) - } - }, name='index'), + url(r'^$', LocalTemplateView.as_view(template_name='index.html'), name='index'), url(r'^faq/$', object_list, extsources, name='faq'), url(r'^browse/$', object_list, browse_hosts, name='browse'), url(r'^browse/rss/$', AliveHostsFeed(), name='browse-rss'),