Beispiel #1
0
    def get_geos(self, geo_ids):
        """
        Return a tuple (data_geos, info_geos) of geo objects,
        where data_geos or geos we should get data for, and info_geos
        are geos that we only need to return geo info/metadata for.
        """
        data_geos = []
        info_geos = []

        for geo_id in geo_ids:
            # either country-KE or level|country-KE, which indicates
            # we must break country-KE into +levels+
            if not '-' in geo_id:
                raise LocationNotFound('Invalid geo id: %s' % geo_id)

            level, code = geo_id.split('-', 1)

            if '|' in level:
                # break geo down further
                split_level, level = level.split('|', 1)
                geo = get_geography(code, level)
                info_geos.append(geo)
                try:
                    data_geos.extend(geo.split_into(split_level))
                except ValueError as e:
                    raise LocationNotFound('Invalid geo level: %s' % split_level)

            else:
                # normal geo
                data_geos.append(get_geography(code, level))

        return data_geos, info_geos
Beispiel #2
0
    def get_geos(self, geo_ids):
        """
        Return a tuple (data_geos, info_geos) of geo objects,
        where data_geos or geos we should get data for, and info_geos
        are geos that we only need to return geo info/metadata for.
        """
        data_geos = []
        info_geos = []

        for geo_id in geo_ids:
            # either country-KE or level|country-KE, which indicates
            # we must break country-KE into +levels+
            if '-' not in geo_id:
                raise LocationNotFound('Invalid geo id: %s' % geo_id)

            level, code = geo_id.split('-', 1)

            if '|' in level:
                # break geo down further
                split_level, level = level.split('|', 1)
                geo = get_geography(code, level)
                info_geos.append(geo)
                try:
                    data_geos.extend(geo.split_into(split_level))
                except ValueError:
                    raise LocationNotFound('Invalid geo level: %s' %
                                           split_level)

            else:
                # normal geo
                data_geos.append(get_geography(code, level))

        return data_geos, info_geos
Beispiel #3
0
    def get_context_data(self, geo_id1, geo_id2):
        page_context = {"geo_id1": geo_id1, "geo_id2": geo_id2}

        try:
            level, code = geo_id1.split("-", 1)
            page_context["geo1"] = get_geography(code, level)

            level, code = geo_id2.split("-", 1)
            page_context["geo2"] = get_geography(code, level)
        except (ValueError, LocationNotFound):
            raise Http404

        return page_context
Beispiel #4
0
    def get_context_data(self, *args, **kwargs):
        geography_id = self.geo_id
        page_context = {}

        try:
            geo_level, geo_code = geography_id.split('-', 1)
            
            geo = get_geography(geo_code, geo_level)
            profile_data = get_census_profile(geo_code, geo_level)
            profile_data['elections'] = get_elections_profile(geo_code, geo_level)
            profile_data['election_list'] = ["national_2014", "provincial_2014"]
            profile_data['geography'] = geo.as_dict_deep()
        except (ValueError, LocationNotFound):
            raise Http404

        profile_data = self.enhance_api_data(profile_data)
        page_context.update(profile_data)

        profile_data_json = SafeString(simplejson.dumps(profile_data, cls=LazyEncoder))
        self.write_profile_json(profile_data_json)

        page_context.update({
            'profile_data_json': profile_data_json
        })

        return page_context
Beispiel #5
0
    def get_context_data(self, *args, **kwargs):
        geography_id = self.geo_id
        page_context = {}

        try:
            geo_level, geo_code = geography_id.split('-', 1)

            geo = get_geography(geo_code, geo_level)
        except (ValueError, LocationNotFound):
            raise Http404

        profile_data = get_census_profile(geo_code, geo_level)
        profile_data['elections'] = get_elections_profile(geo_code, geo_level)
        profile_data['geography'] = geo.as_dict_deep()

        profile_data = enhance_api_data(profile_data)
        page_context.update(profile_data)

        profile_data_json = SafeString(
            simplejson.dumps(profile_data, cls=LazyEncoder))

        page_context.update({'profile_data_json': profile_data_json})

        # is this a head-to-head view?
        page_context['head2head'] = 'h2h' in self.request.GET

        return page_context
Beispiel #6
0
    def get_context_data(self, geo_id1, geo_id2):
        page_context = {
            'geo_id1': geo_id1,
            'geo_id2': geo_id2,
        }

        try:
            level, code = geo_id1.split('-', 1)
            page_context['geo1'] = get_geography(code, level)

            level, code = geo_id2.split('-', 1)
            page_context['geo2'] = get_geography(code, level)
        except (ValueError, LocationNotFound):
            raise Http404

        return page_context
    def get_context_data(self, geo_id1, geo_id2):
        page_context = {
            'geo_id1': geo_id1,
            'geo_id2': geo_id2,
        }

        try:
            level, code = geo_id1.split('-', 1)
            page_context['geo1'] = get_geography(code, level)

            level, code = geo_id2.split('-', 1)
            page_context['geo2'] = get_geography(code, level)
        except (ValueError, LocationNotFound):
            raise Http404

        return page_context
Beispiel #8
0
    def get_context_data(self, *args, **kwargs):
        geography_id = self.geo_id
        page_context = {}

        try:
            geo_level, geo_code = geography_id.split("-", 1)

            geo = get_geography(geo_code, geo_level)
        except (ValueError, LocationNotFound):
            raise Http404

        profile_data = get_census_profile(geo_code, geo_level)
        profile_data["elections"] = get_elections_profile(geo_code, geo_level)
        profile_data["election_list"] = ["national_2014", "provincial_2014"]
        profile_data["geography"] = geo.as_dict_deep()

        profile_data = enhance_api_data(profile_data)
        page_context.update(profile_data)

        profile_data_json = SafeString(simplejson.dumps(profile_data, cls=LazyEncoder))

        page_context.update({"profile_data_json": profile_data_json})

        # is this a head-to-head view?
        page_context["head2head"] = "h2h" in self.request.GET

        return page_context
 def get_geography(self, geo_id):
     try:
         geo_level, geo_code = geo_id.split('-', 1)
         return get_geography(geo_code, geo_level)
     except (ValueError, LocationNotFound):
         raise Http404