Ejemplo n.º 1
0
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # Auto-fill the oauth_server from max_server info endpoint
        maxclient = MaxClient(url=data['max_server'])
        data['oauth_server'] = maxclient.oauth_server

        self.applyChanges(data)

        # Imports required to be here because of circular dependencies
        from mrs5.max.utilities import IMAXClient
        from mrs5.max.utilities import IHubClient
        # Update the connection to the (singleton) clients utilities
        maxclient = getUtility(IMAXClient)
        maxclient.create_new_connection()

        hubclient = getUtility(IHubClient)
        hubclient.create_new_connection()

        notify(ConfigurationChangedEvent(self, data))

        IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
                                                      "info")
        self.context.REQUEST.RESPONSE.redirect("@@maxui-settings")
Ejemplo n.º 2
0
    def handleSave(self, action):
        CheckAuthenticator(self.request)
        data, errors = self.extractData()

        # extra validation for email
        self.validate_email(action, data)

        if action.form.widgets.errors:
            self.status = self.formErrorsMessage
            return
        if self.applyChanges(data):
            IStatusMessage(self.request).addStatusMessage(self.successMessage,
                                                          type='info')
            notify(ConfigurationChangedEvent(self, data))
            self._on_save(data)
        else:
            IStatusMessage(self.request).addStatusMessage(
                self.noChangesMessage, type='info')
        self.request.response.redirect(self.action())
Ejemplo n.º 3
0
    def handleSave(self, action):
        CheckAuthenticator(self.request)
        data, errors = self.extractData()

        # Extra validation for email, when it is there.  email is not in the
        # data when you are at the personal-preferences page.
        if 'email' in data:
            self.validate_email(action, data)

        if action.form.widgets.errors:
            self.status = self.formErrorsMessage
            return
        if self.applyChanges(data):
            IStatusMessage(self.request).addStatusMessage(
                self.successMessage, type='info')
            notify(ConfigurationChangedEvent(self, data))
            self._on_save(data)
        else:
            IStatusMessage(self.request).addStatusMessage(
                self.noChangesMessage, type='info')
        self.request.response.redirect(self.action())
Ejemplo n.º 4
0
    def __call__(self):
        """Perform the update and redirect if necessary, or render the page
        """
        postback = True
        context = aq_inner(self.context)

        form = self.request.form
        submitted = form.get('form.submitted', False)
        save_button = form.get('form.button.Save', None) is not None
        cancel_button = form.get('form.button.Cancel', None) is not None
        type_id = form.get('old_type_id', None)

        if submitted and not cancel_button:
            if type_id:
                portal_types = getToolByName(self.context, 'portal_types')
                portal_repository = getToolByName(self.context,
                                                  'portal_repository')

                fti = getattr(portal_types, type_id)

                # Set FTI properties

                addable = form.get('addable', False)
                allow_discussion = form.get('allow_discussion', False)

                fti.manage_changeProperties(
                    global_allow=bool(addable),
                    allow_discussion=bool(allow_discussion))

                version_policy = form.get('versionpolicy', "off")
                if version_policy != self.current_versioning_policy():
                    newpolicy = [
                        p for p in VERSION_POLICIES
                        if p["id"] == version_policy
                    ][0]

                    versionable_types = list(
                        portal_repository.getVersionableContentTypes())
                    if not newpolicy["policy"]:
                        # check if we need to remove
                        if type_id in versionable_types:
                            versionable_types.remove(type_id)
                        self.remove_versioning_behavior(fti)
                    else:
                        # check if we should add
                        if type_id not in versionable_types:
                            versionable_types.append(safe_unicode(type_id))
                        self.add_versioning_behavior(fti)

                    for policy in portal_repository.listPolicies():
                        policy_id = policy.getId()
                        if policy_id in newpolicy["policy"]:
                            portal_repository.addPolicyForContentType(
                                type_id, policy_id)
                        else:
                            portal_repository.removePolicyFromContentType(
                                type_id, policy_id)

                    portal_repository.setVersionableContentTypes(
                        versionable_types)

                # Set Registry-entries
                registry = getUtility(IRegistry)

                searchable = form.get('searchable', False)
                site_settings = registry.forInterface(ISearchSchema,
                                                      prefix="plone")
                blacklisted = [i for i in site_settings.types_not_searched]
                if searchable and type_id in blacklisted:
                    blacklisted.remove(type_id)
                elif not searchable and type_id not in blacklisted:
                    blacklisted.append(type_id)
                site_settings.types_not_searched = tuple(blacklisted)

                default_page_type = form.get('default_page_type', False)
                types_settings = registry.forInterface(ITypesSchema,
                                                       prefix="plone")
                default_page_types = [
                    safe_unicode(i) for i in types_settings.default_page_types
                ]
                if default_page_type and type_id not in default_page_types:
                    default_page_types.append(safe_unicode(type_id))
                elif not default_page_type and type_id in default_page_types:
                    default_page_types.remove(type_id)
                types_settings.default_page_types = default_page_types

                redirect_links = form.get('redirect_links', False)
                types_settings.redirect_links = redirect_links

            # Update workflow
            if self.have_new_workflow() \
                    and form.get('form.workflow.submitted', False) \
                    and save_button:
                if self.new_workflow_is_different():
                    new_wf = self.new_workflow()
                    if new_wf == '[none]':
                        chain = ()
                    elif new_wf == '(Default)':
                        chain = new_wf
                    else:
                        chain = (new_wf, )
                    state_map = dict([(s['old_state'], s['new_state'])
                                      for s in form.get('new_wfstates', [])])
                    if '[none]' in state_map:
                        state_map[None] = state_map['[none]']
                        del state_map['[none]']
                    if type_id:
                        type_ids = (type_id, )
                    else:
                        wt = getToolByName(self.context, 'portal_workflow')
                        tt = getToolByName(self.context, 'portal_types')
                        nondefault = [
                            info[0] for info in wt.listChainOverrides()
                        ]
                        type_ids = [
                            type for type in tt.listContentTypes()
                            if type not in nondefault
                        ]
                        wt.setChainForPortalTypes(type_ids,
                                                  wt.getDefaultChain())
                        wt.setDefaultChain(','.join(chain))
                        chain = '(Default)'

                    remap_workflow(context,
                                   type_ids=type_ids,
                                   chain=chain,
                                   state_map=state_map)

                    data = {'workflow': new_wf}
                    notify(ConfigurationChangedEvent(self, data))

                else:
                    portal_workflow = getToolByName(context, 'portal_workflow')
                    if self.new_workflow() == '(Default)':
                        # The WorkflowTool API can not handle this sanely
                        cbt = portal_workflow._chains_by_type
                        if type_id in cbt:
                            del cbt[type_id]
                    else:
                        portal_workflow.setChainForPortalTypes(
                            (type_id, ), self.new_workflow())

                self.request.response.redirect(
                    '%s/@@content-controlpanel?type_id=%s' %
                    (context.absolute_url(), type_id))
                postback = False

        elif cancel_button:
            self.request.response.redirect(self.context.absolute_url() +
                                           '/@@overview-controlpanel')
            postback = False

        if postback:
            return self.template()