示例#1
0
    def setChainForPortalTypes(self, pt_names, chain, verify=True,
                               REQUEST=None):
        """ Set a chain for specific portal types.
        """
        cbt = self._chains_by_type
        if cbt is None:
            self._chains_by_type = cbt = PersistentMapping()

        if isinstance(chain, basestring):
            if chain == '(Default)':
                chain = None
            else:
                chain = [ wf.strip() for wf in chain.split(',') if wf.strip() ]

        if chain is None:
            for type_id in pt_names:
                if cbt.has_key(type_id):
                    del cbt[type_id]
            return

        ti_ids = [ t.getId() for t in self._listTypeInfo() ]

        for type_id in pt_names:
            if verify and not (type_id in ti_ids):
                continue
            cbt[type_id] = tuple(chain)
示例#2
0
 def setGlobalConfigurationAttr(self, **kw):
     """ Set global business configuration attribute. """
     if getattr(aq_base(self), '_global_configuration_attributes',
                None) is None:
         self._global_configuration_attributes = PersistentMapping()
     for key, value in kw.items():
         self._global_configuration_attributes[key] = value
示例#3
0
    def wl_lockmapping(self, killinvalids=0, create=0):
        """ if 'killinvalids' is 1, locks who are no longer valid
        will be deleted """

        try:
            locks = getattr(self, '_dav_writelocks', None)
        except:
            locks = None

        if locks is None:
            if create:
                locks = self._dav_writelocks = PersistentMapping()
            else:
                # Don't generate a side effect transaction.
                locks = {}
            return locks
        elif killinvalids:
            # Delete invalid locks
            for token, lock in locks.items():
                if not lock.isValid():
                    del locks[token]
            if (not locks) and hasattr(Acquisition.aq_base(self),
                                       '__no_valid_write_locks__'):
                self.__no_valid_write_locks__()
            return locks
        else:
            return locks
示例#4
0
def _initDCWorkflowWorklists(workflow, worklists):
    """ Initialize DCWorkflow worklists
    """
    from Globals import PersistentMapping
    from Products.DCWorkflow.Worklists import WorklistDefinition

    for w_info in worklists:

        id = str(w_info['worklist_id'])  # no unicode!
        w = WorklistDefinition(id)
        workflow.worklists._setObject(id, w)

        w = workflow.worklists._getOb(id)

        action = w_info['action']

        guard = w_info['guard']
        props = {
            'guard_roles': ';'.join(guard['roles']),
            'guard_permissions': ';'.join(guard['permissions']),
            'guard_groups': ';'.join(guard['groups']),
            'guard_expr': guard['expression']
        }

        w.setProperties(description=w_info['description'],
                        actbox_name=action['name'],
                        actbox_url=action['url'],
                        actbox_category=action['category'],
                        props=props)

        w.var_matches = PersistentMapping()
        for k, v in w_info['match'].items():
            w.var_matches[str(k)] = tuple([str(x) for x in v])
示例#5
0
 def setProperties(self,
                   description,
                   actbox_name='',
                   actbox_url='',
                   actbox_category='global',
                   props=None,
                   REQUEST=None):
     '''
     '''
     if props is None:
         props = REQUEST
     self.description = str(description)
     for key in self.getAvailableCatalogVars():
         # Populate var_matches.
         fieldname = 'var_match_%s' % key
         v = props.get(fieldname, '')
         if v:
             if not self.var_matches:
                 self.var_matches = PersistentMapping()
             self.var_matches[key] = str(v)
         else:
             if self.var_matches and self.var_matches.has_key(key):
                 del self.var_matches[key]
     self.actbox_name = str(actbox_name)
     self.actbox_url = str(actbox_url)
     self.actbox_category = str(actbox_category)
     g = Guard()
     if g.changeFromProperties(props or REQUEST):
         self.guard = g
     else:
         self.guard = None
     if REQUEST is not None:
         return self.manage_properties(REQUEST, 'Properties changed.')
