예제 #1
0
    def edit_account_html(self, REQUEST):
        """ view """
        if not _is_logged_in(REQUEST):
            return REQUEST.RESPONSE.redirect(self.absolute_url() + '/')

        browser_agent = self._get_ldap_agent(browser=True)
        orgs = browser_agent.all_organisations()
        orgs = [{
            'id': k,
            'text': v['name'],
            'text_native': v['name_native'],
            'ldap': True
        } for k, v in orgs.items()]

        agent = self._get_ldap_agent(bind=True)
        user_id = _get_user_id(REQUEST)

        errors = _session_pop(REQUEST, SESSION_FORM_ERRORS, {})
        form_data = _session_pop(REQUEST, SESSION_FORM_DATA, None)
        if form_data is None:
            form_data = agent.user_info(user_id)

        user_orgs = list(agent.user_organisations(user_id))
        if not user_orgs:
            org = form_data.get('organisation')
            if org:
                orgs.append({
                    'id': org,
                    'text': org,
                    'text_native': '',
                    'ldap': False
                })
        else:
            org = user_orgs[0]
            org_id = agent._org_id(org)
            form_data['organisation'] = org_id
        orgs.sort(lambda x, y: cmp(x['text'], y['text']))

        choices = [('-', '-')]
        for org in orgs:
            if org['ldap']:
                if org['text_native']:
                    label = u"%s (%s, %s)" % (org['text'], org['text_native'],
                                              org['id'])
                else:
                    label = u"%s (%s)" % (org['text'], org['id'])
            else:
                label = org['text']
            choices.append((org['id'], label))

        schema = user_info_schema.clone()
        widget = deform.widget.SelectWidget(values=choices)
        schema['organisation'].widget = widget

        invalid_nrcs = []

        org_info = None
        country_code = object()
        try:
            org_info = agent.org_info(form_data['organisation'])
        except:
            pass
        else:
            country_code = org_info['country']

        nrc_roles = get_nrc_roles(agent, user_id)
        for nrc_role in nrc_roles:
            nrc_role_info = agent.role_info(nrc_role)
            country_code = nrc_role.split('-')[-1]
            if not org_info or org_info.get('country') != country_code:
                invalid_nrcs.append(nrc_role_info)

        options = {
            'base_url': self.absolute_url(),
            'form_data': form_data,
            'errors': errors,
            'schema': schema,
            'invalid_nrcs': invalid_nrcs,
        }
        options.update(_get_session_messages(REQUEST))

        return self._render_template('zpt/edit_account.zpt', **options)
예제 #2
0
    def edit_account_html(self, REQUEST):
        """ view """
        if not _is_logged_in(REQUEST):
            return REQUEST.RESPONSE.redirect(self.absolute_url() + '/')

        browser_agent = self._get_ldap_agent(browser=True)
        orgs = browser_agent.all_organisations()
        orgs = [{'id': k, 'text': v['name'], 'text_native': v['name_native'],
                 'ldap': True} for k, v in orgs.items()]

        agent = self._get_ldap_agent(bind=True)
        user_id = _get_user_id(REQUEST)

        errors = _session_pop(REQUEST, SESSION_FORM_ERRORS, {})
        form_data = _session_pop(REQUEST, SESSION_FORM_DATA, None)
        if form_data is None:
            form_data = agent.user_info(user_id)

        user_orgs = list(agent.user_organisations(user_id))
        if not user_orgs:
            org = form_data.get('organisation')
            if org:
                orgs.append({'id': org, 'text': org, 'text_native': '',
                             'ldap': False})
        else:
            org = user_orgs[0]
            org_id = agent._org_id(org)
            form_data['organisation'] = org_id
        orgs.sort(lambda x, y: cmp(x['text'], y['text']))

        choices = [('-', '-')]
        for org in orgs:
            if org['ldap']:
                if org['text_native']:
                    label = u"%s (%s, %s)" % (org['text'], org['text_native'],
                                              org['id'])
                else:
                    label = u"%s (%s)" % (org['text'], org['id'])
            else:
                label = org['text']
            choices.append((org['id'], label))

        schema = user_info_schema.clone()
        widget = deform.widget.SelectWidget(values=choices)
        schema['organisation'].widget = widget

        invalid_nrcs = []

        org_info = None
        country_code = object()
        try:
            org_info = agent.org_info(form_data['organisation'])
        except:
            pass
        else:
            country_code = org_info['country']

        nrc_roles = get_nrc_roles(agent, user_id)
        for nrc_role in nrc_roles:
            nrc_role_info = agent.role_info(nrc_role)
            country_code = nrc_role.split('-')[-1]
            if not org_info or org_info.get('country') != country_code:
                invalid_nrcs.append(nrc_role_info)

        options = {
            'base_url': self.absolute_url(),
            'form_data': form_data,
            'errors': errors,
            'schema': schema,
            'invalid_nrcs': invalid_nrcs,
        }
        options.update(_get_session_messages(REQUEST))

        return self._render_template('zpt/edit_account.zpt', **options)
예제 #3
0
                old_info = agent.user_info(user_id)

                new_org_id = new_info['organisation']
                old_org_id = old_info['organisation']

                new_org_id_valid = agent.org_exists(new_org_id)

                if new_org_id != old_org_id:
                    self._remove_from_all_orgs(agent, user_id)
                    if new_org_id_valid:
                        self._add_to_org(agent, new_org_id, user_id)
                        org_info = agent.org_info(new_org_id)
                    else:
                        org_info = None

                    nrc_roles = get_nrc_roles(agent, user_id)
                    for nrc_role in nrc_roles:
                        nrc_role_info = agent.role_info(nrc_role)
                        country_code = nrc_role.split('-')[-1]
                        # if the organisation is not proper for the nrc,
                        # send an email to all nfps for that country
                        if (not org_info
                                or org_info.get('country') != country_code):
                            nfp_roles = get_nfps_for_country(
                                agent, country_code)
                            for nfp_role in nfp_roles:
                                nfps = role_members(agent,
                                                    nfp_role)['users'].keys()
                                for nfp_id in nfps:
                                    nfp_info = agent.user_info(nfp_id)
                                    self._send_nfp_nrc_email(
예제 #4
0
                old_info = agent.user_info(user_id)

                new_org_id = new_info['organisation']
                old_org_id = old_info['organisation']

                new_org_id_valid = agent.org_exists(new_org_id)

                if new_org_id != old_org_id:
                    self._remove_from_all_orgs(agent, user_id)
                    if new_org_id_valid:
                        self._add_to_org(agent, new_org_id, user_id)
                        org_info = agent.org_info(new_org_id)
                    else:
                        org_info = None

                    nrc_roles = get_nrc_roles(agent, user_id)
                    for nrc_role in nrc_roles:
                        nrc_role_info = agent.role_info(nrc_role)
                        country_code = nrc_role.split('-')[-1]
                        # if the organisation is not proper for the nrc,
                        # send an email to all nfps for that country
                        if (not org_info or
                                org_info.get('country') != country_code):
                            nfp_roles = get_nfps_for_country(agent,
                                                             country_code)
                            for nfp_role in nfp_roles:
                                nfps = role_members(agent,
                                                    nfp_role)['users'].keys()
                                for nfp_id in nfps:
                                    nfp_info = agent.user_info(nfp_id)
                                    self._send_nfp_nrc_email(