Logo Search packages:      
Sourcecode: zope-atseng version File versions  Download package

def ATSchemaEditorNG::SchemaEditor::SchemaEditor::atse_update (   self,
  schema_id,
  schema_template,
  fielddata,
  REQUEST,
  RESPONSE = None 
)

update a single field

Definition at line 466 of file SchemaEditor.py.

                                           :
        """ update a single field"""
        S = self.atse_getSchemaById(schema_id)
        R = REQUEST.form
        FD = fielddata

        if R.has_key('add_field'):
            self.atse_addField(schema_id, FD.schemata, schema_template,
                               R['name'], RESPONSE)
            return            
            
        field = TYPE_MAP.get(FD.type, None)
        if not field:
            raise SchemaEditorError(self.translate('atse_unknown_field', 
                                              {'field' : FD.type},
                                             default='unknown field type: $field',
                                             domain='ATSchemaEditorNG')) 

        D = {}    # dict to be passed to the field constructor
        D['default'] = FD.get('default', '')
        D['schemata'] = FD.schemata
        D['createindex'] = FD.get('createindex', 0)
        storageInfo = self.atse_getStorageMap()[FD.get('storage')]
        D['storage'] = storageInfo['storage']
        
        # call storage data processing method
        if storageInfo.has_key('post_method') and R.get('storage_data'):
            post_method = getattr(storageInfo['storage'], storageInfo['post_method'] )
            post_method(context=self, 
                        public_name = FD.name, 
                        storage_data = R.get('storage_data'))
   
        # build widget
        widget_data = self.atse_getWidgetMap().get(FD.widget, None)
        if not widget_data:
            raise SchemaEditorError(self.translate('atse_unknown_widget', 
                                                  {'widget' : FD.widget},
                                                  default='unknown widget type: $widget',
                                                  domain='ATSchemaEditorNG'))
        widget = widget_data['widget'].copy()

        # support for relations
        D['relationship'] = FD.get('relationship', 'defaultRelation')

        widget.size = FD.get('widgetsize', 60)
        widget.rows = FD.get('widgetrows', 5)
        widget.cols = FD.get('widgetcols', 60)
        maxlength =  FD.get('widgetmaxlength')
        if maxlength:
            widget.maxlength = maxlength

        # setting visibility of field
        widget.visible = {'edit' : 'visible', 'view' : 'visible'}
        if not FD.has_key('visible_edit'):
            widget.visible['edit'] = 'invisible'

        if not FD.has_key('visible_view'):
            widget.visible['view'] = 'invisible'

        if FD.has_key('description'):
            widget.description = FD['description']

        # Validators
        if FD.has_key('validators'):
            validators = tuple([v.strip() for v in FD['validators'].split(',')])
            if validators:
                D['validators'] = validators
                
        widget.label = FD.label
        widget.label_msgid = 'label_' + FD.label
        widget.i18n_domain = S._i18n_domain

        D['widget'] = widget

        # build DisplayList instance for SelectionWidgets
        widget_map = self.atse_getWidgetMap()
        if widget_map[FD.widget].get('useVocab'):
            vocab = FD.get('vocabulary', [])

            # The vocabulary can either be a list of string of 'values'
            # or a list of strings 'key|value' or a list with *one*
            # string 'method:<methodname>'. 'method:<methodname>' is used
            # specify a method that is called to retrieve a DisplayList
            # instance

            if len(vocab) == 1 and vocab[0].startswith('method:'):
                dummy,method = vocab[0].split(':')
                D['vocabulary'] = method.strip()
            else:
                l = []
                for line in vocab:
                    line = line.strip()
                    if not line: continue
                    if '|' in line:
                        k,v = line.split('|', 1)
                    else:
                        k = v = line

                    k = remove_unallowed_chars(k)
                    l.append( (k,v))

                D['vocabulary'] = DisplayList(l)

        D['required'] = FD.get('required', 0)

        newfield = field(FD.name, **D)

        # call custom data processing method
        if hasattr(self, '_post_method_name'):
            post_method = getattr(self, self._post_method_name)
            post_method(context=self,
                        field=newfield,
                        custom_data=R.get('custom_data'))

        S.replaceField(FD.name, newfield)
        self._schemas[schema_id] = S

        util.redirect(RESPONSE, schema_template,
                      self.translate('atse_field_changed', default='Field changed', domain='ATSchemaEditorNG'), 
                      schema_id=schema_id,
                      schemata=FD.schemata, 
                      field=FD.name)


    ######################################################################


Generated by  Doxygen 1.6.0   Back to index