Esempio n. 1
0
    def computeMethodName(self, field, mode):
        if mode not in _modes.keys():
            raise TypeError("Unsupported Mode %s in field: %s (%s)" %
                            (field.getName(), mode))

        prefix = _modes[mode]['prefix']
        name = capitalize(field.getName())
        return "%s%s" % (prefix, name)
Esempio n. 2
0
    def computeMethodName(self, field, mode):
        if mode not in _modes.keys():
            raise TypeError("Unsupported Mode %s in field: %s (%s)" % \
                            (field.getName(), mode))

        prefix = _modes[mode]['prefix']
        name   = capitalize(field.getName())
        return "%s%s" % (prefix, name)
Esempio n. 3
0
 def populateProps(self, field):
     """This is called when the field is created."""
     name = field.getName()
     if not self.label:
         self.label = capitalize(name)
    def Schema(self, schema_id=None):
        """ Retrieve schema from parent object. The client class should
            override the method as Schema(self) and then call his method
            of the baseclass with the corresponding schema_id.
        """

        # Schema() seems to be called during the construction phase when there is
        # no acquisition context. So we return the default schema itself.
        # ATT: mind the difference btn 'hasattr' and 'shasattr' (latter strips acq)
        if not hasattr(self, 'aq_parent') or self.id.find('atse-ptypedummy')>=0:
            if shasattr(self, 'schema'):
                return self._wrap_schema(self.schema)
            else:
                raise ValueError('Instance has no "schema" attribute defined')
            
        provider = self.lookup_provider()
        if not ISchemaEditor.providedBy(provider):
            raise SchemaEditorError, 'Provider -- %s -- can not be recognized as Archetypes Schema Editor! Perhaps you are using ParentManagedSchema derived objects with Tool. A tool can only manage ToolManagedSchema (ParentOrToolManagedSchema) derived objects.' % str(provider).replace('<', '').replace('>','')

        if not self.lookup_provider().atse_isSchemaRegistered(self.portal_type):
            return self._wrap_schema(self.schema)

        # If we're called by the generated methods we can not rely on
        # the id and need to check for portal_type
        if not schema_id:
            schema_id = self.portal_type
            
        # Otherwise get the schema from the parent through
        # acquisition and assign it to a volatile attribute for performance
        # reasons
        self._v_schema = getattr(self, '_v_schema', None)
        if self._v_schema is None:

            # looking for changes in the schema held by the object
            LOG('ATSchemaEditorNG', INFO, 'Looking up changes via lookupChanges() - _v_schema is None')
            self._v_schema = self._lookupChanges(schema_id)

            if not shasattr(self, '_md'):
                self.initializeArchetype()

            for field in self._v_schema.fields():

                ##########################################################
                # Fake accessor and mutator methods
                ##########################################################

                # XXX currently only honoring explicitly specified mutators
                #     or accessors if the method exists on the object.  if
                #     the methods are autogenerated the specified names will
                #     not be honored.

                name = field.getName()

                def atse_get_method(self=self, name=name, *args, **kw):
                    return self.getField(name).get(self, **kw)

                def atse_getRaw_method(self=self, name=name, *args, **kw):
                    return self.getField(name).getRaw(self, **kw)

                # workaround for buggy widget/keyword AT template that
                # uses field.accessor as catalog index name *grrrr*
                # XXX find another way to fix that
                if name != 'subject':
                    accessor_name = getattr(field, 'accessor', None)
                    if accessor_name and shasattr(self, accessor_name):
                        pass # the accessor exists, we're cool
                    else:
                        v_name = '_v_%s_accessor' % name
                        accessor_name = v_name
                        setattr(self, v_name, atse_get_method)
                    field.accessor = accessor_name
                    
                    # the edit accessor and the regular accessor can be the
                    # same in most cases, but not for ReferenceFields
                    # XXX any other cases?
                    
                    # test for special cases where there is no
                    # getter with conformant naming scheme
                    con_name = capitalize(field.getName())
                    dogenerate = not shasattr(self, 'get%s' % con_name)

                    edit_accessor_name = getattr(field, 'edit_accessor', None)
                    if edit_accessor_name and shasattr(self, edit_accessor_name) and not dogenerate:
                        pass # the edit_accessor_name exists, we're cool
                    else:
                        edit_v_name = '_v_%s_edit_accessor' % name
                        edit_accessor_name = edit_v_name
                        field_type = str(field.type).upper()
                        if field_type == 'REFERENCE':
                            setattr(self, edit_accessor_name, atse_getRaw_method)
                        else:
                            setattr(self, edit_accessor_name, atse_get_method)
                    field.edit_accessor = edit_accessor_name

                def atse_set_method(value, self=self, name=name, *args, **kw):
                    if name != 'id':
                         self.getField(name).set(self, value, **kw)
                        
                    # saving id directly (avoiding unicode problems)
                    else: self.setId(value)

                mutator_name = getattr(field, 'mutator', None)
                if mutator_name and shasattr(self, mutator_name):
                    pass # the mutator exists, we're cool
                else:
                    v_name = '_v_%s_mutator' % name
                    mutator_name = v_name
                    setattr(self, v_name, atse_set_method)
                field.mutator = mutator_name

                # Check if we need to update our own properties
                try:
                    value = field.get(self)
                except:
                    field.set(self, field.default)

        return self._wrap_schema(self._v_schema)
