<s> from django import forms <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from . models import Page <EOL> from . _markups import get_all_markups <EOL> from . settings import WALIKI_CODEMIRROR_SETTINGS as CM_SETTINGS , get_slug <EOL> from . acl import check_perms <EOL> class DeleteForm ( forms . Form ) : <EOL> what = forms . ChoiceField ( label = _ ( '<STR_LIT>' ) , <EOL> choices = ( ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) ) <EOL> ) <EOL> class MovePageForm ( forms . ModelForm ) : <EOL> slug = forms . CharField ( ) <EOL> just_redirect = forms . BooleanField ( label = _ ( '<STR_LIT>' ) , widget = forms . HiddenInput , initial = False , required = False ) <EOL> class Meta : <EOL> model = Page <EOL> fields = ( '<STR_LIT>' , '<STR_LIT>' , ) <EOL> exclude = ( '<STR_LIT>' , ) <EOL> def clean ( self ) : <EOL> cleaned_data = super ( MovePageForm , self ) . clean ( ) <EOL> slug = cleaned_data [ '<STR_LIT>' ] <EOL> just_redirect = cleaned_data . get ( '<STR_LIT>' , False ) <EOL> if self . instance . slug == slug : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> if Page . objects . filter ( slug = slug ) . exists ( ) and not just_redirect : <EOL> self . fields [ '<STR_LIT>' ] . widget = forms . CheckboxInput ( ) <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return cleaned_data <EOL> class NewPageForm ( forms . ModelForm ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . user = kwargs . pop ( '<STR_LIT:user>' , None ) <EOL> super ( NewPageForm , self ) . __init__ ( * args , ** kwargs ) <EOL> class Meta : <EOL> model = Page <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def clean_slug ( self ) : <EOL> slug = self . cleaned_data [ '<STR_LIT>' ] <EOL> if not slug : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> if get_slug ( slug ) != slug : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> if not check_perms ( [ '<STR_LIT>' ] , self . user , slug ) : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> if Page . objects . filter ( slug = slug ) . exists ( ) : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return slug <EOL> class PageForm ( forms . ModelForm ) : <EOL> raw = forms . CharField ( label = "<STR_LIT>" , widget = forms . Textarea ) <EOL> message = forms . CharField ( label = _ ( '<STR_LIT>' ) , max_length = <NUM_LIT:200> , required = False ) <EOL> extra_data = forms . CharField ( widget = forms . HiddenInput , required = False ) <EOL> class Meta : <EOL> model = Page <EOL> fields = [ '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:message>' ] <EOL> class Media : <EOL> modes = tuple ( '<STR_LIT>' % ( m . codemirror_mode , m . codemirror_mode ) <EOL> for m in get_all_markups ( ) if hasattr ( m , '<STR_LIT>' ) ) <EOL> theme = ( '<STR_LIT>' % CM_SETTINGS [ '<STR_LIT>' ] , ) if '<STR_LIT>' in CM_SETTINGS else ( ) <EOL> js = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) + modes + ( '<STR_LIT>' , ) <EOL> css = { <EOL> '<STR_LIT:all>' : ( '<STR_LIT>' , ) + theme <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> is_hidden = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( PageForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . raw <EOL> self . fields [ '<STR_LIT>' ] . widget = forms . HiddenInput ( ) <EOL> self . fields [ '<STR_LIT:message>' ] . widget = forms . TextInput ( attrs = { '<STR_LIT>' : _ ( '<STR_LIT>' ) % self . instance . path } ) <EOL> if is_hidden : <EOL> for field in self . fields . values ( ) : <EOL> field . widget = forms . HiddenInput ( ) <EOL> def save ( self , commit = True ) : <EOL> instance = super ( PageForm , self ) . save ( commit ) <EOL> if commit : <EOL> instance . raw = self . cleaned_data [ '<STR_LIT>' ] <EOL> return instance </s>
