<s> import floppyforms as forms <EOL> from django . core import urlresolvers <EOL> from django . forms . models import modelformset_factory <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ungettext_lazy <EOL> from horizon import tables <EOL> from horizon . tables . formset import FormsetDataTable , FormsetRow <EOL> from leonardo . module . web . models import PageDimension <EOL> class Slider ( forms . RangeInput ) : <EOL> min = <NUM_LIT:1> <EOL> max = <NUM_LIT:12> <EOL> step = <NUM_LIT:1> <EOL> class OffsetSlider ( Slider ) : <EOL> min = <NUM_LIT:0> <EOL> class PageDimensionForm ( forms . ModelForm ) : <EOL> col1_width = forms . CharField ( widget = Slider ( ) , initial = <NUM_LIT:4> ) <EOL> col2_width = forms . CharField ( widget = Slider ( ) , initial = <NUM_LIT:4> ) <EOL> col3_width = forms . CharField ( widget = Slider ( ) , initial = <NUM_LIT:4> ) <EOL> class Meta : <EOL> model = PageDimension <EOL> exclude = tuple ( ) <EOL> PageDimensionFormset = modelformset_factory ( <EOL> PageDimension , form = PageDimensionForm , can_delete = True , extra = <NUM_LIT:1> ) <EOL> class PageFormsetRow ( FormsetRow ) : <EOL> def __init__ ( self , column , datum , form ) : <EOL> self . form = form <EOL> super ( PageFormsetRow , self ) . __init__ ( column , datum , form ) <EOL> if not datum : <EOL> self . form . fields [ '<STR_LIT>' ] . initial = self . page_object <EOL> class PageDimensionAddAction ( tables . LinkAction ) : <EOL> name = "<STR_LIT>" <EOL> verbose_name = _ ( "<STR_LIT>" ) <EOL> classes = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> url = "<STR_LIT>" <EOL> def get_link_url ( self ) : <EOL> return urlresolvers . reverse ( <EOL> self . url , args = [ self . table . page_object . id ] ) <EOL> def allowed ( self , request , instance ) : <EOL> return True <EOL> class DeletePageDimension ( tables . DeleteAction ) : <EOL> @ staticmethod <EOL> def action_present ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> @ staticmethod <EOL> def action_past ( count ) : <EOL> return ungettext_lazy ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" , <EOL> count <EOL> ) <EOL> def delete ( self , request , obj_id ) : <EOL> from . . models import PageDimension <EOL> PageDimension . objects . get ( pk = obj_id ) . delete ( ) <EOL> class PageDimensionTable ( tables . DataTable ) : <EOL> formset_class = PageDimensionFormset <EOL> def get_formset ( self ) : <EOL> if self . page_object : <EOL> queryset = self . page_object . dimensions <EOL> else : <EOL> queryset = PageDimension . objects . none ( ) <EOL> if self . _formset is None : <EOL> self . _formset = self . formset_class ( <EOL> self . request . POST or None , <EOL> initial = self . _get_formset_data ( ) , <EOL> prefix = self . _meta . name , <EOL> queryset = queryset ) <EOL> return self . _formset <EOL> def __init__ ( self , request , data = None , needs_form_wrapper = None , ** kwargs ) : <EOL> self . page_object = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( PageDimensionTable , self ) . __init__ ( <EOL> request , data , needs_form_wrapper , ** kwargs ) <EOL> page = tables . Column ( '<STR_LIT>' ) <EOL> size = tables . Column ( '<STR_LIT:size>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> col1_width = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> col3_width = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> col2_width = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> def get_object_id ( self , datum ) : <EOL> return datum . pk <EOL> def get_object_name ( self , datum ) : <EOL> return str ( datum ) <EOL> name = '<STR_LIT>' <EOL> class Meta : <EOL> name = '<STR_LIT>' <EOL> table_name = '<STR_LIT>' <EOL> table_actions = ( PageDimensionAddAction , ) <EOL> row_actions = ( DeletePageDimension , ) </s>