Esempio n. 5
0
def outputContentFile(self, imported_class):
    out = StringIO()
    trans = getToolByName(self, 'translation_service', None)
    utranslate = trans.utranslate
    obj = imported_class("object_id")

    values = dict()

    values['meta_type'] = obj.meta_type
    values['archetype_name'] = obj.archetype_name

    printout(out, obj.meta_type)
    printout(out, '')
    printout(out, '  archetype_name: ' + obj.meta_type)
    printout(out, '')
    schemata_names = obj.schema.getSchemataNames()
    exclude_schemata = ('metadata',)
    schemata_names = [s for s in schemata_names if s not in exclude_schemata]
    printout(out, '')
    printout(out, '  All schemata (except metadata):')
    printout(out, '    %s' % ', '.join(schemata_names))
#    for schemata_name in schemata_names:
#        printout(out, '    %s' %schemata_name)
    printout(out, '')
    for schemata_name in schemata_names:
        printout(out, '    schemata: %s' %schemata_name)
        printout(out, '')
        for field in obj.Schema().filterFields(schemata=schemata_name):
            printout(out, '      field: %s' %field.__name__)
            printout(out, '')
            printout(out, '        field type: %s' %field.type)
            printout(out, '        required: %s' %bool(field.required))
            if field.default:
                printout(out, '        default: %s' %str(field.default))
            if field.default_method is not None:
                printout(out, '        default_method: %s' \
                                                    %field.default_method)
            if field.vocabulary is not ():
                printout(out, '        vocabulary: %s' %str(field.vocabulary))
            if field.enforceVocabulary:
                printout(out, '        enforceVocabulary: %s' \
                                                %bool(field.enforceVocabulary))
            printout(out, '        Multivalued: %s' %bool(field.required))
            printout(out, '        Searchable: %s' %bool(field.required))
            if field.isMetadata:
                printout(out, '        isMetadata: %s' %bool(field.isMetadata))

            capName = capitalize(field.getName())
            if field.accessor != 'get'+capName:
                printout(out, '        accessor: %s' %field.accessor)
            if field.edit_accessor != 'getRaw'+capName:
                printout(out, '        edit_accessor: %s' %field.edit_accessor)
            if field.mutator != 'set'+capName:
                printout(out, '        mutator: %s' %field.mutator)
            if field.mode != 'rw':
                printout(out, '        mode: %s' %field.mode)

            if field.read_permission != 'View':
                printout(out, '        read_permission: %s' \
                                                        %field.read_permission)
            if field.write_permission != 'Modify portal content':
                printout(out, '        write_permission: %s' \
                                                    %field.write_permission)

#            printout(out, '        storage: %s' %field.storage.getName())

#            printout(out, '        generateMode: %s' %field.generateMode)
#            printout(out, '        force: %s' %field.force)

            printout(out, '        widget: %s' %field.widget.getName())
            printout(out, '          widget label: %s' %field.widget.label)
#            if hasattr(field.widget, 'domain'):
#                domain = field.widget.domain
#            else:
#                domain = 'plone'
#            if hasattr(field.widget, 'label_msgid'):
#                printout(out, '          widget label msg_id: %s' \
#                                                    %field.widget.label_msgid)
#                printout(out, '          widget label (fr): %s' \
#                            %utranslate(domain,
#                                        field.widget.label_msgid,
#                                        target_language='fr'))
            if field.widget.description:
                printout(out, '          widget description: %s' \
                                                    %field.widget.description)

