Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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