Exemplo n.º 1
0
    def _process(self):
        form = make_registration_form(self.regform, management=self.management, registration=self.registration)()

        if form.validate_on_submit():
            data = form.data
            notify_user = data.pop('notify_user', False)
            modify_registration(self.registration, data, management=self.management, notify_user=notify_user)
            return redirect(self.success_url)
        elif form.is_submitted():
            # not very pretty but usually this never happens thanks to client-side validation
            for error in form.error_list:
                flash(error, 'error')

        registration_data = {r.field_data.field.html_field_name: camelize_keys(r.user_data)
                             for r in self.registration.data}
        section_data = camelize_keys(get_event_section_data(self.regform, management=self.management,
                                                            registration=self.registration))

        registration_metadata = {
            'paid': self.registration.is_paid,
            'manager': self.management
        }

        return self.view_class.render_template(self.template_file, self.event, event=self.event,
                                               sections=section_data, regform=self.regform,
                                               registration_data=registration_data,
                                               registration_metadata=registration_metadata,
                                               registration=self.registration)
Exemplo n.º 2
0
def get_field_merged_options(field, registration_data):
    rdata = registration_data.get(field.id)
    result = deepcopy(field.view_data)
    if not rdata or not rdata.data:
        return result
    values = [rdata.data['choice']] if 'choice' in rdata.data else [
        k for k, v in rdata.data.items() if v
    ]
    for val in values:
        if val and not any(item['id'] == val for item in result['choices']):
            field_data = rdata.field_data
            merged_data = field.field_impl.unprocess_field_data(
                field_data.versioned_data, field_data.field.data)
            missing_option = next(
                (choice
                 for choice in merged_data['choices'] if choice['id'] == val),
                None)
            if missing_option:
                result['choices'].append(
                    camelize_keys(missing_option) | {'_deleted': True})
        else:
            current_choice_data = _get_choice_by_id(val, result['choices'])
            registration_choice_data = dict(
                camelize_keys(
                    _get_choice_by_id(
                        val,
                        rdata.field_data.versioned_data.get('choices', {}))),
                caption=current_choice_data['caption'])
            if current_choice_data != registration_choice_data:
                pos = result['choices'].index(current_choice_data)
                result['choices'][pos] = registration_choice_data | {
                    '_modified': True
                }
    return result
Exemplo n.º 3
0
 def view_data(self):
     base_dict = dict(self.versioned_data, **self.data)
     base_dict.update(is_enabled=self.is_enabled, title=self.title, is_required=self.is_required,
                      input_type=self.input_type, html_name=self.html_field_name,
                      **super(RegistrationFormField, self).view_data)
     base_dict.update(self.field_impl.view_data)
     return camelize_keys(base_dict)
Exemplo n.º 4
0
def get_field_merged_options(field, registration_data):
    rdata = registration_data.get(field.id)
    result = deepcopy(field.view_data)
    result['deletedChoice'] = []
    result['modifiedChoice'] = []
    if not rdata or not rdata.data:
        return result
    values = [rdata.data['choice']] if 'choice' in rdata.data else rdata.data.keys()
    for val in values:
        if val and not any(item['id'] == val for item in result['choices']):
            field_data = rdata.field_data
            merged_data = field.field_impl.unprocess_field_data(field_data.versioned_data,
                                                                field_data.field.data)
            missing_option = next((choice for choice in merged_data['choices'] if choice['id'] == val), None)
            if missing_option:
                result['choices'].append(missing_option)
                result['deletedChoice'].append(missing_option['id'])
        else:
            current_choice_data = _get_choice_by_id(val, result['choices'])
            registration_choice_data = dict(camelize_keys(
                _get_choice_by_id(val, rdata.field_data.versioned_data.get('choices', {}))),
                caption=current_choice_data['caption'])
            if current_choice_data != registration_choice_data:
                pos = result['choices'].index(current_choice_data)
                result['choices'][pos] = registration_choice_data
                result['modifiedChoice'].append(val)
    return result
