예제 #1
0
 def test_should_return_date_format(self):
     field = DateField(name="What is the date?",
                       code="dat",
                       label="naam",
                       date_format="dd/mm/yyyy")
     preview = helper.get_preview_for_field(field)
     self.assertEqual("dd/mm/yyyy", preview["constraints"])
예제 #2
0
def questionnaire_preview(request, project_id=None, sms_preview=False):
    manager = get_database_manager(request.user)
    if request.method == 'GET':
        dashboard_page = settings.HOME_PAGE + "?deleted=true"
        questionnaire = Project.get(manager, project_id)
        if questionnaire.is_void():
            return HttpResponseRedirect(dashboard_page)
            #if form_model.is_entity_type_reporter():
        #    fields = helper.hide_entity_question(form_model.fields)
        project_links = make_project_links(questionnaire)
        questions = []
        fields = questionnaire.fields
        for field in fields:
            question = helper.get_preview_for_field(field)
            questions.append(question)
        example_sms = "%s" % (questionnaire.form_code)
        example_sms += get_example_sms(fields)

    template = 'project/questionnaire_preview.html' if sms_preview else 'project/questionnaire_preview_list.html'
    return render_to_response(
        template, {
            "questions": questions,
            'questionnaire_code': questionnaire.form_code,
            'project': questionnaire,
            'project_links': project_links,
            'is_quota_reached': is_quota_reached(request),
            'example_sms': example_sms,
            'org_number': get_organization_telephone_number(request)
        },
        context_instance=RequestContext(request))
예제 #3
0
 def test_should_add_constraint_text_for_numeric_field_with_min(self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     constraint = NumericConstraint(min=10)
     field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type, range=constraint)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Minimum 10", preview["constraint"])
     self.assertEqual("integer", preview["type"])
예제 #4
0
 def test_should_return_choices(self):
     type = DataDictType(Mock(DatabaseManager), name="color type")
     field = SelectField(name="What's the color?", code="nam", label="naam", ddtype=type,
                         options=[("Red", "a"), ("Green", "b"), ("Blue", "c")])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("select1", preview["type"])
     self.assertEqual(["Red", "Green", "Blue"], preview["constraint"])
예제 #5
0
 def test_should_add_constraint_text_for_numeric_field_with_max(self):
     constraint = NumericRangeConstraint(max=100)
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          constraints=[constraint])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Upto 100", preview["constraints"])
예제 #6
0
 def test_should_add_constraint_text_for_text_field_with_max(self):
     constraints = [TextLengthConstraint(max=100)]
     field = TextField(name="What's in a name?",
                       code="nam",
                       label="naam",
                       constraints=constraints)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Upto 100 characters", preview["constraints"])
예제 #7
0
 def test_should_create_basic_fields_in_preview(self):
     type = DataDictType(Mock(DatabaseManager), name="Name type")
     field = TextField(name="What's in a name?", code="nam", label="naam", ddtype=type, instruction="please write more tests")
     preview = helper.get_preview_for_field(field)
     self.assertEquals("What's in a name?", preview["description"])
     self.assertEquals("nam", preview["code"])
     self.assertEquals("text", preview["type"])
     self.assertEquals("please write more tests", preview["instruction"])
예제 #8
0
 def test_should_return_geocode_format(self):
     type = DataDictType(Mock(DatabaseManager), name="date type")
     field = GeoCodeField(name="What is the place?",
                          code="dat",
                          label="naam",
                          ddtype=type)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("xx.xxxx yy.yyyy", preview["constraints"])
예제 #9
0
 def test_should_add_constraint_text_for_numeric_field_without_constraint(
         self):
     field = IntegerField(
         name="What's in the age?",
         code="nam",
         label="naam",
     )
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraints"])
예제 #10
0
 def test_should_return_choices_type_as_select(self):
     field = SelectField(name="What's the color?",
                         code="nam",
                         label="naam",
                         options=[("Red", "a"), ("Green", "b"),
                                  ("Blue", "c")],
                         single_select_flag=False)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("select", preview["type"])
예제 #11
0
 def test_should_return_date_format(self):
     type = DataDictType(Mock(DatabaseManager), name="date type")
     field = DateField(name="What is the date?",
                       code="dat",
                       label="naam",
                       ddtype=type,
                       date_format="dd/mm/yyyy")
     preview = helper.get_preview_for_field(field)
     self.assertEqual("dd/mm/yyyy", preview["constraints"])
예제 #12
0
 def test_should_add_constraint_text_for_numeric_field_without_constraint(
         self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          ddtype=type)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraints"])
