<s> import floppyforms as forms <EOL> from django . forms . models import modelformset_factory <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import tables <EOL> from horizon . tables . formset import FormsetDataTable , FormsetRow <EOL> from leonardo . module . web . models import WidgetDimension <EOL> class Slider ( forms . RangeInput ) : <EOL> min = <NUM_LIT:1> <EOL> max = <NUM_LIT:12> <EOL> step = <NUM_LIT:1> <EOL> template_name = '<STR_LIT>' <EOL> class OffsetSlider ( Slider ) : <EOL> min = <NUM_LIT:0> <EOL> class HeightSlider ( OffsetSlider ) : <EOL> max = <NUM_LIT> <EOL> class WidgetDimensionForm ( forms . ModelForm ) : <EOL> width = forms . CharField ( widget = Slider ( ) , initial = <NUM_LIT:12> ) <EOL> height = forms . CharField ( widget = HeightSlider ( ) , initial = <NUM_LIT:0> ) <EOL> offset = forms . CharField ( widget = OffsetSlider ( ) , initial = <NUM_LIT:0> ) <EOL> class Meta : <EOL> model = WidgetDimension <EOL> exclude = tuple ( ) <EOL> WidgetDimensionFormset = modelformset_factory ( <EOL> WidgetDimension , form = WidgetDimensionForm , can_delete = True , extra = <NUM_LIT:1> ) <EOL> class CustomFormsetRow ( FormsetRow ) : <EOL> def __init__ ( self , column , datum , form ) : <EOL> self . form = form <EOL> super ( CustomFormsetRow , self ) . __init__ ( column , datum , form ) <EOL> if not datum and column . data : <EOL> try : <EOL> previous = column . data [ <NUM_LIT:0> ] <EOL> self . form . fields [ '<STR_LIT>' ] . initial = previous . widget_type <EOL> self . form . fields [ '<STR_LIT>' ] . initial = previous . widget_id <EOL> self . form . fields [ '<STR_LIT:id>' ] . initial = previous . id + <NUM_LIT:1> <EOL> except Exception : <EOL> pass <EOL> class WidgetDimensionTable ( FormsetDataTable ) : <EOL> formset_class = WidgetDimensionFormset <EOL> def get_formset ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . widget : <EOL> queryset = self . widget . dimensions <EOL> else : <EOL> queryset = WidgetDimension . 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 , * args , ** kwargs ) : <EOL> self . _meta . row_class = CustomFormsetRow <EOL> self . widget = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( WidgetDimensionTable , self ) . __init__ ( * args , ** kwargs ) <EOL> widget_id = tables . Column ( '<STR_LIT>' , hidden = True ) <EOL> widget_type = tables . Column ( '<STR_LIT>' , hidden = True ) <EOL> size = tables . Column ( '<STR_LIT:size>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> width = tables . Column ( '<STR_LIT:width>' , verbose_name = ( '<STR_LIT>' ) ) <EOL> height = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> offset = tables . Column ( '<STR_LIT>' , verbose_name = _ ( '<STR_LIT>' ) ) <EOL> name = '<STR_LIT>' <EOL> class Meta : <EOL> name = '<STR_LIT>' <EOL> table_name = '<STR_LIT>' </s>
