Changeset 15
- Timestamp:
- 02/07/08 07:20:09 (1 year ago)
- Files:
-
- trunk/common/middleware.py (added)
- trunk/common/models.py (modified) (1 diff)
- trunk/common/templates/base.html (modified) (2 diffs)
- trunk/common/templates/common/_navigation.html (added)
- trunk/common/templates/flatpages (added)
- trunk/common/templates/flatpages/default.html (added)
- trunk/common/templatetags/navigation.py (added)
- trunk/common/views.py (modified) (1 diff)
- trunk/settings.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/common/models.py
r4 r15 1 # vim: encoding=utf-8 : 2 3 from datetime import datetime 4 5 from django.core import validators 1 6 from django.db import models 7 from django.utils.translation import ugettext_lazy as _ 2 8 3 # Create your models here. 9 10 class FlatPage(models.Model): 11 """ 12 flat pages. 13 """ 14 url = models.CharField(_(u'URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], unique=True, 15 help_text=_(u"Example: '/about/contact/'. Make sure to have leading and trailing slashes.")) 16 title = models.CharField(_(u'title'), max_length=100, default=None) 17 content = models.TextField(_(u'content')) 18 template_name = models.CharField(_(u'template name'), max_length=70, blank=True, 19 help_text=_(u"Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'.")) 20 created_at = models.DateTimeField(_(u'created at'), editable=False, default=datetime.now) 21 updated_at = models.DateTimeField(_(u'updated at'), editable=False) 22 navigation_enabled = models.BooleanField(_(u'navigation enabled'), default=True) 23 is_active = models.BooleanField(_(u'is active'), editable=False, default=True) 24 25 class Meta: 26 ordering = ('title',) 27 verbose_name = _(u'flat page') 28 verbose_name_plural = _(u'flat pages') 29 30 class Admin: 31 list_display = ('title', 'url', 'created_at', 'updated_at', 'navigation_enabled', 'is_active') 32 fields = ( 33 (None, { 34 'fields': ('url', 'title', 'content'), 35 }), 36 ('Advanced options', { 37 'classes': 'collapse', 38 'fields': ('navigation_enabled', 'template_name') 39 }), 40 ) 41 list_filter = ('is_active',) 42 search_fields = ('url', 'title') 43 44 def __unicode__(self): 45 return self.title 46 47 def get_absolute_url(self): 48 return self.url 49 50 def save(self): 51 self.updated_at = datetime.now() 52 super(FlatPage, self).save() 53 54 def delete(self): 55 self.is_active = False 56 self.save() trunk/common/templates/base.html
r12 r15 2 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3 3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> 4 {% load i18n %}4 {% load i18n navigation %} 5 5 <head> 6 6 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> … … 40 40 </fieldset> 41 41 </form> 42 <ul> 43 <li><a href="" title="home">home</a></li> 44 <li><a href="" title="about">about</a></li> 45 </ul> 42 {% navigation PATH_INFO %} 46 43 </div> 47 44 </div> trunk/common/views.py
r4 r15 1 # Create your views here. 1 # vim: encoding=utf-8 : 2 3 from django.conf import settings 4 from django.http import HttpResponse, Http404 5 from django.template import loader, RequestContext as Context 6 7 from common.models import FlatPage 8 9 DEFAULT_TEMPLATE = 'flatpages/default.html' 10 11 12 def flatpage(req, url): 13 """ 14 Show flatpage. 15 """ 16 if not url.startswith('/'): 17 url = "/" + url 18 try: 19 object = FlatPage.objects.filter(url__exact=url)\ 20 .get(is_active__exact=True) 21 except FlatPage.DoesNotExist: 22 raise Http404 23 if object.template_name: 24 t = loader.select_template((object.template_name, DEFAULT_TEMPLATE)) 25 else: 26 t = loader.get_template(DEFAULT_TEMPLATE) 27 c = Context(req, { 28 'object': object, 29 }) 30 return HttpResponse(t.render(c)) trunk/settings.py
r6 r15 87 87 'django.contrib.auth.middleware.AuthenticationMiddleware', 88 88 'django.middleware.doc.XViewMiddleware', 89 'common.middleware.FlatpageFallbackMiddleware', 89 90 ) 90 91