예제 #13
0
 def test_should_create_basic_fields_in_preview(self):
     field = TextField(name="naam",
                       code="nam",
                       label="What's in a name?",
                       instruction="please write more tests")
     preview = helper.get_preview_for_field(field)
     self.assertEquals("What's in a name?", preview["description"])
     self.assertEquals("nam", preview["code"])
     self.assertEquals("text", preview["type"])
     self.assertEquals("please write more tests", preview["instruction"])
예제 #14
0
 def test_should_add_constraint_text_for_numeric_field_with_max(self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     constraint = NumericRangeConstraint(max=100)
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          ddtype=type,
                          constraints=[constraint])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Upto 100", preview["constraints"])
예제 #15
0
 def test_should_return_choices(self):
     field = SelectField(name="What's the color?",
                         code="nam",
                         label="naam",
                         options=[("Red", "a"), ("Green", "b"),
                                  ("Blue", "c")])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("select1", preview["type"])
     self.assertEqual([("Red", "a"), ("Green", "b"), ("Blue", "c")],
                      preview["constraints"])
예제 #16
0
 def test_should_add_constraint_text_for_text_field_with_max(self):
     type = DataDictType(Mock(DatabaseManager), name="Name type")
     constraints = [TextLengthConstraint(max=100)]
     field = TextField(name="What's in a name?",
                       code="nam",
                       label="naam",
                       ddtype=type,
                       constraints=constraints)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Upto 100 characters", preview["constraints"])
예제 #17
0
def questionnaire_preview(request, project_id=None, sms_preview=False):
    manager = get_database_manager(request.user)
    if request.method == 'GET':
        project = Project.load(manager.database, project_id)
        form_model = FormModel.get(manager, project.qid)
        fields = form_model.fields
        if form_model.is_entity_type_reporter():
            fields = helper.hide_entity_question(form_model.fields)
        project_links = make_project_links(project, form_model.form_code)
        questions = []
        for field in fields:
            question = helper.get_preview_for_field(field)
            questions.append(question)
        example_sms = "%s" % (
            form_model.form_code)
        example_sms += get_example_sms(fields)

    template = 'project/questionnaire_preview.html' if sms_preview else 'project/questionnaire_preview_list.html'
    return render_to_response(template,
                              {"questions": questions, 'questionnaire_code': form_model.form_code,
                               'project': project, 'project_links': project_links,
                               'is_quota_reached': is_quota_reached(request),
                               'example_sms': example_sms, 'org_number': get_organization_telephone_number(request)},
                              context_instance=RequestContext(request))
예제 #18
0
 def test_should_add_constraint_text_for_text_field_without_constraint(
         self):
     field = TextField(name="What's in a name?", code="nam", label="naam")
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraints"])
예제 #19
0
 def test_should_add_constraint_text_for_numeric_field_without_constraint(self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     field = IntegerField(name="What's in the age?", code="nam", label="naam", ddtype=type)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraint"])
def get_questions(form_model):
    fields = form_model.fields
    if form_model.is_entity_type_reporter():
        fields = hide_entity_question(form_model.fields)

    return [get_preview_for_field(field) for field in fields]
예제 #21
0
 def test_should_add_constraint_text_for_text_field_with_max_and_min(self):
     type = DataDictType(Mock(DatabaseManager), name="Name type")
     constraint = TextConstraint(min=10, max=100)
     field = TextField(name="What's in a name?", code="nam", label="naam", ddtype=type, length=constraint)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Between 10 - 100 characters", preview["constraint"])
예제 #22
0
 def test_should_return_date_format(self):
     type = DataDictType(Mock(DatabaseManager), name="date type")
     field = DateField(name="What is the date?", code="dat", label="naam", ddtype=type, date_format="dd/mm/yyyy")
     preview = helper.get_preview_for_field(field)
     self.assertEqual("dd/mm/yyyy", preview["constraint"])
예제 #23
0
 def test_should_return_geocode_format(self):
     field = GeoCodeField(name="What is the place?",
                          code="dat",
                          label="naam")
     preview = helper.get_preview_for_field(field)
     self.assertEqual("xx.xxxx yy.yyyy", preview["constraints"])
예제 #24
0
 def test_should_return_geocode_format(self):
     type = DataDictType(Mock(DatabaseManager), name="date type")
     field = GeoCodeField(name="What is the place?", code="dat", label="naam", ddtype=type)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("xx.xxxx yy.yyyy", preview["constraint"])
예제 #25
0
def get_questions(form_model):
    fields = form_model.fields
    return [get_preview_for_field(field) for field in fields]