<s> from django import forms <EOL> from django . contrib import messages <EOL> from django . core . urlresolvers import reverse <EOL> from django . http import HttpResponseRedirect <EOL> from django . utils . translation import ugettext_lazy as _ , ugettext <EOL> from wakawaka . models import Revision <EOL> class WikiPageForm ( forms . Form ) : <EOL> content = forms . CharField ( label = _ ( '<STR_LIT>' ) , widget = forms . Textarea ( attrs = { '<STR_LIT>' : <NUM_LIT:30> } ) ) <EOL> message = forms . CharField ( label = _ ( '<STR_LIT>' ) , widget = forms . TextInput , required = False ) <EOL> def save ( self , request , page , * args , ** kwargs ) : <EOL> Revision . objects . create ( <EOL> page = page , <EOL> creator = request . user , <EOL> creator_ip = request . META [ '<STR_LIT>' ] , <EOL> content = self . cleaned_data [ '<STR_LIT:content>' ] , <EOL> message = self . cleaned_data [ '<STR_LIT:message>' ] <EOL> ) <EOL> DELETE_CHOICES = ( <EOL> ) <EOL> class DeleteWikiPageForm ( forms . Form ) : <EOL> delete = forms . ChoiceField ( label = _ ( '<STR_LIT>' ) , choices = ( ) ) <EOL> def __init__ ( self , request , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . base_fields [ '<STR_LIT>' ] . choices = [ ] <EOL> if request . user . has_perm ( '<STR_LIT>' ) : <EOL> self . base_fields [ '<STR_LIT>' ] . choices . append ( ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , ) <EOL> if request . user . has_perm ( '<STR_LIT>' ) and request . user . has_perm ( '<STR_LIT>' ) : <EOL> self . base_fields [ '<STR_LIT>' ] . choices . append ( ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , ) <EOL> super ( DeleteWikiPageForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def _delete_page ( self , page ) : <EOL> page . delete ( ) <EOL> def _delete_revision ( self , rev ) : <EOL> rev . delete ( ) <EOL> def delete_wiki ( self , request , page , rev ) : <EOL> """<STR_LIT>""" <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' and request . user . has_perm ( '<STR_LIT>' ) and request . user . has_perm ( '<STR_LIT>' ) : <EOL> self . _delete_page ( page ) <EOL> messages . success ( request , ugettext ( '<STR_LIT>' % page . slug ) ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> revision_length = len ( page . revisions . all ( ) ) <EOL> if revision_length > <NUM_LIT:1> and request . user . has_perm ( '<STR_LIT>' ) : <EOL> self . _delete_revision ( rev ) <EOL> messages . success ( request , ugettext ( '<STR_LIT>' % page . slug ) ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : page . slug } ) ) <EOL> if revision_length <= <NUM_LIT:1> and not request . user . has_perm ( '<STR_LIT>' ) : <EOL> messages . error ( request , ugettext ( '<STR_LIT>' % page . slug ) ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : page . slug } ) ) <EOL> if revision_length <= <NUM_LIT:1> and request . user . has_perm ( '<STR_LIT>' ) and request . user . has_perm ( '<STR_LIT>' ) : <EOL> self . _delete_page ( page ) <EOL> messages . success ( request , ugettext ( '<STR_LIT>' % page . slug ) ) <EOL> return HttpResponseRedirect ( reverse ( '<STR_LIT>' ) ) <EOL> return None </s>
