def addNyContact_who_who(self, id='', REQUEST=None, contributor=None, **kwargs):
        """
        Create a Contact type of object in 'who-who' folder adding
        * extra validation for topics and target-groups
        * pointers in the selected topics and target-groups

        """
        schema_raw_data = dict(REQUEST.form)
        topics = schema_raw_data.get("topics", [])
        if not topics:
            # unfortunately we both need _prepare_error_response
            # (on NyContentData) and methods for session (by acquisition)
            ob = NyContact('', '').__of__(self)
            form_errors = {'topics': ['Please select at least one Topic']}
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/show_on_atlas' % self.absolute_url())
            return

        who_who = self.restrictedTraverse('who-who')
        response = contact_item.addNyContact(who_who, '', REQUEST)
        if isinstance(response, NyContact):
            form = REQUEST.form.copy()
            form['username'] = response.contributor
            handle_groups(response, form)
            REQUEST.RESPONSE.redirect(response.absolute_url())
            pass    # Contacts are now redirected from post-add event
        else:       # we have errors
            REQUEST.RESPONSE.redirect('%s/show_on_atlas' % self.absolute_url())
Пример #2
0
    def addNyContact_who_who(self,
                             id='',
                             REQUEST=None,
                             contributor=None,
                             **kwargs):
        """
        Create a Contact type of object in 'who-who' folder adding
        * extra validation for topics and target-groups
        * pointers in the selected topics and target-groups

        """
        schema_raw_data = dict(REQUEST.form)
        topics = schema_raw_data.get("topics", [])
        if not topics:
            # unfortunately we both need _prepare_error_response
            # (on NyContentData) and methods for session (by acquisition)
            ob = NyContact('', '').__of__(self)
            form_errors = {'topics': ['Please select at least one Topic']}
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/show_on_atlas' % self.absolute_url())
            return

        who_who = self.restrictedTraverse('who-who')
        response = contact_item.addNyContact(who_who, '', REQUEST)
        if isinstance(response, NyContact):
            form = REQUEST.form.copy()
            form['username'] = response.contributor
            handle_groups(response, form)
            REQUEST.RESPONSE.redirect(response.absolute_url())
            pass  # Contacts are now redirected from post-add event
        else:  # we have errors
            REQUEST.RESPONSE.redirect('%s/show_on_atlas' % self.absolute_url())
Пример #3
0
def process_create_account(context, request):
    """ """
    referer = request.HTTP_REFERER
    site = context.getSite()
    schema = site.getSchemaTool()['NyContact']
    register_schema = context.getSite().getSchemaTool()['registration']
    form_data, form_errors = validate_widgets(schema, register_schema, request.form)

    # if filling up the lower part, then the upper part is required as well
    if form_data['landscape_type'] and not form_data['topics']:
        form_errors['topics'] = ['Value is required for Topics']

    if form_errors:
        prepare_error_response(context, schema, register_schema, form_errors, request.form)
        # we need to put ourselves the user specific values in form
        args_for_session = {}
        for key in EW_REGISTER_FIELD_NAMES:
            args_for_session[key] = request.form.get(key)
        args_for_session['name'] = request.form.get('username')
        site.setRequestRoleSession(**args_for_session)
        request.RESPONSE.redirect(referer)
    else:
        # OBS: email is already sent here:
        real_comment = request.form.get('comments')
        if not real_comment:
            request.form['comments'] = " "
        site.processRequestRoleForm(request)
        redirect = request.RESPONSE.headers.get('location')
        if redirect != referer:
            # redirects to referer only when something is wrong in register form
            where = site['who-who']['destinet-users']
            username = request.form['username']
            contact_name = "%(firstname)s %(lastname)s" % request.form
            ob = _create_NyContact_object(where, username, username)
            ob.releasedate = site.utGetTodayDate()
            ob.approveThis(1, username)
            ob.submitThis()
            ob.giveEditRights()
            # voodoo for setting ownership using AccessControl.Owned API
            new_user = site.acl_users.getUser(username).__of__(site.acl_users)
            ob.changeOwnership(new_user)

            site.admin_addroles([username], ['Contributor'], '', send_mail=True)

            # hack to edit object without permissions (no auth)
            setattr(ob, 'checkPermissionEditObject', lambda: True)
            ob.manageProperties(title=contact_name,
                                firstname=request.form['firstname'],
                                lastname=request.form['lastname'],
                                organisation=request.form['organisation'],
                                approved=True,
                                description=real_comment,
                                **form_data)
            handle_groups(ob, request.form)
            delattr(ob, 'checkPermissionEditObject')
        else:
            # also call this to prefill values in form for contact
            prepare_error_response(context, schema, register_schema, form_errors, request.form)
Пример #4
0
def process_create_account(context, request):
    """ """
    referer = request.HTTP_REFERER
    site = context.getSite()
    schema = site.getSchemaTool()['NyContact']
    register_schema = context.getSite().getSchemaTool()['registration']
    form_data, form_errors = validate_widgets(schema, register_schema,
                                              request.form)

    # if filling up the lower part, then the upper part is required as well
    if form_data['landscape_type'] and not form_data['topics']:
        form_errors['topics'] = ['Value is required for Topics']

    if form_errors:
        prepare_error_response(context, schema, register_schema, form_errors,
                               request.form)
        # we need to put ourselves the user specific values in form
        args_for_session = {}
        for key in EW_REGISTER_FIELD_NAMES:
            args_for_session[key] = request.form.get(key)
        args_for_session['name'] = request.form.get('username')
        site.setRequestRoleSession(**args_for_session)
        request.RESPONSE.redirect(referer)
    else:
        # OBS: email is already sent here:
        real_comment = request.form.get('comments')
        if not real_comment:
            request.form['comments'] = " "
        site.processRequestRoleForm(request)
        redirect = request.RESPONSE.headers.get('location')
        if redirect != referer:
            # redirects to referer only when something is wrong in register form
            where = site['who-who']['destinet-users']
            username = request.form['username']
            contact_name = "%(firstname)s %(lastname)s" % request.form
            ob = _create_NyContact_object(where, username, username)
            ob.releasedate = site.utGetTodayDate()
            ob.approveThis(1, username)
            ob.submitThis()
            ob.giveEditRights()
            # voodoo for setting ownership using AccessControl.Owned API
            new_user = site.acl_users.getUser(username).__of__(site.acl_users)
            ob.changeOwnership(new_user)

            site.admin_addroles([username], ['Contributor'],
                                '',
                                send_mail=True)

            # hack to edit object without permissions (no auth)
            setattr(ob, 'checkPermissionEditObject', lambda: True)
            ob.manageProperties(title=contact_name,
                                firstname=request.form['firstname'],
                                lastname=request.form['lastname'],
                                organisation=request.form['organisation'],
                                approved=True,
                                description=real_comment,
                                **form_data)
            handle_groups(ob, request.form)
            delattr(ob, 'checkPermissionEditObject')
        else:
            # also call this to prefill values in form for contact
            prepare_error_response(context, schema, register_schema,
                                   form_errors, request.form)