示例#6
0
 def setMultiEntryTransition(self, transition_url, max_entry_number):
     """ Set a transition as multiple - i.e max_entry_number of forms 
     which will be rendered. This method is called in after scripts
     and usually this number is set by user in a web form. """
     if getattr(aq_base(self), '_multi_entry_transitions', None) is None:
         self._multi_entry_transitions = PersistentMapping()
     self._multi_entry_transitions[transition_url] = max_entry_number
示例#7
0
def _initDCWorkflowStates(workflow, states):
    """ Initialize DCWorkflow states
    """
    from Globals import PersistentMapping
    from Products.DCWorkflow.States import StateDefinition

    for s_info in states:

        id = str(s_info['state_id'])  # no unicode!
        s = StateDefinition(id)
        workflow.states._setObject(id, s)
        s = workflow.states._getOb(id)

        s.setProperties(title=s_info['title'],
                        description=s_info['description'],
                        transitions=s_info['transitions'])

        for k, v in s_info['permissions'].items():
            s.setPermission(k, type(v) is type([]), v)

        vmap = s.var_values = PersistentMapping()

        for name, v_info in s_info['variables'].items():

            value = _convertVariableValue(v_info['value'], v_info['type'])

            vmap[name] = value
示例#8
0
def install(self):
    " Register the CMF Topic with portal_types and friends "
    out = StringIO()
    typestool = getToolByName(self, 'portal_types')
    skinstool = getToolByName(self, 'portal_skins')
    workflowtool = getToolByName(self, 'portal_workflow')

    # Borrowed from CMFDefault.Portal.PortalGenerator.setupTypes()
    # We loop through anything defined in the factory type information
    # and configure it in the types tool if it doesn't already exist
    for t in CMFWikiPage.factory_type_information:
        if t['id'] not in typestool.objectIds():
            cfm = apply(ContentFactoryMetadata, (), t)
            typestool._setObject(t['id'], cfm)
            out.write('Registered %s with the types tool\n' % t['id'])
        else:
            out.write('Object "%s" already existed in the types tool\n' %
                      (t['id']))

    # Setup the skins
    # This is borrowed from CMFDefault/scripts/addImagesToSkinPaths.pys
    if 'wiki' not in skinstool.objectIds():
        # We need to add Filesystem Directory Views for any directories
        # in our skins/ directory.  These directories should already be
        # configured.
        addDirectoryViews(skinstool, 'skins', wiki_globals)
        out.write("Added 'wiki' directory view to portal_skins\n")

    # Now we need to go through the skin configurations and insert
    # 'wiki' into the configurations.  Preferably, this should be
    # right before where 'content' is placed.  Otherwise, we append
    # it to the end.
    skins = skinstool.getSkinSelections()
    for skin in skins:
        path = skinstool.getSkinPath(skin)
        path = map(string.strip, string.split(path, ','))
        for dir in ('wiki', 'zpt_wiki'):

            if not dir in path:
                try:
                    idx = path.index('custom')
                except ValueError:
                    idx = 999
                path.insert(idx + 1, dir)

        path = string.join(path, ', ')
        # addSkinSelection will replace existing skins as well.
        skinstool.addSkinSelection(skin, path)
        out.write("Added 'wiki' and 'zpt_wiki' to %s skin\n" % skin)

    # remove workflow for Wiki pages
    cbt = workflowtool._chains_by_type
    if cbt is None:
        cbt = PersistentMapping()
    cbt['CMF Wiki'] = []
    cbt['CMF Wiki Page'] = []
    workflowtool._chains_by_type = cbt
    out.write("Removed all workflow from CMF Wikis and CMF Wiki Pages")
    return out.getvalue()
示例#9
0
def _getCentralRefreshData(jar, create=0):
    root = jar.root()
    if root.has_key('RefreshData'):
        rd = root['RefreshData']
    else:
        rd = PersistentMapping()
        if create:
            root['RefreshData'] = rd
    return rd