#            printout(out, '        validators: %s' %str(field.validators))

            printout(out, '        index: %s' %field.index)
            if field.index_method != '_at_accessor':
                printout(out, '        index_method: %s' %field.index_method)

#            printout(out, '        languageIndependent: %s' %field.languageIndependent)
            printout(out, '')
            printout(out, '        index priority: ')
            printout(out, '')


    return out.getvalue()
Esempio n. 6
0
 def populateProps(self, field):
     """This is called when the field is created."""
     name = field.getName()
     if not self.label:
         self.label = capitalize(name)
Esempio n. 7
0
def outputContentFile(self, imported_class):
    out = StringIO()
    trans = getToolByName(self, 'translation_service', None)
    utranslate = trans.utranslate
    obj = imported_class("object_id")

    values = dict()

    values['meta_type'] = obj.meta_type
    values['archetype_name'] = obj.archetype_name

    printout(out, obj.meta_type)
    printout(out, '')
    printout(out, '  archetype_name: ' + obj.meta_type)
    printout(out, '')
    schemata_names = obj.schema.getSchemataNames()
    exclude_schemata = ('metadata', )
    schemata_names = [s for s in schemata_names if s not in exclude_schemata]
    printout(out, '')
    printout(out, '  All schemata (except metadata):')
    printout(out, '    %s' % ', '.join(schemata_names))
    #    for schemata_name in schemata_names:
    #        printout(out, '    %s' %schemata_name)
    printout(out, '')
    for schemata_name in schemata_names:
        printout(out, '    schemata: %s' % schemata_name)
        printout(out, '')
        for field in obj.Schema().filterFields(schemata=schemata_name):
            printout(out, '      field: %s' % field.__name__)
            printout(out, '')
            printout(out, '        field type: %s' % field.type)
            printout(out, '        required: %s' % bool(field.required))
            if field.default:
                printout(out, '        default: %s' % str(field.default))
            if field.default_method is not None:
                printout(out, '        default_method: %s' \
                                                    %field.default_method)
            if field.vocabulary is not ():
                printout(out, '        vocabulary: %s' % str(field.vocabulary))
            if field.enforceVocabulary:
                printout(out, '        enforceVocabulary: %s' \
                                                %bool(field.enforceVocabulary))
            printout(out, '        Multivalued: %s' % bool(field.required))
            printout(out, '        Searchable: %s' % bool(field.required))
            if field.isMetadata:
                printout(out,
                         '        isMetadata: %s' % bool(field.isMetadata))

            capName = capitalize(field.getName())
            if field.accessor != 'get' + capName:
                printout(out, '        accessor: %s' % field.accessor)
            if field.edit_accessor != 'getRaw' + capName:
                printout(out,
                         '        edit_accessor: %s' % field.edit_accessor)
            if field.mutator != 'set' + capName:
                printout(out, '        mutator: %s' % field.mutator)
            if field.mode != 'rw':
                printout(out, '        mode: %s' % field.mode)

            if field.read_permission != 'View':
                printout(out, '        read_permission: %s' \
                                                        %field.read_permission)
            if field.write_permission != 'Modify portal content':
                printout(out, '        write_permission: %s' \
                                                    %field.write_permission)

#            printout(out, '        storage: %s' %field.storage.getName())

#            printout(out, '        generateMode: %s' %field.generateMode)
#            printout(out, '        force: %s' %field.force)

            printout(out, '        widget: %s' % field.widget.getName())
            printout(out, '          widget label: %s' % field.widget.label)
            #            if hasattr(field.widget, 'domain'):
            #                domain = field.widget.domain
            #            else:
            #                domain = 'plone'
            #            if hasattr(field.widget, 'label_msgid'):
            #                printout(out, '          widget label msg_id: %s' \
            #                                                    %field.widget.label_msgid)
            #                printout(out, '          widget label (fr): %s' \
            #                            %utranslate(domain,
            #                                        field.widget.label_msgid,
            #                                        target_language='fr'))
            if field.widget.description:
                printout(out, '          widget description: %s' \
                                                    %field.widget.description)

#            printout(out, '        validators: %s' %str(field.validators))

            printout(out, '        index: %s' % field.index)
            if field.index_method != '_at_accessor':
                printout(out, '        index_method: %s' % field.index_method)

#            printout(out, '        languageIndependent: %s' %field.languageIndependent)
            printout(out, '')
            printout(out, '        index priority: ')
            printout(out, '')

    return out.getvalue()