Exemplo n.º 5
0
def test_camelize_keys():
    d = {
        'fooBar': 'foo',
        'bar_foo': 123,
        'moo_bar': {
            'hello_world': 'test'
        },
        'nested': [{
            'is_dict': True
        }, 'foo', ({
            'a_b': 'c'
        }, )]
    }
    orig = d.copy()
    d2 = camelize_keys(d)
    assert d == orig  # original dict not modified
    assert d2 == {
        'fooBar': 'foo',
        'barFoo': 123,
        'mooBar': {
            'helloWorld': 'test'
        },
        'nested': [{
            'isDict': True
        }, 'foo', ({
            'aB': 'c'
        }, )]
    }
Exemplo n.º 6
0
Arquivo: util.py Projeto: javfg/indico
def get_flat_section_submission_data(regform,
                                     *,
                                     management=False,
                                     registration=None):
    section_data = {
        s.id: camelize_keys(s.own_data)
        for s in regform.active_sections if management or not s.is_manager_only
    }

    item_data = {}
    registration_data = {r.field_data.field.id: r
                         for r in registration.data} if registration else None
    for item in regform.active_fields:
        can_modify = management or not item.parent.is_manager_only
        if not can_modify:
            continue
        if registration and isinstance(item.field_impl,
                                       (ChoiceBaseField, AccommodationField)):
            field_data = get_field_merged_options(item, registration_data)
        elif registration and isinstance(item.field_impl,
                                         AccompanyingPersonsField):
            field_data = item.view_data
            field_data[
                'availablePlaces'] = item.field_impl.get_available_places(
                    registration)
        else:
            field_data = item.view_data
        item_data[item.id] = field_data
    for item in regform.active_labels:
        item_data[item.id] = item.view_data
    return {'sections': section_data, 'items': item_data}
Exemplo n.º 7
0
 def view_data(self):
     field_data = dict(self.own_data,
                       items=[
                           child.view_data for child in self.children
                           if not child.is_deleted
                       ])
     return camelize_keys(field_data)
Exemplo n.º 8
0
 def view_data(self):
     base_dict = dict(self.versioned_data, **self.data)
     base_dict.update(is_enabled=self.is_enabled, title=self.title, is_required=self.is_required,
                      input_type=self.input_type, html_name=self.html_field_name,
                      **super(RegistrationFormField, self).view_data)
     base_dict.update(self.field_impl.view_data)
     return camelize_keys(base_dict)
