def test_add_extras(self):
        context = {}
        settings.ANALYTICS = {
            'GOOGLE': {
                'GTM_SITE_ID': 'gtm-site-id',
                'GA_SITE_ID': 'ga-site-id',
                },
            'DAP': {
                'AGENCY': 'agency',
                'SUBAGENCY': 'sub-agency',
            }
        }
        utils.add_extras(context)

        self.assertTrue('APP_PREFIX' in context)
        self.assertTrue('env' in context)

        self.assertEquals('gtm-site-id',
                          context['ANALYTICS']['GOOGLE']['GTM_SITE_ID'])
        self.assertEquals('ga-site-id',
                          context['ANALYTICS']['GOOGLE']['GA_SITE_ID'])
        self.assertEquals('agency', context['ANALYTICS']['DAP']['AGENCY'])
        self.assertEquals('sub-agency',
                          context['ANALYTICS']['DAP']['SUBAGENCY'])
        self.assertEquals('agency=agency&subagency=sub-agency',
                          context['ANALYTICS']['DAP']['DAP_URL_PARAMS'])
def handle_generic_404(request):
    template = loader.get_template('regulations/generic_404.html')
    context = {'request_path': request.path}
    utils.add_extras(context)
    body = template.render(RequestContext(
        request, context))
    return http.HttpResponseNotFound(body, content_type='text/html')
Example #3
0
def about(request):
   context = {} 
   utils.add_extras(context)
   c = RequestContext(request, context)
   t = select_template([
        'regulations/about.html'])
   return HttpResponse(t.render(c))
def universal(request):
   context = {} 
   utils.add_extras(context)
   c = RequestContext(request, context)
   t = select_template([
        'regulations/universal_landing.html',
        'regulations/generic_universal.html'])
   return HttpResponse(t.render(c))
def universal(request):
    context = {}
    utils.add_extras(context)

    all_versions = versions.fetch_regulations_and_future_versions()
    regs = get_regulations_list(all_versions)

    context['regulations'] = regs
    context['cfr_title_text'] = regs[0]['meta']['cfr_title_text']
    context['cfr_title_number'] = utils.to_roman(
        regs[0]['meta']['cfr_title_number'])

    c = RequestContext(request, context)
    t = select_template([
        'regulations/universal_landing.html',
        'regulations/generic_universal.html'])
    return HttpResponse(t.render(c))
    def get_context_data(self, **kwargs):
        #   Skip ChromeView's implementation
        context = super(ChromeView, self).get_context_data(**kwargs)

        context["reg_part"] = context["label_id"].split("-")[0]
        context["version"] = self.request.GET.get("from_version")
        meta = api_reader.ApiReader().layer("meta", context["reg_part"], context["version"])
        context["meta"] = meta[context["reg_part"]][0]
        context["formatted_id"] = label_to_text(context["label_id"].split("-"))

        content = self.content(context)
        if isinstance(content, HttpResponse):  # error occurred
            return content
        context["partial_content"] = content

        utils.add_extras(context)
        return context
    def get_context_data(self, **kwargs):
        #   Skip ChromeView's implementation
        context = super(ChromeView, self).get_context_data(**kwargs)

        context['reg_part'] = context['label_id'].split('-')[0]
        context['version'] = self.request.GET.get('from_version')
        meta = api_reader.ApiReader().layer('meta', context['reg_part'],
                                            context['version'])
        context['meta'] = meta[context['reg_part']][0]
        context['formatted_id'] = label_to_text(context['label_id'].split('-'))

        content = self.content(context)
        if isinstance(content, HttpResponse):  # error occurred
            return content
        context['partial_content'] = content

        utils.add_extras(context)
        return context
Example #8
0
    def set_chrome_context(self, context, reg_part, version):
        utils.add_extras(context)
        context['reg_part'] = reg_part
        context['history'] = fetch_grouped_history(reg_part)

        toc = fetch_toc(reg_part, version)
        for el in toc:
            el['url'] = SectionUrl().of(
                el['index'], version, self.partial_class.sectional_links)
            for sub in el.get('sub_toc', []):
                sub['url'] = SectionUrl().of(
                    sub['index'], version, self.partial_class.sectional_links)
        context['TOC'] = toc

        regulation_meta = utils.regulation_meta(
            reg_part,
            version,
            self.partial_class.sectional_links)
        context['version_switch_view'] = self.version_switch_view
        context['diff_redirect_label'] = self.diff_redirect_label(
            context['label_id'], toc)
        context['meta'] = regulation_meta
    def test_add_extras_env(self):
        context = {}

        settings.JS_DEBUG = True
        utils.add_extras(context)
        self.assertEqual('source', context['env'])

        settings.JS_DEBUG = False
        utils.add_extras(context)
        self.assertEqual('built', context['env'])

        del(settings.JS_DEBUG)
        utils.add_extras(context)
        self.assertEqual('built', context['env'])