示例#10
0
文件: States.py 项目: bendavis78/zope
    def addVariable(self,id,value,REQUEST=None):
        """Add a WorkflowVariable to State."""
        if self.var_values is None:
            self.var_values = PersistentMapping()

        self.var_values[id] = value

        if REQUEST is not None:
            return self.manage_variables(REQUEST, 'Variable added.')
示例#11
0
文件: States.py 项目: bendavis78/zope
 def setPermission(self, permission, acquired, roles):
     """Set a permission for this State."""
     pr = self.permission_roles
     if pr is None:
         self.permission_roles = pr = PersistentMapping()
     if acquired:
         roles = list(roles)
     else:
         roles = tuple(roles)
     pr[permission] = roles
示例#12
0
def make_config_persistent(kwargs):
    """ iterates on the given dictionnary and replace list by persistent list,
    dictionary by persistent mapping.
    """
    for key, value in kwargs.items():
        if type(value) == type({}):
            p_value = PersistentMapping(value)
            kwargs[key] = p_value
        elif type(value) in (type(()), type([])):
            p_value = PersistentList(value)
            kwargs[key] = p_value
示例#13
0
 def migrateDiscussionContainer(self, src_folder, dst_folder, place=()):
     self.visited_folders.append( '/'.join(place) )
     dst_container = getattr(dst_folder, '_container', None)
     if dst_container is None:
         dst_container = dst_folder._container = PersistentMapping()
     for id, s_ob in src_folder._container.items():
         d_ob = dst_container.get(id)
         to_store = self.migrateObject(id, s_ob, d_ob, dst_folder,
                                       place + (id,))
         if to_store is not None:
             dst_container[id] = aq_base(to_store)
示例#14
0
 def setPermission(self, permission, acquired, roles):
     '''
     '''
     pr = self.permission_roles
     if pr is None:
         self.permission_roles = pr = PersistentMapping()
     if acquired:
         roles = list(roles)
     else:
         roles = tuple(roles)
     pr[permission] = roles
示例#15
0
文件: States.py 项目: bendavis78/zope
    def setVariables(self, ids=[], REQUEST=None):
        """Set values for Variables set by this State."""
        if self.var_values is None:
            self.var_values = PersistentMapping()

        vv = self.var_values

        if REQUEST is not None:
            for id in vv.keys():
                fname = 'varval_%s' % id
                vv[id] = str(REQUEST[fname])
            return self.manage_variables(REQUEST, 'Variables changed.')
示例#16
0
    def setChainForPortalTypes(self, pt_names, chain):
        """ Set a chain for a specific portal type """
        cbt = self._chains_by_type
        if cbt is None:
            self._chains_by_type = cbt = PersistentMapping()

        if type(chain) is type(''):
            chain = map(strip, split(chain, ','))

        ti = self._listTypeInfo()
        for t in ti:
            id = t.getId()
            if id in pt_names:
                cbt[id] = tuple(chain)
示例#17
0
def enableAutoRefresh(jar, productid, enable):
    productid = str(productid)
    rd = _getCentralRefreshData(jar, 1)
    ids = rd.get('auto', None)
    if ids is None:
        if enable:
            rd['auto'] = ids = PersistentMapping()
        else:
            return
    if enable:
        ids[productid] = 1
    else:
        if ids.has_key(productid):
            del ids[productid]
示例#18
0
 def addVariable(self, id, text, REQUEST=None):
     '''
     Add a variable expression.
     '''
     if self.var_exprs is None:
         self.var_exprs = PersistentMapping()
     
     expr = None
     if text:
       expr = Expression(str(text))
     self.var_exprs[id] = expr
     
     if REQUEST is not None:
         return self.manage_variables(REQUEST, 'Variable added.')
示例#19
0
    def setChainForPortalTypes(self, pt_names, chain):
        """ Set a chain for a specific portal type.
        """
        cbt = self._chains_by_type
        if cbt is None:
            self._chains_by_type = cbt = PersistentMapping()

        if isinstance(chain, basestring):
            chain = [wf.strip() for wf in chain.split(',') if wf.strip()]

        ti = self._listTypeInfo()
        for t in ti:
            id = t.getId()
            if id in pt_names:
                cbt[id] = tuple(chain)
