def __call__(self):
        storage = getUtility(IRedirectionStorage)
        request = self.request
        form = request.form
        status = IStatusMessage(self.request)
        errors = {}

        if 'form.button.Add' in form:
            redirection, err = absolutize_path(form.get('redirection'), is_alias=True)
            if err:
                errors['redirection'] = err
                status.addStatusMessage(err, type='error')
            else:
                # XXX check if there is an existing alias
                # XXX check whether there is an object
                del form['redirection']
                storage.add(redirection, "/".join(self.context.getPhysicalPath()))
                status.addStatusMessage(_(u"Alias added."), type='info')
        elif 'form.button.Remove' in form:
            redirects = form.get('redirects', ())
            for redirect in redirects:
                storage.remove(redirect)
            if len(redirects) > 1:
                status.addStatusMessage(_(u"Aliases removed."), type='info')
            else:
                status.addStatusMessage(_(u"Alias removed."), type='info')

        return self.template(errors=errors)
Ejemplo n.º 2
0
 def __call__(self):
     form = self.request.form
     context = aq_inner(self.context)
     status = IStatusMessage(self.request)
     if not self.can_edit_response:
         msg = _(u"You are not allowed to edit responses.")
         msg = translate(msg, 'Poi', context=self.request)
         status.addStatusMessage(msg, type='error')
     else:
         response_id = form.get('response_id', None)
         if response_id is None:
             msg = _(u"No response selected for saving.")
             msg = translate(msg, 'Poi', context=self.request)
             status.addStatusMessage(msg, type='error')
         else:
             response = self.folder[response_id]
             response_text = form.get('response', u'')
             response.text = response_text
             # Remove cached rendered response.
             response.rendered_text = None
             msg = _(u"Changes saved to response id ${response_id}.",
                     mapping=dict(response_id=response_id))
             msg = translate(msg, 'Poi', context=self.request)
             status.addStatusMessage(msg, type='info')
             # Fire event.  We put the context in the descriptions
             # so event handlers can use this fully acquisition
             # wrapped object to do their thing.  Feels like
             # cheating, but it gets the job done.  Arguably we
             # could turn the two arguments around and signal that
             # the issue has changed, with the response in the
             # event descriptions.
             modified(response, context)
     self.request.response.redirect(context.absolute_url())
Ejemplo n.º 3
0
 def __call__(self):
     form = self.request.form
     context = aq_inner(self.context)
     status = IStatusMessage(self.request)
     if not self.can_edit_response:
         msg = _(u"You are not allowed to edit responses.")
         msg = translate(msg, 'Poi', context=self.request)
         status.addStatusMessage(msg, type='error')
     else:
         response_id = form.get('response_id', None)
         if response_id is None:
             msg = _(u"No response selected for saving.")
             msg = translate(msg, 'Poi', context=self.request)
             status.addStatusMessage(msg, type='error')
         else:
             response = self.folder[response_id]
             response_text = form.get('response', u'')
             response.text = response_text
             # Remove cached rendered response.
             response.rendered_text = None
             msg = _(u"Changes saved to response id ${response_id}.",
                     mapping=dict(response_id=response_id))
             msg = translate(msg, 'Poi', context=self.request)
             status.addStatusMessage(msg, type='info')
             # Fire event.  We put the context in the descriptions
             # so event handlers can use this fully acquisition
             # wrapped object to do their thing.  Feels like
             # cheating, but it gets the job done.  Arguably we
             # could turn the two arguments around and signal that
             # the issue has changed, with the response in the
             # event descriptions.
             modified(response, context)
     self.request.response.redirect(context.absolute_url())
    def __call__(self):
        storage = getUtility(IRedirectionStorage)
        request = self.request
        form = request.form
        status = IStatusMessage(self.request)
        errors = {}

        if 'form.button.Add' in form:
            redirection, err = absolutize_path(form.get('redirection'),
                                               is_alias=True)
            if err:
                errors['redirection'] = err
                status.addStatusMessage(err, type='error')
            else:
                # XXX check if there is an existing alias
                # XXX check whether there is an object
                del form['redirection']
                storage.add(redirection,
                            "/".join(self.context.getPhysicalPath()))
                status.addStatusMessage(_("Alias added."), type='info')
        elif 'form.button.Remove' in form:
            redirects = form.get('redirects', ())
            for redirect in redirects:
                storage.remove(redirect)
            if len(redirects) > 1:
                status.addStatusMessage(_("Aliases removed."), type='info')
            else:
                status.addStatusMessage(_("Alias removed."), type='info')

        return self.template(errors=errors)
