<s> import json <EOL> from django import forms <EOL> from django . template import RequestContext <EOL> from django . utils . safestring import mark_safe <EOL> from django . template . loader import render_to_string <EOL> from widgy . models import VersionCommit <EOL> from widgy . views . versioning import CommitForm <EOL> class JsonField ( forms . CharField ) : <EOL> def to_python ( self , value ) : <EOL> try : <EOL> result = json . loads ( value ) <EOL> return result <EOL> except ValueError : <EOL> raise forms . ValidationError <EOL> def prepare_value ( self , value ) : <EOL> return json . dumps ( value ) <EOL> class UndoApprovalsForm ( forms . Form ) : <EOL> actions = JsonField ( widget = forms . HiddenInput , required = True ) <EOL> referer = forms . CharField ( widget = forms . HiddenInput , required = True ) <EOL> def render ( self , request , site ) : <EOL> return mark_safe ( <EOL> render_to_string ( <EOL> '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : self , <EOL> '<STR_LIT>' : site , <EOL> } , <EOL> RequestContext ( request ) , <EOL> ) <EOL> ) <EOL> class ApproveForm ( forms . ModelForm ) : <EOL> approve = forms . BooleanField ( required = False ) <EOL> class Meta : <EOL> model = VersionCommit <EOL> fields = ( '<STR_LIT>' , ) <EOL> def save ( self , request , commit = True ) : <EOL> if self . cleaned_data [ '<STR_LIT>' ] : <EOL> self . instance . approve ( request . user , commit = commit ) <EOL> return super ( ApproveForm , self ) . save ( commit = commit ) <EOL> class ReviewedCommitForm ( CommitForm ) : <EOL> def commit ( self , obj , user ) : <EOL> approve_it = '<STR_LIT>' in self . data <EOL> commit = super ( ReviewedCommitForm , self ) . commit ( obj , user ) <EOL> if approve_it : <EOL> commit . reviewedversioncommit . approve ( user ) </s>
