def addReferenceForm(self,tableName): """ adds a reference form of this table """ Form.manage_add( self.references, id=tableName, title=self.labelFromId(tableName), unicode_mode=True ) referenceForm = getattr(self.references,tableName) referenceForm.manage_addProperty('primary_keys',[],'lines') setattr(referenceForm,'stored_encoding',"UTF-8")
def addReferenceField(self,referenceFormObject,fieldName, fieldType="StringField", title="", primary_key=False, auto_num=False, null=True, width=8, unique=False): """ adds a reference field with those properties """ if not(title): title = self.labelFromId(fieldName) referenceFormObject.manage_addField(fieldName,Form.convert_unicode(title),fieldType) field = getattr(referenceFormObject,fieldName) field.db_width = width initialSettingsDictionnary = {'required':null,'title':title,'unicode':True} # VALIDATION CONSTRAINTS : a ameliorer if width: if field.has_value('end'): # pour les entiers qui peuvent avoir un maximum initialSettingsDictionnary['start']= 0 - (2 ** (2**width)) / 2 -1 initialSettingsDictionnary['end']= (2 ** (2**width)) / 2 +1 initialSettingsDictionnary['display_maxwidth'] = (2 ** (2**width))/10+1 elif field.has_value('max_length'): initialSettingsDictionnary['max_length'] = width if fieldType in ["TextAreaField","RawTextAreaField"]: initialSettingsDictionnary['width']=40 initialSettingsDictionnary['height']=width/40+1 else: initialSettingsDictionnary['display_maxwidth'] = 2**width if primary_key: # primary keys are stored as a reference form property referenceFormObject.manage_changeProperties( {"primary_keys":referenceFormObject.primary_keys + (fieldName,)}) if unique: # TODO initialSettingsDictionnary['external_validator']="verifyUnicityConstraint" if auto_num: initialSettingsDictionnary['override_default']="sequelAutoNum" field.initialize_values(initialSettingsDictionnary)
def addViewField(self,fieldName, fieldType="StringField", title="", primary_key=False, auto_num=False, null=False, width=0, unique=False): """ adds a reference field with those properties """ if not(title): title = self.labelFromId(fieldName) if self.isDefaultDbField(fieldName): # permet la gestion des champs par defaut, commencant par underscore fieldName = "d"+fieldName self.form.manage_addField(fieldName,Form.convert_unicode(title),fieldType) field = getattr(self.form,fieldName) self._setFieldSettings(field,title=title, null=null, width=width)
def initialize(context): """Initialize the Formulator product. """ # register field classes FieldRegistry.registerField(StandardFields.StringField, 'www/StringField.gif') FieldRegistry.registerField(StandardFields.CheckBoxField, 'www/CheckBoxField.gif') FieldRegistry.registerField(StandardFields.IntegerField, 'www/IntegerField.gif') FieldRegistry.registerField(StandardFields.TextAreaField, 'www/TextAreaField.gif') FieldRegistry.registerField(StandardFields.RawTextAreaField, 'www/TextAreaField.gif') FieldRegistry.registerField(StandardFields.LinesField, 'www/LinesField.gif') FieldRegistry.registerField(StandardFields.ListField, 'www/ListField.gif') FieldRegistry.registerField(StandardFields.MultiListField, 'www/MultiListField.gif') FieldRegistry.registerField(StandardFields.RadioField, 'www/RadioField.gif') FieldRegistry.registerField(StandardFields.MultiCheckBoxField, 'www/MultiCheckBoxField.gif') FieldRegistry.registerField(StandardFields.PasswordField, 'www/PasswordField.gif') FieldRegistry.registerField(StandardFields.EmailField, 'www/EmailField.gif') FieldRegistry.registerField(StandardFields.PatternField, 'www/PatternField.gif') FieldRegistry.registerField(StandardFields.FloatField, 'www/FloatField.gif') FieldRegistry.registerField(StandardFields.DateTimeField, 'www/DateTimeField.gif') FieldRegistry.registerField(StandardFields.FileField, 'www/FileField.gif') FieldRegistry.registerField(StandardFields.LinkField, 'www/LinkField.gif') FieldRegistry.registerField(StandardFields.LabelField, 'www/LabelField.gif') # some helper fields FieldRegistry.registerField(HelperFields.ListTextAreaField) FieldRegistry.registerField(HelperFields.MethodField) FieldRegistry.registerField(HelperFields.TALESField) # some other fields FieldRegistry.registerField(EmailLinesField.EmailLinesField, 'www/EmailField.gif') FieldRegistry.registerField(InterfaceField.InterfaceField, 'www/BasicField.gif') # obsolete field (same as helper; useable but not addable) FieldRegistry.registerField(StandardFields.RangedIntegerField, 'www/RangedIntegerField.gif') # register the form itself context.registerClass(Form.ZMIForm, constructors=(Form.manage_addForm, Form.manage_add), icon='www/Form.gif') # make Dummy Fields into real fields FieldRegistry.initializeFields() # do initialization of Form class to make fields addable Form.initializeForm(FieldRegistry) # register help for the product context.registerHelp()
def labelFromId(id): """ cree un label a partir de l'id majuscule premiere lettre + minuscules et espaces a la place des _""" id = Form.convert_unicode(id) id = id.replace("_", " ") id = id[0].upper() + id[1:].lower() return id.strip()
def initialize(context): """Initialize the Formulator product. """ # register field classes FieldRegistry.registerField(StandardFields.StringField, 'www/StringField.gif') FieldRegistry.registerField(StandardFields.CheckBoxField, 'www/CheckBoxField.gif') FieldRegistry.registerField(StandardFields.IntegerField, 'www/IntegerField.gif') FieldRegistry.registerField(StandardFields.TextAreaField, 'www/TextAreaField.gif') FieldRegistry.registerField(StandardFields.RawTextAreaField, 'www/TextAreaField.gif') FieldRegistry.registerField(StandardFields.LinesField, 'www/LinesField.gif') FieldRegistry.registerField(StandardFields.ListField, 'www/ListField.gif') FieldRegistry.registerField(StandardFields.MultiListField, 'www/MultiListField.gif') FieldRegistry.registerField(StandardFields.RadioField, 'www/RadioField.gif') FieldRegistry.registerField(StandardFields.MultiCheckBoxField, 'www/MultiCheckBoxField.gif') FieldRegistry.registerField(StandardFields.PasswordField, 'www/PasswordField.gif') FieldRegistry.registerField(StandardFields.EmailField, 'www/EmailField.gif') FieldRegistry.registerField(StandardFields.PatternField, 'www/PatternField.gif') FieldRegistry.registerField(StandardFields.FloatField, 'www/FloatField.gif') FieldRegistry.registerField(StandardFields.DateTimeField, 'www/DateTimeField.gif') FieldRegistry.registerField(StandardFields.FileField, 'www/FileField.gif') FieldRegistry.registerField(StandardFields.LinkField, 'www/LinkField.gif') FieldRegistry.registerField(StandardFields.LabelField, 'www/LabelField.gif') # some helper fields FieldRegistry.registerField(HelperFields.ListTextAreaField) FieldRegistry.registerField(HelperFields.MethodField) FieldRegistry.registerField(HelperFields.TALESField) # some other fields FieldRegistry.registerField( EmailLinesField.EmailLinesField, 'www/EmailField.gif') FieldRegistry.registerField( InterfaceField.InterfaceField, 'www/BasicField.gif') # obsolete field (same as helper; useable but not addable) FieldRegistry.registerField( StandardFields.RangedIntegerField, 'www/RangedIntegerField.gif') # register the form itself context.registerClass( Form.ZMIForm, constructors = (Form.manage_addForm, Form.manage_add), icon = 'www/Form.gif') # make Dummy Fields into real fields FieldRegistry.initializeFields() # do initialization of Form class to make fields addable Form.initializeForm(FieldRegistry) # register help for the product context.registerHelp()
def createForm(self): self.initializeForm() Form.manage_add(self, "form", title="formulaire", unicode_mode=True) setattr(self.form,'stored_encoding',"UTF-8") self.form.manage_addProperty("fields_on_public_form",tuple(),"lines") self.initDbTableStructureSave()