Ejemplo n.º 5
0
 def __call__(self):
     
     self.errors = {}
     
     if self.request.method == 'POST':
         CheckAuthenticator(self.request)
     
     catalog = getToolByName(self.context, 'portal_catalog')
     
     form = self.request.form
     
     if 'form.button.SaveGeneral' in form:
         name = form.get('defaultSiteLayout')
         directory = queryResourceDirectory(SITE_LAYOUT_RESOURCE_NAME, name)
         if directory is None:
             IStatusMessage(self.request).add(_(u"Cannot find resource directory"), type="error")
         else:
             
             filename = SITE_LAYOUT_FILE_NAME
             
             if directory.isFile(MANIFEST_FILENAME):
                 manifest = getManifest(directory.openFile(MANIFEST_FILENAME), SITE_LAYOUT_MANIFEST_FORMAT)
                 filename = manifest.get('file', filename)
             
             registry = getUtility(IRegistry)
             registry['plone.defaultSiteLayout'] = "./++%s++%s/%s" % \
                     (SITE_LAYOUT_RESOURCE_NAME, name, filename)
             
             IStatusMessage(self.request).add(_(u"Default site layout updated"), type="info")
         
     elif 'form.button.DeletePageType' in form:
         portal_type = form.get('name')
         if portal_type == DEFAULT_PAGE_TYPE_NAME:
             IStatusMessage(self.request).add(_(u"Cannot delete the default page type"), type="error")
         elif len(catalog({'portal_type': portal_type})) > 0:
             IStatusMessage(self.request).add(_(u"Cannot delete a type that is in use"), type="error")
         else:
             portal_types = getToolByName(self, 'portal_types')
             del portal_types[portal_type]
             IStatusMessage(self.request).add(_(u"Type deleted"), type="info")
     
     elif 'form.button.DeleteSiteLayout' in form:
         name = form.get('name')
         resources = getUtility(IResourceDirectory, name='persistent')
         sitelayouts = resources[SITE_LAYOUT_RESOURCE_NAME]
         del sitelayouts[name]
         IStatusMessage(self.request).add(_(u"Site layout deleted"), type="info")
     
     elif 'form.button.DeletePageLayout' in form:
         name = form.get('name')
         resources = getUtility(IResourceDirectory, name='persistent')
         pagelayouts = resources[PAGE_LAYOUT_RESOURCE_NAME]
         del pagelayouts[name]
         IStatusMessage(self.request).add(_(u"Page layout deleted"), type="info")
     
     return self.index()
Ejemplo n.º 6
0
 def getResults(self):
     if self._data is None:
         return None
     form = self._data
     contentType = form.get('contentType')
     contentName = form.get('contentName')
     contentName = '*%s*' % contentName
     catalog = api.portal.get_tool('portal_catalog')
     brains = catalog.searchResults(portal_type=contentType,
                                    Title=contentName)[:20]
     return brains
Ejemplo n.º 7
0
 def getResults(self):
     if self._data is None:
         return None
     form = self._data
     contentType = form.get('contentType')
     contentName = form.get('contentName')
     contentName = '*%s*' % contentName
     catalog = api.portal.get_tool('portal_catalog')
     brains = catalog.searchResults(portal_type=contentType,
                                    Title=contentName)[:20]
     return brains
    def __call__(self):
        storage = getUtility(IRedirectionStorage)
        portal = getUtility(ISiteRoot)
        request = self.request
        form = request.form
        status = IStatusMessage(self.request)

        if 'form.button.Remove' in form:
            redirects = form.get('redirects', ())
            for redirect in redirects:
                storage.remove(redirect)
            if len(redirects) == 0:
                status.addStatusMessage(_("No aliases selected for removal."),
                                        type='info')
            elif len(redirects) > 1:
                status.addStatusMessage(_("Aliases removed."), type='info')
            else:
                status.addStatusMessage(_("Alias removed."), type='info')
        elif 'form.button.Save' in form:
            dst = IAliasesSchema(self.context)
            dst.managed_types = self.request.form['form.widgets.managed_types']
        elif 'form.button.Upload' in form:
            self.upload(form['file'], portal, storage, status)

        self.form = RedirectsControlPanelForm(self.context, self.request)
        self.form.update()
        return self.template()
    def __call__(self):
        storage = getUtility(IRedirectionStorage)
        portal = getUtility(ISiteRoot)
        request = self.request
        form = request.form
        status = IStatusMessage(self.request)

        if 'form.button.Remove' in form:
            redirects = form.get('redirects', ())
            for redirect in redirects:
                storage.remove(redirect)
            if len(redirects) == 0:
                status.addStatusMessage(_(u"No aliases selected for removal."), type='info')
            elif len(redirects) > 1:
                status.addStatusMessage(_(u"Aliases removed."), type='info')
            else:
                status.addStatusMessage(_(u"Alias removed."), type='info')
        elif 'form.button.Save' in form:
            dst = IAliasesSchema(self.context)
            dst.managed_types = self.request.form['form.widgets.managed_types']
        elif 'form.button.Upload' in form:
            self.upload(form['file'], portal, storage, status)

        self.form = RedirectsControlPanelForm(self.context, self.request)
        self.form.update()
        return self.template()
