def build_sections_list(): d = {} for fname in os.listdir(os.path.join(*['dmd', 'analysis'])): if not fname.endswith('.py') \ or not re.match(r'^section([0-9]+)\.py$', fname): continue mod = import_path('dmd.analysis.{}'.format(fname[:-3]), failsafe=True) if mod is None: continue d.update({text_type(mod.SECTION_ID): mod.SECTION_NAME}) return d
def analysis(request, section_id, entity_uuid=None, perioda_str=None, periodb_str=None, *args, **kwargs): ''' Generic view for simple sections using an entity and periods ''' context = {'page': 'analysis_section{}'.format(section_id)} if section_id not in SECTIONS: raise Http404(_("Unknown section ID `{sid}`").format(sid=section_id)) section = import_path('dmd.analysis.section{}'.format(section_id)) # handling entity context.update(process_entity_filter(request, entity_uuid)) # handling periods context.update(process_period_filter(request, perioda_str, 'perioda')) context.update(process_period_filter(request, periodb_str, 'periodb')) if context['perioda'] > context['periodb']: context['perioda'], context['periodb'] = \ context['periodb'], context['perioda'] periods = MonthPeriod.all_from(context['perioda'], context['periodb']) context.update({'selected_periods': periods}) context.update({ 'section': section_id, 'section_name': SECTIONS.get(section_id), 'elements': section.build_context(periods=periods, entity=context['entity']) }) # absolute URI for links context.update({'baseurl': request.build_absolute_uri()}) return render( request, kwargs.get('template_name', 'analysis_section{}.html'.format(section_id)), context)
def analysis(request, section_id, entity_uuid=None, perioda_str=None, periodb_str=None, *args, **kwargs): ''' Generic view for simple sections using an entity and periods ''' context = {'page': 'analysis_section{}'.format(section_id)} if section_id not in SECTIONS: raise Http404(_("Unknown section ID `{sid}`").format(sid=section_id)) section = import_path('dmd.analysis.section{}'.format(section_id)) # handling entity context.update(process_entity_filter(request, entity_uuid)) # handling periods context.update(process_period_filter(request, perioda_str, 'perioda')) context.update(process_period_filter(request, periodb_str, 'periodb')) if context['perioda'] > context['periodb']: context['perioda'], context['periodb'] = \ context['periodb'], context['perioda'] periods = MonthPeriod.all_from(context['perioda'], context['periodb']) context.update({'selected_periods': periods}) context.update({ 'section': section_id, 'section_name': SECTIONS.get(section_id), 'elements': section.build_context(periods=periods, entity=context['entity']) }) # absolute URI for links context.update({'baseurl': request.build_absolute_uri()}) return render(request, kwargs.get('template_name', 'analysis_section{}.html'.format(section_id)), context)