#NEWLINE# def _get_form_field( self , field , value = None ) : #NEWLINE# #INDENT# 'Generate a Django-friendly field from Hardtree spec in DB' #NEWLINE# form_field = None #NEWLINE# if ( field . field_type == 'text' ) : #NEWLINE# #INDENT# form_field = forms . CharField ( label = field . label , max_length = 512 , widget = forms . TextInput ( attrs = { #NEWLINE# #INDENT# 'size' : '30' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . field_type == 'details' ) : #NEWLINE# #INDENT# form_field = forms . CharField ( label = field . label , widget = forms . Textarea ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . field_type == 'url' ) : #NEWLINE# #INDENT# form_field = forms . URLField ( label = field . label , widget = forms . TextInput ( attrs = { #NEWLINE# #INDENT# 'size' : '50' , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . field_type == 'picture' ) : #NEWLINE# #INDENT# form_field = forms . ImageField ( label = field . label , widget = forms . FileInput ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field . field_type == 'date' ) : #NEWLINE# #INDENT# form_field = forms . DateTimeField ( label = field . label ) #NEWLINE# form_field . widget . attrs . update ( { #NEWLINE# #INDENT# 'class' : 'datetimepicker' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# form_field . required = field . required #NEWLINE# if value : #NEWLINE# #INDENT# if ( isinstance ( form_field , forms . FileField ) and value . value ) : #NEWLINE# #INDENT# form_field = forms . ChoiceField ( label = field . label , widget = forms . RadioSelect ( ) ) #NEWLINE# filename = full_filename = value . value #NEWLINE# match = re . match ( '.*[a-z0-9]{32}__(?P<filename>.+)$' , filename ) #NEWLINE# if match : #NEWLINE# #INDENT# filename = match . group ( 'filename' ) #NEWLINE# #UNINDENT# form_field . choices = ( ( full_filename , ( _ ( 'Keep existing: ' ) + unicode ( filename ) ) ) , ( 'delete' , _ ( 'Delete ' ) ) ) #NEWLINE# form_field . initial = full_filename #NEWLINE# form_field . required = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# form_field . initial = value . value #NEWLINE# #UNINDENT# #UNINDENT# return form_field