Advertisement
lengend

Untitled

Sep 14th, 2012
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. ###
  2. #  Project: CMDO Clan Website
  3. #
  4. #  Copyright (C) 2012 lengend. All rights reserved.
  5. ###
  6.  
  7. ### Module: Site.Administration
  8.  
  9. ### Imports
  10. from models import Page
  11. from django.utils.translation import ugettext as _
  12. from django.contrib import admin
  13. from django.contrib.admin.widgets import AdminTextInputWidget
  14. from django import forms
  15.  
  16. ### Page administration form
  17. class PageForm(forms.ModelForm):
  18.         def __init__(self, *args, **kwargs):
  19.                 super ( PageForm, self ).__init__ ( *args, **kwargs )
  20.                 if ( self.instance and self.instance.pk ):
  21.                         self.fields [ 'key' ].widget = AdminTextInputWidget ( attrs = { 'readonly': 'readonly' } )
  22.  
  23.         def clean_key(self):
  24.                 if ( self.instance and self.instance.pk ):
  25.                         if ( self.instance.key != self.cleaned_data [ 'key' ] ):
  26.                                 raise forms.ValidationError ( _ ( 'This field is read only.' ) )
  27.                         return self.instance.key
  28.                 else: return self.cleaned_data [ 'key' ]
  29.  
  30.         class Meta:
  31.                 model = Page
  32.  
  33. ### Page administration model
  34. class PageAdmin(admin.ModelAdmin):
  35.         ### Form configuration
  36.         form = PageForm
  37.  
  38.         ### Field configuration
  39.         list_display = ( 'key', )
  40.         search_fields = ( 'key', 'body', )
  41.  
  42.         ### Media configuration
  43.         class Media:
  44.                 js = ( 'administration/js/tiny_mce/tiny_mce.js', 'administration/js/tiny_mce/tiny_mce_setup.js', )
  45.  
  46. ### Registrations
  47. def autodiscover():
  48.         admin.site.register ( Page, PageAdmin )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement