Esempio n. 1
0
    def handleApply(self, action):
        """Handle the process of creating the user's new Space at site root.

        This function utilises the manage_clone functionality associated
        with Plone in order to reproduce a given template. Administrative
        users are presented with the option to change the template ID whereas
        normal users cannot do so to prevent security issues.
        """
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        space_id = str(data['id'])
        space_title = unicode(data['space_title'])
        template_id = 'space-template'

        #Only load the template_id from the request if allowed
        if checkPermission('collective.spaces.AddSpace', self.context):
            template_id = str(data.get('template_id', u'space-template'))

        membership_tool = getToolByName(self.context, 'portal_membership')
        member = membership_tool.getAuthenticatedMember()
        member_id = member.getUserName()

        try:
            template = self.context.get(template_id)
            #Check if template exists or not. If not, create from scratch.
            if template:
                new_space = utils._clone(self.context, template, space_id)
            else:
                new_space = createContentInContainer(self.context,
                                                     'collective.spaces.space',
                                                     id=space_id,
                                                     checkConstraints=False)
            new_space.setTitle(space_title)
            new_space.setCreators(member_id)
            new_space.manage_setLocalRoles(member_id, ALL_ROLES)
            new_space.reindexObject()

            #If okay, then redirect to the new Space
            IStatusMessage(self.request).addStatusMessage(
                _(u"Welcome to your new Space! Start adding content "
                  u"and sharing with others."),
                "info"
            )

            space_url = new_space.absolute_url()
            self.request.response.redirect(space_url)
        except Exception as e:
            log.exception("Coud not create a Space")
            self.status = _(u"An error occurred whilst creating your Space \
                            with this ID. Please try again or contact your \
                            site administrator if issues persist.")
Esempio n. 2
0
 def validate(self, value):
     super(TemplateIdValidator, self).validate(value)
     if value not in self.context:
         raise interface.Invalid(_(u"An object of this ID does not exist."))
Esempio n. 3
0
 def validate(self, value):
     super(SpaceIdValidator, self).validate(value)
     if value in self.context:
         raise interface.Invalid(_(u"This ID is reserved or already in use."
                                   u" Please enter another."))