<s> import time <EOL> import datetime <EOL> from flask . ext import wtf <EOL> from wtforms import fields , widgets <EOL> from flask_superadmin . babel import gettext <EOL> from flask import request <EOL> class BaseForm ( wtf . Form ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , formdata = None , obj = None , prefix = '<STR_LIT>' , ** kwargs ) : <EOL> if formdata : <EOL> super ( BaseForm , self ) . __init__ ( formdata , obj , prefix , ** kwargs ) <EOL> else : <EOL> super ( BaseForm , self ) . __init__ ( obj = obj , prefix = prefix , ** kwargs ) <EOL> self . _obj = obj <EOL> @ property <EOL> def has_file_field ( self ) : <EOL> """<STR_LIT>""" <EOL> for f in self : <EOL> if isinstance ( f , fields . FileField ) : <EOL> return True <EOL> return False <EOL> class TimeField ( fields . Field ) : <EOL> """<STR_LIT>""" <EOL> widget = widgets . TextInput ( ) <EOL> def __init__ ( self , label = None , validators = None , formats = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( TimeField , self ) . __init__ ( label , validators , ** kwargs ) <EOL> self . formats = formats or ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def _value ( self ) : <EOL> if self . raw_data : <EOL> return u'<STR_LIT:U+0020>' . join ( self . raw_data ) <EOL> else : <EOL> return self . data and self . data . strftime ( self . formats [ <NUM_LIT:0> ] ) or u'<STR_LIT>' <EOL> def process_formdata ( self , valuelist ) : <EOL> if valuelist : <EOL> date_str = u'<STR_LIT:U+0020>' . join ( valuelist ) <EOL> for format in self . formats : <EOL> try : <EOL> timetuple = time . strptime ( date_str , format ) <EOL> self . data = datetime . time ( timetuple . tm_hour , <EOL> timetuple . tm_min , <EOL> timetuple . tm_sec ) <EOL> return <EOL> except ValueError : <EOL> pass <EOL> raise ValueError ( gettext ( '<STR_LIT>' ) ) <EOL> class ChosenSelectWidget ( widgets . Select ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> if getattr ( field , '<STR_LIT>' , False ) and not self . multiple : <EOL> kwargs [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> return super ( ChosenSelectWidget , self ) . __call__ ( field , ** kwargs ) <EOL> class ChosenSelectField ( fields . SelectField ) : <EOL> """<STR_LIT>""" <EOL> widget = ChosenSelectWidget <EOL> class FileFieldWidget ( object ) : <EOL> widget_checkbox = widgets . CheckboxInput ( ) <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> from cgi import escape <EOL> input_file = '<STR_LIT>' % widgets . html_params ( name = field . name , type = '<STR_LIT:file>' ) <EOL> return widgets . HTMLString ( '<STR_LIT>' % ( input_file , escape ( field . _value ( ) ) , self . widget_checkbox ( field . _clear ) , field . _clear . id ) ) <EOL> class FileField ( fields . FileField ) : <EOL> widget = FileFieldWidget ( ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . clearable = kwargs . pop ( '<STR_LIT>' , True ) <EOL> super ( FileField , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _prefix = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . clear_field = fields . BooleanField ( default = False ) <EOL> if self . clearable : <EOL> self . _clear_name = '<STR_LIT>' % self . short_name <EOL> self . _clear_id = '<STR_LIT>' % self . id <EOL> self . _clear = self . clear_field . bind ( form = None , name = self . _clear_name , prefix = self . _prefix , id = self . _clear_id ) <EOL> def process ( self , formdata , data = fields . _unset_value ) : <EOL> super ( FileField , self ) . process ( formdata , data ) <EOL> if self . clearable : <EOL> self . _clear . process ( formdata , data ) <EOL> self . _clear . checked = False <EOL> @ property <EOL> def clear ( self ) : <EOL> return ( not self . clearable ) or self . _clear . data <EOL> @ property <EOL> def data ( self ) : <EOL> data = self . _data <EOL> if data is not None : <EOL> data . clear = self . clear <EOL> return data <EOL> @ data . setter <EOL> def data ( self , data ) : <EOL> self . _data = data <EOL> class DatePickerWidget ( widgets . TextInput ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> return super ( DatePickerWidget , self ) . __call__ ( field , ** kwargs ) <EOL> class DateTimePickerWidget ( widgets . TextInput ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , field , ** kwargs ) : <EOL> kwargs [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> return super ( DateTimePickerWidget , self ) . __call__ ( field , ** kwargs ) </s>
