Example #1
0
def create_personal_data_fields(regform):
    """Creates the special section/fields for personal data."""
    section = next((s for s in regform.sections
                    if s.type == RegistrationFormItemType.section_pd), None)
    if section is None:
        section = RegistrationFormPersonalDataSection(
            registration_form=regform, title='Personal Data')
        missing = set(PersonalDataType)
    else:
        existing = {
            x.personal_data_type
            for x in section.children
            if x.type == RegistrationFormItemType.field_pd
        }
        missing = set(PersonalDataType) - existing
    for pd_type, data in PersonalDataType.FIELD_DATA:
        if pd_type not in missing:
            continue
        field = RegistrationFormPersonalDataField(
            registration_form=regform,
            personal_data_type=pd_type,
            is_required=pd_type.is_required)
        if not data.get('is_enabled', True):
            field.position = data['position']
        for key, value in data.iteritems():
            setattr(field, key, value)
        field.data, versioned_data = field.field_impl.process_field_data(
            data.pop('data', {}))
        field.current_data = RegistrationFormFieldData(
            versioned_data=versioned_data)
        section.children.append(field)
Example #2
0
def create_personal_data_fields(regform):
    """Creates the special section/fields for personal data."""
    section = next((s for s in regform.sections if s.type == RegistrationFormItemType.section_pd), None)
    if section is None:
        section = RegistrationFormPersonalDataSection(registration_form=regform, title='Personal Data')
        missing = set(PersonalDataType)
    else:
        existing = {x.personal_data_type for x in section.children if x.type == RegistrationFormItemType.field_pd}
        missing = set(PersonalDataType) - existing
    for pd_type, data in PersonalDataType.FIELD_DATA:
        if pd_type not in missing:
            continue
        field = RegistrationFormPersonalDataField(registration_form=regform, personal_data_type=pd_type,
                                                  is_required=pd_type.is_required)
        for key, value in data.iteritems():
            setattr(field, key, value)
        field.data, versioned_data = field.field_impl.process_field_data(data.pop('data', {}))
        field.current_data = RegistrationFormFieldData(versioned_data=versioned_data)
        section.children.append(field)
Example #3
0
 def _column_ids_to_db(self, ids):
     """Translate string-based ids to DB-based RegistrationFormItem ids."""
     result = []
     for item_id in ids:
         if isinstance(item_id, basestring):
             personal_data = PersonalDataType.get(item_id)
             if personal_data:
                 result.append(RegistrationFormPersonalDataField.find_one(registration_form=self.regform,
                                                                          personal_data_type=personal_data).id)
             else:
                 result.append(item_id)
         else:
             result.append(item_id)
     return result
Example #4
0
def _column_ids_to_db(form, ids):
    """Translate string-based ids to DB-based RegistrationFormItem ids."""
    result = []
    for item_id in ids:
        if isinstance(item_id, basestring):
            personal_data = PersonalDataType.get(item_id)
            if personal_data:
                result.append(RegistrationFormPersonalDataField.find_one(registration_form=form,
                                                                         personal_data_type=personal_data).id)
            else:
                result.append(item_id)
        else:
            result.append(item_id)
    return result