Browse files

Some code cleanup

  • Loading branch information...
1 parent 4878a78 commit 547c6529b237c50476a3a14a5ed9ed28a74cc143 @zerok committed Jan 13, 2012
Showing with 16 additions and 11 deletions.
  1. +3 −2 flatblocks/admin.py
  2. +1 −0 flatblocks/forms.py
  3. +4 −3 flatblocks/models.py
  4. +3 −2 flatblocks/urls.py
  5. +5 −4 flatblocks/views.py
View
5 flatblocks/admin.py
@@ -1,8 +1,9 @@
from django.contrib import admin
from flatblocks.models import FlatBlock
-
+
+
class FlatBlockAdmin(admin.ModelAdmin):
- ordering = ['slug',]
+ ordering = ['slug', ]
list_display = ('slug', 'header')
search_fields = ('slug', 'header', 'content')
View
1 flatblocks/forms.py
@@ -2,6 +2,7 @@
from flatblocks.models import FlatBlock
+
class FlatBlockForm(ModelForm):
class Meta:
model = FlatBlock
View
7 flatblocks/models.py
@@ -11,17 +11,18 @@ class FlatBlock(models.Model):
basically a piece of content with a given name (slug) and an optional
title (header) which you can, for example, use in a sidebar of a website.
"""
- slug = models.CharField(max_length=255, unique=True,
+ slug = models.CharField(max_length=255, unique=True,
verbose_name=_('Slug'),
help_text=_("A unique name used for reference in the templates"))
header = models.CharField(blank=True, null=True, max_length=255,
verbose_name=_('Header'),
help_text=_("An optional header for this content"))
- content = models.TextField(verbose_name=_('Content'), blank=True, null=True)
+ content = models.TextField(verbose_name=_('Content'), blank=True,
+ null=True)
def __unicode__(self):
return u"%s" % (self.slug,)
-
+
def save(self, *args, **kwargs):
super(FlatBlock, self).save(*args, **kwargs)
# Now also invalidate the cache used in the templatetag
View
5 flatblocks/urls.py
@@ -1,7 +1,8 @@
-from django.conf.urls.defaults import *
+from django.conf.urls.defaults import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from flatblocks.views import edit
urlpatterns = patterns('',
- url('^edit/(?P<pk>\d+)/$', staff_member_required(edit), name='flatblocks-edit')
+ url('^edit/(?P<pk>\d+)/$', staff_member_required(edit),
+ name='flatblocks-edit')
)
View
9 flatblocks/views.py
@@ -1,6 +1,7 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
-from django.http import HttpResponseRedirect, HttpResponseForbidden, HttpResponse
+from django.http import HttpResponseRedirect, HttpResponseForbidden,\
+ HttpResponse
from django.utils.translation import ugettext as _
from flatblocks.models import FlatBlock
@@ -17,7 +18,7 @@ def edit(request, pk, modelform_class=FlatBlockForm, permission_check=None,
keyword-argument.
The other entry point helps you check permissions: Pass a simple function
- via the ``permission_check`` keyword-argument in order to check
+ via the ``permission_check`` keyword-argument in order to check
permissions on the flatblock-level::
def my_perm_check(request, flatblock):
@@ -33,7 +34,7 @@ def my_perm_check(request, flatblock):
The contract here is pretty simple: If the function returns False, the
view will return HttpResponseForbidden. Otherwise it will pass. So if you
want to do some fancy redirects if the permissions are wrong, return your
- own HttpResponse-object/-subclass.
+ own HttpResponse-object/-subclass.
If everything is alright with the permissions, simply return True.
"""
@@ -47,7 +48,7 @@ def my_perm_check(request, flatblock):
session_key = 'flatblock.origin.%d' % (int(pk), )
if request.method == 'POST':
- origin = request.session.get(session_key,
+ origin = request.session.get(session_key,
request.META.get('HTTP_REFERER', '/'))
form = modelform_class(request.POST, instance=flatblock)
if form.is_valid():

0 comments on commit 547c652

Please sign in to comment.