Example #1
0
    def _updateProperty(self, id, value, meta=None):
        # Update the value of an existing property. If value is a string,
        # an attempt will be made to convert the value to the type of the
        # existing property. If a mapping containing meta-data is passed,
        # it will used to _replace_ the properties meta data.
        self._wrapperCheck(value)
        if not self.hasProperty(id):
            raise BadRequest, 'The property %s does not exist.' % escape(id)
        propinfo = self.propertyInfo(id)
        if not 'w' in propinfo.get('mode', 'wd'):
            raise BadRequest, '%s cannot be changed.' % escape(id)
        if type(value) == type(''):
            proptype = propinfo.get('type', 'string')
            if type_converters.has_key(proptype):
                value = type_converters[proptype](value)
        if meta is not None:
            props = []
            pself = self.p_self()
            for prop in pself._properties:
                if prop['id'] == id: prop['meta'] = meta
                props.append(prop)
            pself._properties = tuple(props)

        if type(value) == ListType:
            value = tuple(value)
        setattr(self.v_self(), id, value)
    def setMemberProperties(self, mapping):
        """ Set extended properties on this member.
        Overridden to store a copy of certain user data fields in an SQL database.
        Dispatches to the method it over-rides, as well, so (generally) PAS can do what it
        needs to do.
        """
        # Only pass relevant fields to the database
        db_args = dict([(f, v) for (f, v) in mapping.items() if f in DB_FIELDS and self.getProperty(f) != v])
        dbtool = getToolByName(self, 'portal_moduledb', None)
        if dbtool and db_args:
            # We have to pass in aq_parent to be our own parent,
            # otheriwse the ZSQL method will acquire blank arguments
            # from the property sheet
            if not self.member_catalog(getUserName=self.getId()):
                #logger.info("INSERT memberdata for %s: %s" % (self.getId(), db_args))
                dbtool.sqlInsertMember(aq_parent=self.aq_parent, id=self.getId(), **db_args)
            else:
                #logger.info("UPDATE memberdata for %s: %s" % (self.getId(), db_args))
                dbtool.sqlUpdateMember(aq_parent=self.aq_parent, id=self.getId(), **db_args)

        # also, set property on MemberData so it can be cataloged
        tool = self.getTool()
        for id in tool.propertyIds():
            if mapping.has_key(id):
                if not self.__class__.__dict__.has_key(id):
                    value = mapping[id]
                    if type(value)==type(''):
                        proptype = tool.getPropertyType(id) or 'string'
                        if type_converters.has_key(proptype):
                            value = type_converters[proptype](value)
                        setattr(self, id, value)
        # call original
        MemberData._orig_setMemberProperties(self, mapping)
Example #3
0
    def _updateProperty(self, id, value, meta=None):
        # Update the value of an existing property. If value is a string,
        # an attempt will be made to convert the value to the type of the
        # existing property. If a mapping containing meta-data is passed,
        # it will used to _replace_ the properties meta data.
        self._wrapperCheck(value)
        if not self.hasProperty(id):
            raise BadRequest, 'The property %s does not exist.' % escape(id)
        propinfo=self.propertyInfo(id)
        if not 'w' in propinfo.get('mode', 'wd'):
            raise BadRequest, '%s cannot be changed.' % escape(id)
        if type(value)==type(''):
            proptype=propinfo.get('type', 'string')
            if type_converters.has_key(proptype):
                value=type_converters[proptype](value)
        if meta is not None:
            props=[]
            pself=self.p_self()
            for prop in pself._properties:
                if prop['id']==id: prop['meta']=meta
                props.append(prop)
            pself._properties=tuple(props)

        if type(value) == ListType:
            value = tuple(value)
        setattr(self.v_self(), id, value)
Example #4
0
    def _updateProperty(self, id, value, meta=None):
        # Update the value of an existing property. If value is a string,
        # an attempt will be made to convert the value to the type of the
        # existing property. If a mapping containing meta-data is passed,
        # it will used to _replace_ the properties meta data.
        self._wrapperCheck(value)
        if not self.hasProperty(id):
            raise BadRequest, "The property %s does not exist." % escape(id)
        propinfo = self.propertyInfo(id)
        if not "w" in propinfo.get("mode", "wd"):
            raise BadRequest, "%s cannot be changed." % escape(id)
        if type(value) == type(""):
            proptype = propinfo.get("type", "string")
            if type_converters.has_key(proptype):
                value = type_converters[proptype](value)
        if meta is not None:
            props = []
            pself = self.p_self()
            for prop in pself._properties:
                if prop["id"] == id:
                    prop["meta"] = meta
                props.append(prop)
            pself._properties = tuple(props)

        if type(value) == list:
            value = tuple(value)
        setattr(self.v_self(), id, value)
