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
示例#2
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)
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'
        }, )]
    }
 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)
示例#5
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 = 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')

        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,
            sections=section_data,
            regform=self.regform,
            registration_data=registration_data,
            registration_metadata=registration_metadata,
            registration=self.registration)
示例#6
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)
示例#7
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)
 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)