Beispiel #1
0
    def test_should_batch_get_form_models(self):
        fields = [ShortCodeField('name', 'eid', 'label')]
        form = EntityFormModel(
            self.manager,
            'test_form',
            'label',
            'form_code1',
            fields=fields,
            entity_type=['Clinic'],
            validators=[
                MandatoryValidator(),
                MobileNumberValidationsForReporterRegistrationValidator()
            ])
        form.save()

        fields = [ShortCodeField('name', 'eid', 'label')]
        form = EntityFormModel(
            self.manager,
            'test_form',
            'label',
            'form_code2',
            fields=fields,
            entity_type=['Clinic'],
            validators=[
                MandatoryValidator(),
                MobileNumberValidationsForReporterRegistrationValidator()
            ])
        form.save()

        forms = list_form_models_by_code(self.manager,
                                         ['form_code1', 'form_code2'])

        self.assertEqual(2, len(forms))
        self.assertEqual('form_code1', forms[0].form_code)
        self.assertEqual('form_code2', forms[1].form_code)
Beispiel #2
0
 def setUp(self):
     self.validator = MandatoryValidator()
     self.field1 = TextField('a', 'a', 'a')
     self.field2 = TextField('b', 'b', 'b', required=False)
     self.field3 = TextField('c', 'c', 'c')
     self.field4 = TextField('d', 'd', 'd')
     self.fields = [self.field1, self.field2, self.field3, self.field4]
Beispiel #3
0
 def test_should_remove_validator_from_form_model(self):
     self.form_model.validators = [
         MandatoryValidator(),
         UniqueIdExistsValidator()
     ]
     self.form_model.remove_validator(UniqueIdExistsValidator)
     self.assertEquals(len(self.form_model.validators), 1)
Beispiel #4
0
 def test_should_not_add_validator_to_form_model_if_already_present(self):
     self.form_model.validators = [
         MandatoryValidator(),
         UniqueIdExistsValidator()
     ]
     self.form_model.add_validator(UniqueIdExistsValidator)
     self.assertEquals(len(self.form_model.validators), 2)
Beispiel #5
0
def _construct_global_deletion_form(manager):
    question1 = HierarchyField(name=ENTITY_TYPE_FIELD_NAME, code=ENTITY_TYPE_FIELD_CODE,
        label="What is the entity type" , instruction="Enter a type for the entity")

    question2 = ShortCodeField(name=SHORT_CODE_FIELD, code=SHORT_CODE, label="What is the entity's Unique ID Number",
        defaultValue="some default value" ,
        instruction="Enter the id of the entity you want to delete", constraints=[])

    form_model = EntityFormModel(manager, name=ENTITY_DELETION_FORM_CODE, form_code=ENTITY_DELETION_FORM_CODE, fields=[
        question1, question2], entity_type=["deletion"],
        validators=[MandatoryValidator(), EntityShouldExistValidator()])
    return form_model
Beispiel #6
0
 def test_should_save_form_model_with_validators(self):
     fields = [ShortCodeField('name', 'eid', 'label')]
     form = EntityFormModel(
         self.manager,
         'test_form',
         'label',
         'foo',
         fields=fields,
         entity_type=['Clinic'],
         validators=[
             MandatoryValidator(),
             MobileNumberValidationsForReporterRegistrationValidator()
         ])
     form.save()
     form = get_form_model_by_code(self.manager, 'foo')
     self.assertEqual(2, len(form.validators))
     self.assertTrue(isinstance(form.validators[0], MandatoryValidator))
     self.assertTrue(
         isinstance(
             form.validators[1],
             MobileNumberValidationsForReporterRegistrationValidator))
Beispiel #7
0
    def __init__(self,
                 dbm,
                 name=None,
                 label=None,
                 form_code=None,
                 fields=None,
                 language="en",
                 is_registration_model=False,
                 validators=None,
                 enforce_unique_labels=True):
        if not validators: validators = [MandatoryValidator()]
        assert isinstance(dbm, DatabaseManager)
        assert name is None or is_not_empty(name)
        assert fields is None or is_sequence(fields)
        assert form_code is None or (is_string(form_code)
                                     and is_not_empty(form_code))
        # assert type is None or is_not_empty(type)

        DataObject.__init__(self, dbm)
        self.xform_model = None
        self._old_doc = None

        self._snapshots = {}
        self._form_fields = []
        self.errors = []
        self.validators = validators
        self._enforce_unique_labels = enforce_unique_labels
        self._validation_exception = []
        # Are we being constructed from scratch or existing doc?
        if name is None:
            return

        # Not made from existing doc, so build ourselves up
        self._validate_fields(fields)
        self._form_fields = fields

        self._set_doc(form_code, is_registration_model, label, language, name)
Beispiel #8
0
def construct_global_registration_form(manager):
    question1 = HierarchyField(name=ENTITY_TYPE_FIELD_NAME,
                               code=ENTITY_TYPE_FIELD_CODE,
                               label="What is associated subject type?",
                               instruction="Enter a type for the subject")

    question2 = TextField(name=NAME_FIELD,
                          code=NAME_FIELD_CODE,
                          label="What is the subject's name?",
                          defaultValue="some default value",
                          instruction="Enter a subject name",
                          constraints=[TextLengthConstraint(max=80)],
                          required=False)
    question3 = ShortCodeField(
        name=SHORT_CODE_FIELD,
        code=SHORT_CODE,
        label="What is the subject's Unique ID Number",
        defaultValue="some default value",
        instruction="Enter a id, or allow us to generate it",
        constraints=[
            TextLengthConstraint(max=12),
            ShortCodeRegexConstraint(reg='^[a-zA-Z0-9]+$')
        ],
        required=False)
    question4 = HierarchyField(
        name=LOCATION_TYPE_FIELD_NAME,
        code=LOCATION_TYPE_FIELD_CODE,
        label="What is the subject's location?",
        instruction="Enter a region, district, or commune",
        required=False)
    question5 = GeoCodeField(name=GEO_CODE_FIELD_NAME,
                             code=GEO_CODE,
                             label="What is the subject's GPS co-ordinates?",
                             instruction="Enter lat and long. Eg 20.6, 47.3",
                             required=False)
    question6 = TelephoneNumberField(
        name=MOBILE_NUMBER_FIELD,
        code=MOBILE_NUMBER_FIELD_CODE,
        label="What is the mobile number associated with the subject?",
        defaultValue="some default value",
        instruction="Enter the subject's number",
        constraints=(_create_constraints_for_mobile_number()),
        required=True)
    question7 = TextField(name=EMAIL_FIELD,
                          code=EMAIL_FIELD,
                          label="What is the subject's email",
                          defaultValue="",
                          instruction="Enter email id",
                          constraints=[TextLengthConstraint(max=50)],
                          required=False)
    question8 = BooleanField(name=IS_DATASENDER_FIELD_CODE,
                             code=IS_DATASENDER_FIELD_CODE,
                             label="Am I a data sender",
                             defaultValue=True,
                             required=False)
    form_model = EntityFormModel(
        manager,
        name=GLOBAL_REGISTRATION_FORM_CODE,
        form_code=REGISTRATION_FORM_CODE,
        fields=[
            question1, question2, question3, question4, question5, question6,
            question7, question8
        ],
        is_registration_model=True,
        entity_type=["registration"],
        validators=[
            MandatoryValidator(),
            MobileNumberValidationsForReporterRegistrationValidator()
        ])
    return form_model