示例#20
0
    def setRoleMapping(self, portal_role, userfolder_role):
        """
        set the mapping of roles between roles understood by 
        the portal and roles coming from outside user sources
        """
        if not hasattr(self, 'role_map'): self.role_map = PersistentMapping()

        if len(userfolder_role) < 1:
            del self.role_map[portal_role]
        else:
            self.role_map[portal_role] = userfolder_role

        return MessageDialog(title='Mapping updated',
                             message='The Role mappings have been updated',
                             action='manage_mapRoles')
示例#21
0
    def setChainForPortalTypes(self, pt_names, chain, verify=True):
        """ Set a chain for a specific portal type.
        """
        cbt = self._chains_by_type
        if cbt is None:
            self._chains_by_type = cbt = PersistentMapping()

        if isinstance(chain, basestring):
            chain = [wf.strip() for wf in chain.split(',') if wf.strip()]

        ti_ids = [t.getId() for t in self._listTypeInfo()]

        for type_id in pt_names:
            if verify and not (type_id in ti_ids):
                continue
            cbt[type_id] = tuple(chain)
示例#22
0
文件: States.py 项目: bendavis78/zope
 def setPermissions(self, REQUEST):
     """Set the permissions in REQUEST for this State."""
     pr = self.permission_roles
     if pr is None:
         self.permission_roles = pr = PersistentMapping()
     for p in self.getManagedPermissions():
         roles = []
         acquired = REQUEST.get('acquire_' + p, 0)
         for r in self.getAvailableRoles():
             if REQUEST.get('%s|%s' % (p, r), 0):
                 roles.append(r)
         roles.sort()
         if not acquired:
             roles = tuple(roles)
         pr[p] = roles
     return self.manage_permissions(REQUEST, 'Permissions changed.')
示例#23
0
    def __init__(
            self,
            publisher=None
        #, initial_values_hook=None
        #, validation_hook=None
        ,
            element_specs=DEFAULT_ELEMENT_SPECS):

        self.editProperties(publisher
                            #, initial_values_hook
                            #, validation_hook
                            )

        self.element_specs = PersistentMapping()

        for name, is_multi_valued in element_specs:
            self.element_specs[name] = ElementSpec(is_multi_valued)
示例#24
0
 def setStatusOf(self, wf_id, ob, status):
     """ Append a record to the workflow history of a given workflow.
     """
     wfh = None
     has_history = 0
     if hasattr(aq_base(ob), 'workflow_history'):
         history = ob.workflow_history
         if history is not None:
             has_history = 1
             wfh = history.get(wf_id, None)
             if wfh is not None:
                 wfh = list(wfh)
     if not wfh:
         wfh = []
     wfh.append(status)
     if not has_history:
         ob.workflow_history = PersistentMapping()
     ob.workflow_history[wf_id] = tuple(wfh)
示例#25
0
def po_import(self, lang, data):
    """ """
    messages = self._messages

    resource = memory.File(data)
    po = PO.PO(resource)

    # Load the data
    for msgid in po.get_msgids():
        if isinstance(msgid, unicode): msgid = msgid.encode('utf-8')
        if msgid:
            msgstr = po.get_msgstr(msgid) or ''
            if not messages.has_key(msgid):
                messages[msgid] = PersistentMapping()
            messages[msgid][lang] = msgstr

        # Set the encoding (the full header should be loaded XXX)
        self.update_po_header(lang, charset=po.get_encoding())
示例#26
0
    def setVariables(self, ids=[], REQUEST=None):
        ''' set values for Variables set by this state
        '''
        if self.var_exprs is None:
            self.var_exprs = PersistentMapping()
 
        ve = self.var_exprs
 
        if REQUEST is not None:
            for id in ve.keys():
                fname = 'varexpr_%s' % id

                val = REQUEST[fname]
                expr = None
                if val:
                    expr = Expression(str(REQUEST[fname]))
                ve[id] = expr

            return self.manage_variables(REQUEST, 'Variables changed.')
