<s> from django . views . generic . edit import FormMixin <EOL> from django . shortcuts import get_object_or_404 <EOL> from widgy . models import Node <EOL> class HandleFormMixin ( FormMixin ) : <EOL> """<STR_LIT>""" <EOL> def post ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> form_class = self . get_form_class ( ) <EOL> form = self . get_form ( form_class ) <EOL> if form . is_valid ( ) : <EOL> return self . form_valid ( form ) <EOL> else : <EOL> return self . form_invalid ( form ) <EOL> put = post <EOL> def get_form_node ( self ) : <EOL> node = get_object_or_404 ( Node , pk = self . kwargs [ '<STR_LIT>' ] ) <EOL> node . prefetch_tree ( ) <EOL> return node <EOL> def get_form_class ( self ) : <EOL> self . form_node = self . get_form_node ( ) <EOL> return self . form_node . content . build_form_class ( ) <EOL> def get_form ( self , form_class = None ) : <EOL> if form_class is None : <EOL> if self . kwargs . get ( '<STR_LIT>' ) is None : <EOL> return None <EOL> form_class = self . get_form_class ( ) <EOL> return form_class ( ** self . get_form_kwargs ( ) ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> kwargs . setdefault ( self . form_node . content . context_var , kwargs [ '<STR_LIT>' ] ) <EOL> return super ( HandleFormMixin , self ) . get_context_data ( ** kwargs ) <EOL> def form_valid ( self , form ) : <EOL> return self . form_node . content . execute ( self . request , form ) </s>
