<s> from flask import redirect <EOL> from flask_views . base import TemplateResponseMixin , View <EOL> from flask_views . db . mongoengine . detail import BaseDetailView , SingleObjectMixin <EOL> from flask_views . edit import FormMixin , ProcessFormMixin <EOL> class ModelFormMixin ( FormMixin , SingleObjectMixin ) : <EOL> """<STR_LIT>""" <EOL> def get_form_kwargs ( self ) : <EOL> """<STR_LIT>""" <EOL> kwargs = super ( ModelFormMixin , self ) . get_form_kwargs ( ) <EOL> kwargs [ '<STR_LIT>' ] = self . object <EOL> return kwargs <EOL> def form_valid ( self , form ) : <EOL> """<STR_LIT>""" <EOL> if not self . object : <EOL> self . object = self . document_class ( ) <EOL> form . populate_obj ( self . object ) <EOL> self . object . save ( ) <EOL> return super ( ModelFormMixin , self ) . form_valid ( form ) <EOL> def get_context_data ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> context = super ( ModelFormMixin , self ) . get_context_data ( ** kwargs ) <EOL> context . update ( { <EOL> '<STR_LIT:object>' : self . object , <EOL> } ) <EOL> return context <EOL> class BaseCreateView ( ModelFormMixin , ProcessFormMixin , View ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = None <EOL> return super ( BaseCreateView , self ) . get ( * args , ** kwargs ) <EOL> def post ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = None <EOL> return super ( BaseCreateView , self ) . post ( * args , ** kwargs ) <EOL> class CreateView ( TemplateResponseMixin , BaseCreateView ) : <EOL> """<STR_LIT>""" <EOL> class BaseUpdateView ( ModelFormMixin , ProcessFormMixin , View ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = self . get_object ( ) <EOL> return super ( BaseUpdateView , self ) . get ( * args , ** kwargs ) <EOL> def post ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = self . get_object ( ) <EOL> return super ( BaseUpdateView , self ) . post ( * args , ** kwargs ) <EOL> class UpdateView ( TemplateResponseMixin , BaseUpdateView ) : <EOL> """<STR_LIT>""" <EOL> class DeletionMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> success_url = None <EOL> """<STR_LIT>""" <EOL> def get_success_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . success_url <EOL> def delete ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object . delete ( ) <EOL> return redirect ( self . get_success_url ( ) ) <EOL> class BaseDeleteView ( DeletionMixin , BaseDetailView ) : <EOL> """<STR_LIT>""" <EOL> def delete ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . object = self . get_object ( ) <EOL> return super ( BaseDeleteView , self ) . delete ( * args , ** kwargs ) <EOL> class DeleteView ( TemplateResponseMixin , BaseDeleteView ) : <EOL> """<STR_LIT>""" </s>
