Example #1
0
def create_question(post_dict, dbm):
    options = post_dict.get('options')
    datadict_type = options.get('ddtype') if options is not None else None
    if is_not_empty(datadict_type):
        #  question already has a data dict type
        datadict_slug = datadict_type.get('slug')
    else:
        datadict_slug = str(slugify(unicode(post_dict.get('title'))))
    ddtype = get_or_create_data_dict(dbm=dbm,
                                     name=post_dict.get('code'),
                                     slug=datadict_slug,
                                     primitive_type=post_dict.get('type'),
                                     description=post_dict.get('title'))

    if post_dict["type"] == "text":
        return _create_text_question(post_dict, ddtype)
    if post_dict["type"] == "integer":
        return _create_integer_question(post_dict, ddtype)
    if post_dict["type"] == "geocode":
        return _create_geo_code_question(post_dict, ddtype)
    if post_dict["type"] == "select":
        return _create_select_question(post_dict,
                                       single_select_flag=False,
                                       ddtype=ddtype)
    if post_dict["type"] == "date":
        return _create_date_question(post_dict, ddtype)
    if post_dict["type"] == "select1":
        return _create_select_question(post_dict,
                                       single_select_flag=True,
                                       ddtype=ddtype)
Example #2
0
 def _get_ddtype(self, post_dict):
     options = post_dict.get('options')
     datadict_type = options.get('ddtype') if options is not None else None
     if is_not_empty(datadict_type):
         #  question already has a data dict type
         datadict_slug = datadict_type.get('slug')
     else:
         datadict_slug = str(slugify(unicode(post_dict.get('title'))))
     ddtype = self._get_or_create_data_dict(
         name=post_dict.get('code'),
         slug=datadict_slug,
         primitive_type=post_dict.get('type'),
         description=post_dict.get('title'))
     return ddtype
Example #3
0
                print "%d LGAs failed to load:" % len(lga_failed)
                for lga in lga_failed:
                    print "\t%s" % lga

        if load_mdg:
            print "Adding MDG indicator data..."

            print "Adding data from 'Education MDG Data' worksheet"
            lga_loaded = []
            lga_failed = []
            for i, row in enumerate(nims_data['Education MDG Data']):
                if i > max_mdg_to_import:
                    break
                raw_slug = get_string('indicator', row)
                if not raw_slug: continue
                slug = str(slugify(unicode(raw_slug, 'utf-8')))
                name = get_string('indicator', row)
                lga = get_string('lga', row)
                state = get_string('state', row)
                mdg = get_string('mdg', row)
                value = get_string('value', row)
                location = ("Nigeria", state, lga)
                if not slug in datadict_types:
                    dd_type = create_datadict_type(
                        dbm,
                        slug=slug,
                        name=name,
                        primitive_type='number',
                        tags=['Education', 'MDG']
                    )
                    datadict_types[slug] = dd_type.id
Example #4
0
                print "%d LGAs failed to load:" % len(lga_failed)
                for lga in lga_failed:
                    print "\t%s" % lga

        if load_mdg:
            print "Adding MDG indicator data..."

            print "Adding data from 'Education MDG Data' worksheet"
            lga_loaded = []
            lga_failed = []
            for i, row in enumerate(nims_data['Education MDG Data']):
                if i > max_mdg_to_import:
                    break
                raw_slug = get_string('indicator', row)
                if not raw_slug: continue
                slug = str(slugify(unicode(raw_slug, 'utf-8')))
                name = get_string('indicator', row)
                lga = get_string('lga', row)
                state = get_string('state', row)
                mdg = get_string('mdg', row)
                value = get_string('value', row)
                location = ("Nigeria", state, lga)
                if not slug in datadict_types:
                    dd_type = create_datadict_type(dbm,
                                                   slug=slug,
                                                   name=name,
                                                   primitive_type='number',
                                                   tags=['Education', 'MDG'])
                    datadict_types[slug] = dd_type.id
                data = [(slug, value,
                         get_datadict_type(dbm, datadict_types[slug]))]