Beispiel #1
0
def check_hq_fq_headers(xlsforms):
    hq = [xlsform for xlsform in xlsforms if xlsform.xml_root == 'HHQ']
    fq = [xlsform for xlsform in xlsforms if xlsform.xml_root == 'FRS']
    for h in hq:
        if not len(h.save_instance) > 1 or not len(h.save_form) > 1:
            m = ('HQ ({}) does not define both "{}" and '
                 '"{}" columns and their values')
            m = m.format(h.short_file, constants.SAVE_INSTANCE, constants.SAVE_FORM)
            raise XlsformError(m)
    for f in fq:
        if not len(f.delete_form) > 1:
            m = 'FQ ({}) missing "{}" column and "true()" value'
            m = m.format(f.short_file, constants.DELETE_FORM)
            raise XlsformError(m)
Beispiel #2
0
 def no_xml_root(filename, expected_xml_root):
     msg = ('"%s" does not have a "name" defined in the settings tab. '
            'Should be defined as "%s".')
     if expected_xml_root:
         msg %= filename, expected_xml_root
     else:
         all_xml_roots = list(constants.xml_codes.values())
         add_on = 'one of %s' % ', '.join(all_xml_roots)
         msg %= filename, add_on
     raise XlsformError(msg)
Beispiel #3
0
 def linking_consistency(filename, save_instance, save_form):
     # Test if columns have a value (first value is column header)
     has_save_instance = len(save_instance) > 1
     has_save_form = len(save_form) > 1
     inconsistent = has_save_instance ^ has_save_form
     if inconsistent:
         if has_save_instance:
             m = '"{}" defines {save_instance} value but no {save_form} value'
         else:
             m = '"{}" defines {save_form} value but no {save_instance} value'
         raise XlsformError(m.format(filename, save_instance=constants.SAVE_INSTANCE, save_form=constants.SAVE_FORM))
Beispiel #4
0
 def external_choices_consistency(filename, wb):
     has_external_type = Xlsform.find_external_type(wb)
     has_external_choices_sheet = Xlsform.find_external_choices(wb)
     inconsistent = has_external_type ^ has_external_choices_sheet
     if inconsistent:
         if has_external_type:
             m = ('"{}" has survey question of type "*_external" but no '
                  '"external_choices" sheet')
         else:
             m = ('"{}" has "external_choices" sheet but no survey '
                  'question of type "*_external"')
         raise XlsformError(m.format(filename))
Beispiel #5
0
 def version_consistency(self):
     version_re = r'[Vv](\d+)'
     prog = re.compile(version_re)
     short_outfile = os.path.split(self.outpath)[1]
     short_outname = os.path.splitext(short_outfile)[0]
     to_check = itertools.chain([
         short_outname,
         self.short_name,
         self.form_id,
         self.form_title,
     ],  self.save_form[1:])
     version = set()
     for word in to_check:
         found = prog.search(word)
         version.add('none' if not found else found.group(1))
     if len(version) > 1:
         m = ('"{}" has inconsistent version numbers among XLSForm '
              'filename, XML filename, form_id, form_title, entries in '
              '{}. Versions found: {}.')
         m = m.format(self.path, constants.SAVE_FORM, ', '.join(version))
         raise XlsformError(m)
Beispiel #6
0
 def bad_filename_and_title(filename, form_title):
     msg = '"%s" has non-matching form_title "%s".'
     msg %= (filename, form_title)
     raise XlsformError(msg)
Beispiel #7
0
 def bad_filename_and_id(filename, form_id):
     msg = '"%s" has non-matching form_id "%s".'
     msg %= (filename, form_id)
     raise XlsformError(msg)
Beispiel #8
0
 def no_form_title(filename):
     msg = '"%s" does not have a form_title defined in the settings tab.'
     msg %= filename
     raise XlsformError(msg)
Beispiel #9
0
 def filename_error(filename):
     msg = ('"%s" does not match approved PMA naming scheme '
            '(approved %s):\n%s')
     msg %= (filename, constants.approval_date, constants.odk_file_model)
     raise XlsformError(msg)
Beispiel #10
0
def hq_fq_mismatch(filename):
    msg = ('"%s" does not have a matching (by country, round, and version) '
           'FQ/HQ questionnaire.\nHQ and FQ must be edited together or not '
           'at all.')
    msg %= filename
    raise XlsformError(msg)