Exemplo n.º 9
0
 def view_data(self):
     base_dict = self.versioned_data | self.data
     base_dict.update(section_id=self.parent_id, is_enabled=self.is_enabled, title=self.title,
                      is_required=self.is_required,
                      retention_period=(self.retention_period.days // 7 if self.retention_period else None),
                      input_type=self.input_type, html_name=self.html_field_name, **super().view_data)
     base_dict.update(self.field_impl.view_data)
     return camelize_keys(base_dict)
Exemplo n.º 10
0
def test_camelize_keys():
    d = {'fooBar': 'foo', 'bar_foo': 123, 'moo_bar': {'hello_world': 'test'},
         'nested': [{'is_dict': True}, 'foo', ({'a_b': 'c'},)]}
    orig = d.copy()
    d2 = camelize_keys(d)
    assert d == orig  # original dict not modified
    assert d2 == {'fooBar': 'foo', 'barFoo': 123, 'mooBar': {'helloWorld': 'test'},
                  'nested': [{'isDict': True}, 'foo', ({'aB': 'c'},)]}
Exemplo n.º 11
0
Arquivo: util.py Projeto: javfg/indico
def get_flat_section_setup_data(regform):
    section_data = {
        s.id: camelize_keys(s.own_data)
        for s in regform.sections if not s.is_deleted
    }
    item_data = {
        f.id: f.view_data
        for f in regform.form_items if not f.is_section and not f.is_deleted
    }
    return {'sections': section_data, 'items': item_data}
Exemplo n.º 12
0
Arquivo: util.py Projeto: javfg/indico
def get_initial_form_values(regform, *, management=False):
    initial_values = {}
    for item in regform.active_fields:
        can_modify = management or not item.parent.is_manager_only
        if can_modify:
            impl = item.field_impl
            if not impl.is_invalid_field:
                initial_values[item.html_field_name] = camelize_keys(
                    impl.default_value)
    return initial_values
Exemplo n.º 13
0
def test_camelize_keys():
    d = {
        "fooBar": "foo",
        "bar_foo": 123,
        "moo_bar": {"hello_world": "test"},
        "nested": [{"is_dict": True}, "foo", ({"a_b": "c"},)],
    }
    orig = d.copy()
    d2 = camelize_keys(d)
    assert d == orig  # original dict not modified
    assert d2 == {
        "fooBar": "foo",
        "barFoo": 123,
        "mooBar": {"helloWorld": "test"},
        "nested": [{"isDict": True}, "foo", ({"aB": "c"},)],
    }
Exemplo n.º 14
0
Arquivo: util.py Projeto: javfg/indico
def get_form_registration_data(regform, registration, *, management=False):
    """
    Return a mapping from 'html_field_name' to the registration data.
    This also includes default values for any newly added fields since
    the React frontend requires all initial values to be present.
    """
    data_by_field = registration.data_by_field
    registration_data = {}
    for item in regform.active_fields:
        can_modify = management or not item.parent.is_manager_only
        if not can_modify:
            continue
        elif item.id in data_by_field:
            registration_data[item.html_field_name] = camelize_keys(
                data_by_field[item.id].user_data)
        else:
            registration_data[
                item.html_field_name] = item.field_impl.default_value
    if management:
        registration_data['notify_user'] = session.get(
            'registration_notify_user_default', True)
    return registration_data
Exemplo n.º 15
0
 def view_data(self):
     field_data = dict(super().view_data,
                       is_enabled=self.is_enabled,
                       input_type='label',
                       title=self.title)
     return camelize_keys(field_data)
Exemplo n.º 16
0
 def view_data(self):
     field_data = dict(super().view_data, is_personal_data=True)
     del field_data['isPersonalData']
     return camelize_keys(field_data)
Exemplo n.º 17
0
 def view_data(self):
     field_data = dict(super(RegistrationFormText, self).view_data, is_enabled=self.is_enabled, input_type='label',
                       title=self.title)
     return camelize_keys(field_data)
Exemplo n.º 18
0
 def view_data(self):
     field_data = dict(super(RegistrationFormPersonalDataSection, self).view_data, is_personal_data=True)
     del field_data['isPersonalData']
     return camelize_keys(field_data)
Exemplo n.º 19
0
 def view_data(self):
     field_data = dict(self.own_data,
                       items=[child.view_data for child in self.children if not child.is_deleted])
     return camelize_keys(field_data)
Exemplo n.º 20
0
 def view_data(self):
     field_data = dict(super(RegistrationFormPersonalDataSection, self).view_data, is_personal_data=True)
     del field_data['isPersonalData']
     return camelize_keys(field_data)
Exemplo n.º 21
0
 def view_data(self):
     data = dict(super(RegistrationFormPersonalDataField, self).view_data,
                 field_is_required=self.personal_data_type.is_required,
                 field_is_personal_data=True)
     return camelize_keys(data)
Exemplo n.º 22
0
 def view_data(self):
     field_data = dict(super().view_data, section_id=self.parent_id, is_enabled=self.is_enabled, input_type='label',
                       title=self.title, is_purged=self.is_purged)
     return camelize_keys(field_data)
Exemplo n.º 23
0
 def view_data(self):
     data = dict(super().view_data,
                 field_is_required=self.personal_data_type.is_required,
                 field_is_personal_data=True)
     return camelize_keys(data)
Exemplo n.º 24
0
 def view_data(self):
     data = dict(super(RegistrationFormPersonalDataField, self).view_data,
                 field_is_required=self.personal_data_type.is_required,
                 field_is_personal_data=True)
     return camelize_keys(data)
Exemplo n.º 25
0
    def _process(self):
        form = make_registration_form(self.regform,
                                      management=self.management,
                                      registration=self.registration)()

        verif_field, reg_field = ('', '')
        for k in form._fields:
            if form._fields[k].label.text.lower() == 'registration option':
                reg_field = form._fields[k].label.field_id
            if form._fields[k].label.text.lower() == 'verification code':
                verif_field = form._fields[k].label.field_id

        verif_code = ''
        if verif_field and form._fields[verif_field].data:
            verif_code = form._fields[verif_field].data
        elif request.form.get(verif_field):
            verif_code = request.form.get(verif_field)

        reg_opt = ''
        if reg_field and form._fields[reg_field].data:
            reg_opt = form._fields[reg_field].data

        opt_text = ''
        if reg_opt:
            for i in self.regform.active_fields:
                if i.title.lower() == 'registration option':
                    for k in i.data['captions']:
                        if k == next(iter(reg_opt)):
                            opt_text = i.data['captions'][k]
                else:
                    continue

        members_choice = False
        if opt_text and re.search(r' members', opt_text, flags=re.IGNORECASE):
            members_choice = True

        registration_data = {
            r.field_data.field.html_field_name: camelize_keys(r.user_data)
            for r in self.registration.data
        }

        reg_allowed = False
        if members_choice:
            str_list = [
                registration_data['first_name'] +
                registration_data['last_name'] + '/' + str(self.event.id) +
                '/' + datetime.today().strftime('%Y-%m-%d'),
                registration_data['first_name'] +
                registration_data['last_name'] + '/' + str(self.event.id) +
                '/' +
                (datetime.now() + timedelta(days=-1)).strftime('%Y-%m-%d'),
                registration_data['first_name'] +
                registration_data['last_name'] + '/' + str(self.event.id) +
                '/' +
                (datetime.now() + timedelta(days=-2)).strftime('%Y-%m-%d')
            ]
            for strn in str_list:
                sha = hmac.new(u''.encode(),
                               strn.lower().encode('utf-8'),
                               hashlib.sha256).hexdigest()
                md = hmac.new(''.encode(), sha.encode(),
                              hashlib.md5).hexdigest()
                enc = codecs.encode(codecs.decode(
                    md, 'hex'), 'base64').decode().replace("\n", "").replace(
                        "=", "").replace("/", "9").replace("+", "8")
                print(strn.lower())
                print(enc)
                if enc == verif_code:
                    reg_allowed = True

        setattr(self.regform, 'member_attempt', False)
        if (members_choice and reg_allowed) or not members_choice:
            if form.validate_on_submit():
                data = form.data
                notify_user = not self.management or data.pop(
                    'notify_user', False)
                if self.management:
                    session['registration_notify_user_default'] = notify_user
                modify_registration(self.registration,
                                    data,
                                    management=self.management,
                                    notify_user=notify_user)
                return redirect(self.success_url)
            elif form.is_submitted():
                # not very pretty but usually this never happens thanks to client-side validation
                for error in form.error_list:
                    flash(error, 'error')
        else:
            setattr(self.regform, 'member_attempt', True)

        section_data = camelize_keys(
            get_event_section_data(self.regform,
                                   management=self.management,
                                   registration=self.registration))

        registration_metadata = {
            'paid': self.registration.is_paid,
            'manager': self.management
        }

        return self.view_class.render_template(
            self.template_file,
            self.event,
            sections=section_data,
            regform=self.regform,
            registration_data=registration_data,
            registration_metadata=registration_metadata,
            registration=self.registration)