Ejemplo n.º 10
0
    def __call__(self):
        form = self.request.form
        if self.request.REQUEST_METHOD == 'POST':
            if form.get('button.exportregistry'):
                return self.export_registry()
            if form.get('button.importregistry'):
                return self.import_registry()
        search = form.get('q')
        searchp = form.get('qp')
        compare = _is_in
        if searchp not in (None, ''):
            search = searchp
        if search is not None and search.startswith('prefix:'):
            search = search[len('prefix:'):]
            compare = _starts_with
        if not search:
            compare = _true

        self.prefixes = {}
        self.records = []
        for record in self.context.records.values():
            ifaceName = record.interfaceName
            if ifaceName is not None:
                recordPrefix = ifaceName.split('.')[-1]
                prefixValue = record.interfaceName
            else:
                prefixValue = record.__name__
                for prefix in _okay_prefixes:
                    name = record.__name__
                    if name.startswith(prefix):
                        recordPrefix = '.'.join(
                            name.split('.')[:len(prefix.split('.')) + 1])
                        prefixValue = recordPrefix
                        break
            if recordPrefix not in self.prefixes:
                self.prefixes[recordPrefix] = prefixValue
            if (compare(search, prefixValue) or compare(search, record.__name__)):
                self.records.append(record)
        self.records = Batch(
            self.records,
            15,
            int(form.get('b_start', '0')),
            orphan=1
        )
        return super(RecordsControlPanel, self).__call__()
Ejemplo n.º 11
0
    def __call__(self):

        form = self.request.form

        if form.get('pid', False):

            if form.get('form.button.delete', None) is not None:
                pid = form.get('pid', None)
                if self.delete_item(pid):
                    api.portal.show_message(
                        message=_(u'Item deleted.'), request=self.request)
                else:
                    api.portal.show_message(
                        message=_(u'Item not deleted.'), request=self.request)

            elif form.get('form.button.moveup', None) is not None:
                pid = form.get('pid', None)
                if self.move_item(pid, 'move_up'):
                    api.portal.show_message(
                        message=_(u'Item moved.'), request=self.request)
                else:
                    api.portal.show_message(
                        message=_(u'Item not moved.'), request=self.request)

            elif form.get('form.button.movedown', None) is not None:
                pid = form.get('pid', None)
                if self.move_item(pid, 'move_down'):
                    api.portal.show_message(
                        message=_(u'Item moved.'), request=self.request)
                else:
                    api.portal.show_message(
                        message=_(u'Item not moved.'), request=self.request)

        return self.template()
Ejemplo n.º 12
0
    def __call__(self):
        form = self.request.form
        if self.request.REQUEST_METHOD == 'POST':
            if form.get('button.exportregistry'):
                return self.export_registry()
            if form.get('button.importregistry'):
                return self.import_registry()
        search = form.get('q')
        searchp = form.get('qp')
        compare = _is_in
        if searchp not in (None, ''):
            search = searchp
        if search is not None and search.startswith('prefix:'):
            search = search[len('prefix:'):]
            compare = _starts_with
        if not search:
            compare = _true

        self.prefixes = {}
        self.records = []
        for record in self.context.records.values():
            ifaceName = record.interfaceName
            if ifaceName is not None:
                recordPrefix = ifaceName.split('.')[-1]
                prefixValue = record.interfaceName
            else:
                prefixValue = record.__name__
                for prefix in _okay_prefixes:
                    name = record.__name__
                    if name.startswith(prefix):
                        recordPrefix = '.'.join(
                            name.split('.')[:len(prefix.split('.')) + 1])
                        prefixValue = recordPrefix
                        break
            if recordPrefix not in self.prefixes:
                self.prefixes[recordPrefix] = prefixValue
            if (compare(search, prefixValue)
                    or compare(search, record.__name__)):
                self.records.append(record)
        self.records = Batch(self.records,
                             15,
                             int(form.get('b_start', '0')),
                             orphan=1)
        return super(RecordsControlPanel, self).__call__()
Ejemplo n.º 13
0
 def response(self):
     form = self.request.form
     response_id = form.get('response_id', None)
     if response_id is None:
         return None
     try:
         response_id = int(response_id)
     except ValueError:
         return None
     if response_id >= len(self.folder):
         return None
     return self.folder[response_id]
Ejemplo n.º 14
0
 def response(self):
     form = self.request.form
     response_id = form.get('response_id', None)
     if response_id is None:
         return None
     try:
         response_id = int(response_id)
     except ValueError:
         return None
     if response_id >= len(self.folder):
         return None
     return self.folder[response_id]
Ejemplo n.º 15
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')
                portal_properties = getToolByName(self.context,
                                                  'portal_properties')
                site_properties = getattr(portal_properties, 'site_properties')

                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(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
                    )

                searchable = form.get('searchable', False)
                blacklisted = list(
                    site_properties.getProperty('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_properties.manage_changeProperties(
                    types_not_searched=blacklisted
                )

                redirect_links = form.get('redirect_links', False)
                site_properties.manage_changeProperties(
                    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()
Ejemplo n.º 16
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()
Ejemplo n.º 17
0
 def _show_forgot_button(self):
     btn = self.buttons['forgot']
     form = self.request.form
     button_name = '%s.buttons.%s' % (self.prefix, btn.__name__)
     return (self.parent.status == self.parent.already_subscribed_message or
             form.get(button_name))