Permalink
Browse files

Refactor a little bit for siteconfig,

Note: fixture for the defaults is not working if we reference
siteconfig.settings.foo directly. Either we have to add a templatetag,
or use fixture.
  • Loading branch information...
kunxi committed Jun 23, 2010
1 parent 966f8bb commit ed4754c5fbe824865e499be981c0fbfd1c9c37a5
Showing with 13 additions and 11 deletions.
  1. +2 −2 bloggo/context_processors.py
  2. +4 −2 bloggo/management.py
  3. +6 −6 bloggo/tests.py
  4. +1 −1 bloggo/urls.py
@@ -1,4 +1,4 @@
from djblets.siteconfig.models import SiteConfiguration
-def siteconf_processor(request):
- return {'siteconf': SiteConfiguration.objects.get_current() }
+def siteconfig(request):
+ return {'siteconfig': SiteConfiguration.objects.get_current()}
View
@@ -8,7 +8,9 @@
def initial_siteconf(*args, **kwargs):
print 'Initialize site configuration'
- siteconfig = SiteConfiguration(site=Site.objects.get_current(), version=bloggo.__version__)
- siteconfig.save()
+
+ siteconfig, created = SiteConfiguration.objects.get_or_create(site=Site.objects.get_current(), version=bloggo.__version__)
+ if created:
+ x = siteconfig.save()
post_syncdb.connect(initial_siteconf, sender=site_app)
View
@@ -1,24 +1,24 @@
from django.http import HttpResponse, Http404
-from context_processors import siteconf_processor
+from context_processors import siteconfig
from unittest import TestCase
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.test import Client
-def siteconf_view(request):
- c = RequestContext(request, {}, [siteconf_processor])
+def siteconfig_view(request):
+ c = RequestContext(request, {}, [siteconfig])
try:
- x = c['siteconf']
+ x = c['siteconfig']
except KeyError:
raise Http404
- return HttpResponse('siteconf_processor works.', status=200)
+ return HttpResponse('siteconfig context_processor works.', status=200)
class TestView(TestCase):
def setUp(self):
self.client = Client()
def testSiteConfDecorator(self):
- response = self.client.get(reverse('test_siteconf'))
+ response = self.client.get(reverse('test_siteconfig'))
self.assertEqual(response.status_code, 200)
View
@@ -10,7 +10,7 @@
urlpatterns = patterns('',
(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict' : feeds}),
- url(r'siteconf', view=tests.siteconf_view, name='test_siteconf'),
+ url(r'siteconfig', view=tests.siteconfig_view, name='test_siteconfig'),
(r'', include('basic.blog.urls')),
)

0 comments on commit ed4754c

Please sign in to comment.