Example #5
0
 def manage_addProperty(self, id, value, type, REQUEST=None):
     """Add a new property via the web. Sets a new property with
     the given id, type, and value."""
     if type_converters.has_key(type):
         value = type_converters[type](value)
     self._setProperty(id, value, type)
     if REQUEST is not None:
         return self.manage(self, REQUEST)
Example #6
0
 def manage_addProperty(self, id, value, type, REQUEST=None):
     """Add a new property via the web. Sets a new property with
     the given id, type, and value."""
     if type_converters.has_key(type):
         value=type_converters[type](value)
     self._setProperty(id, value, type)
     if REQUEST is not None:
         return self.manage(self, REQUEST)
Example #7
0
 def manage_addProperty(self, id, value, type, label, REQUEST=None):
     """Add a new property via the web. Sets a new property with
     the given id, type, and value."""
     if type_converters.has_key(type):
         value=type_converters[type](value)
     self._setProperty(id.strip(), value, type)
     if label != '':
         self._setPropLabel(id.strip(), label)
     if REQUEST is not None:
         return self.manage_propertiesForm(self, REQUEST)
Example #8
0
 def _updateProperty(self, id, value):
     # Update the value of an existing property. If value
     # is a string, an attempt will be made to convert
     # the value to the type of the existing property.
     self._wrapperCheck(value)
     if not self.hasProperty(id):
         raise BadRequest, 'The property %s does not exist' % escape(id)
     if type(value)==type(''):
         proptype=self.getPropertyType(id) or 'string'
         if type_converters.has_key(proptype):
             value=type_converters[proptype](value)
     self._setPropValue(id, value)
Example #9
0
 def _updateProperty(self, id, value):
     # Update the value of an existing property. If value
     # is a string, an attempt will be made to convert
     # the value to the type of the existing property.
     self._wrapperCheck(value)
     if not self.hasProperty(id):
         raise BadRequest, 'The property %s does not exist' % escape(id)
     if type(value) == type(''):
         proptype = self.getPropertyType(id) or 'string'
         if type_converters.has_key(proptype):
             value = type_converters[proptype](value)
     self._setPropValue(id, value)
Example #10
0
 def setMemberProperties(self, mapping):
     '''Sets the properties of the member.
     '''
     # Sets the properties given in the MemberDataTool.
     tool = self.getTool()
     for id in tool.propertyIds():
         if mapping.has_key(id):
             if not self.__class__.__dict__.has_key(id):
                 value = mapping[id]
                 if type(value) == type(''):
                     proptype = tool.getPropertyType(id) or 'string'
                     if type_converters.has_key(proptype):
                         value = type_converters[proptype](value)
                 setattr(self, id, value)
     # Hopefully we can later make notifyModified() implicit.
     self.notifyModified()
Example #11
0
 def setMemberProperties(self, mapping):
     '''Sets the properties of the member.
     '''
     # Sets the properties given in the MemberDataTool.
     tool = self.getTool()
     for id in tool.propertyIds():
         if mapping.has_key(id):
             if not self.__class__.__dict__.has_key(id):
                 value = mapping[id]
                 if type(value)==type(''):
                     proptype = tool.getPropertyType(id) or 'string'
                     if type_converters.has_key(proptype):
                         value = type_converters[proptype](value)
                 setattr(self, id, value)
     # Hopefully we can later make notifyModified() implicit.
     self.notifyModified()
    def setMemberProperties(self, mapping):
        """ Set extended properties on this member.
        Overridden to store a copy of certain user data fields in an SQL database.
        Dispatches to the method it over-rides, as well, so (generally) PAS can do what it
        needs to do.
        """
        # Only pass relevant fields to the database
        db_args = dict([(f, v) for (f, v) in mapping.items()
                        if f in DB_FIELDS and self.getProperty(f) != v])
        dbtool = getToolByName(self, 'portal_moduledb', None)
        if dbtool and db_args:
            # We have to pass in aq_parent to be our own parent,
            # otheriwse the ZSQL method will acquire blank arguments
            # from the property sheet
            if not self.member_catalog(getUserName=self.getId()):
                #logger.info("INSERT memberdata for %s: %s" % (self.getId(), db_args))
                dbtool.sqlInsertMember(aq_parent=self.aq_parent,
                                       id=self.getId(),
                                       **db_args)
            else:
                #logger.info("UPDATE memberdata for %s: %s" % (self.getId(), db_args))
                dbtool.sqlUpdateMember(aq_parent=self.aq_parent,
                                       id=self.getId(),
                                       **db_args)

        # also, set property on MemberData so it can be cataloged
        tool = self.getTool()
        for id in tool.propertyIds():
            if mapping.has_key(id):
                if not self.__class__.__dict__.has_key(id):
                    value = mapping[id]
                    if type(value) == type(''):
                        proptype = tool.getPropertyType(id) or 'string'
                        if type_converters.has_key(proptype):
                            value = type_converters[proptype](value)
                        setattr(self, id, value)
        # call original
        MemberData._orig_setMemberProperties(self, mapping)