示例#27
0
 def setStatusOf(self, wf_id, ob, status):
     '''
     Invoked by workflow definitions.  Appends to the workflow history.
     '''
     wfh = None
     has_history = 0
     if hasattr(aq_base(ob), 'workflow_history'):
         history = ob.workflow_history
         if history is not None:
             has_history = 1
             wfh = history.get(wf_id, None)
             if wfh is not None:
                 wfh = list(wfh)
     if not wfh:
         wfh = []
     wfh.append(status)
     if not has_history:
         ob.workflow_history = PersistentMapping()
     ob.workflow_history[wf_id] = tuple(wfh)
示例#28
0
    def manage_changeWorkflows(self, default_chain, props=None, REQUEST=None):

        """ Changes which workflows apply to objects of which type.
        """
        if props is None:
            props = REQUEST
        cbt = self._chains_by_type
        if cbt is None:
            self._chains_by_type = cbt = PersistentMapping()
        ti = self._listTypeInfo()
        # Set up the chains by type.
        if not (props is None):
            for t in ti:
                id = t.getId()
                field_name = 'chain_%s' % id
                chain = props.get(field_name, '(Default)').strip()
                if chain == '(Default)':
                    # Remove from cbt.
                    if cbt.has_key(id):
                        del cbt[id]
                else:
                    chain = chain.replace(',', ' ')
                    ids = []
                    for wf_id in chain.split(' '):
                        if wf_id:
                            if not self.getWorkflowById(wf_id):
                                raise ValueError, (
                                    '"%s" is not a workflow ID.' % wf_id)
                            ids.append(wf_id)
                    cbt[id] = tuple(ids)
        # Set up the default chain.
        default_chain = default_chain.replace(',', ' ')
        ids = []
        for wf_id in default_chain.split(' '):
            if wf_id:
                if not self.getWorkflowById(wf_id):
                    raise ValueError, (
                        '"%s" is not a workflow ID.' % wf_id)
                ids.append(wf_id)
        self._default_chain = tuple(ids)
        if REQUEST is not None:
            return self.manage_selectWorkflows(REQUEST,
                            manage_tabs_message='Changed.')
示例#29
0
    def wl_clearLocks(self):
        # Called by lock management machinery to quickly and effectively
        # destroy all locks.
        try:
            locks = self.wl_lockmapping()
            locks.clear()
        except:
            # The locks may be totally messed up, so we'll just delete
            # and replace.
            if hasattr(self, '_dav_writelocks'):
                del self._dav_writelocks
            if IWriteLock.providedBy(self) or \
                    WriteLockInterface.isImplementedBy(self):
                self._dav_writelocks = PersistentMapping()

        # Call into a special hook used by LockNullResources to delete
        # themselves.  Could be used by other objects who want to deal
        # with the state of empty locks.
        if hasattr(Acquisition.aq_base(self), '__no_valid_write_locks__'):
            self.__no_valid_write_locks__()
示例#30
0
文件: States.py 项目: bendavis78/zope
 def setGroups(self, REQUEST, RESPONSE=None):
     """Set the group to role mappings in REQUEST for this State.
     """
     map = self.group_roles
     if map is None:
         self.group_roles = map = PersistentMapping()
     map.clear()
     all_roles = self.getWorkflow().getRoles()
     for group in self.getWorkflow().getGroups():
         roles = []
         for role in all_roles:
             if REQUEST.get('%s|%s' % (group, role), 0):
                 roles.append(role)
         roles.sort()
         roles = tuple(roles)
         map[group] = roles
     if RESPONSE is not None:
         RESPONSE.redirect(
             "%s/manage_groups?manage_tabs_message=Groups+changed."
             % self.absolute_url())