示例#1
0
    def _loc_type_dict(self, loc_type):
        uncategorized_keys = set()
        tab_rows = []
        for loc in Location.filter_by_type(self.domain, loc_type):

            model_data, uncategorized_data = \
                self.data_model.get_model_and_uncategorized(loc.metadata)

            uncategorized_keys.update(uncategorized_data.keys())

            loc_dict = {
                'site_code': loc.site_code,
                'name': loc.name,
                'parent_site_code': loc.parent.site_code if loc.parent else '',
                'latitude': loc.latitude or '',
                'longitude': loc.longitude or '',
                'data': model_data,
                'uncategorized_data': uncategorized_data,
                'consumption': self.get_consumption(loc),
            }

            tab_rows.append(dict(flatten_json(loc_dict)))

        tab_headers = ['site_code', 'name', 'parent_site_code', 'latitude', 'longitude']
        def _extend_headers(prefix, headers):
            tab_headers.extend(json_to_headers(
                {prefix: {header: None for header in headers}}
            ))
        _extend_headers('data', (f.slug for f in self.data_model.fields))
        _extend_headers('uncategorized_data', uncategorized_keys)
        if self.include_consumption_flag and loc_type not in self.administrative_types:
            _extend_headers('consumption', self.product_codes)

        return (loc_type, {
            'headers': tab_headers,
            'rows': tab_rows,
        })
示例#2
0
 def get_group_rows():
     for group_dict in group_dicts:
         row = dict(flatten_json(group_dict))
         yield [row.get(header) or '' for header in group_headers]
示例#3
0
 def get_group_rows():
     for group_dict in group_dicts:
         row = dict(flatten_json(group_dict))
         yield [row.get(header) or '' for header in group_headers]
示例#4
0
 def get_user_rows():
     for user_dict in user_dicts:
         row = dict(flatten_json(user_dict))
         yield [row.get(header) or '' for header in user_headers]
示例#5
0
 def get_user_rows():
     for user_dict in user_dicts:
         row = dict(flatten_json(user_dict))
         yield [row.get(header) or '' for header in user_headers]