def get_end_label(self, period):
     return l10n_date_medium(period['end'], decode=True)
 def get_start_label(self, period):
     return l10n_date_medium(period['start'], decode=True)
Example #3
0
 def filename(self):
     report_date = l10n_date_medium(timezone.now().date())
     return u'{name} {report_date}.xlsx'.format(name=self.report_name, report_date=report_date)
Example #4
0
 def end_display(self):
     return l10n_date_medium(self.period['end'])
Example #5
0
 def start_display(self):
     return l10n_date_medium(self.period['start'])
Example #6
0
def get_program_filter_data(request):
    """uses request user to populate program data for filter dropdowns in IPTT Quickstart / IPTT Reeport"""

    programs = []
    #countries = request.user.tola_user.available_countries
    programs_qs = request.user.tola_user.available_programs.filter(
        funding_status="Funded",
        reporting_period_start__isnull=False,
        reporting_period_end__isnull=False).order_by('id')
    frequencies_qs = Indicator.objects.filter(
        program__in=programs_qs, target_frequency__isnull=False).order_by(
            'program_id',
            'target_frequency').values('program_id',
                                       'target_frequency').distinct()
    for program in programs_qs:
        frequencies = [
            f['target_frequency'] for f in frequencies_qs
            if f['program_id'] == program.pk
        ]
        if frequencies:
            start_formatted = l10n_date_medium(program.reporting_period_start)
            end_formatted = l10n_date_medium(program.reporting_period_end)
            programs.append({
                'id': program.pk,
                'name': program.name,
                'old_style_levels': not program.results_framework,
                'frequencies': frequencies,
                'reporting_period_start': start_formatted,
                'reporting_period_end': end_formatted,
                'result_chain_filter_label': program.rf_chain_sort_label,
                'short_result_chain_label': program.rf_chain_group_label,
                # blanks in below strings are placeholders until this moves to associative arrays:
                'periodDateRanges': {
                    '1': [[
                        start_formatted,
                        end_formatted,
                        '',
                        '',
                        '',
                        program.reporting_period_start.isoformat(),
                        program.reporting_period_end.isoformat(),
                    ]],
                    '2': [[
                        start_formatted,
                        end_formatted,
                        ugettext('Midline'),
                        '',
                        '',
                        program.reporting_period_start.isoformat(),
                        program.reporting_period_end.isoformat(),
                    ],
                          [
                              start_formatted,
                              end_formatted,
                              ugettext('Endline'),
                              '',
                              '',
                              program.reporting_period_start.isoformat(),
                              program.reporting_period_end.isoformat(),
                          ]],
                    '3': [[
                        l10n_date_medium(period['start']),
                        l10n_date_medium(period['end']),
                        period['start'] > timezone.now().date(),
                        '',
                        '',
                        period['start'].isoformat(),
                        period['end'].isoformat(),
                    ] for period in PeriodicTarget.generate_for_frequency(3)
                          (program.reporting_period_start,
                           program.reporting_period_end)],
                    '4': [[
                        l10n_date_medium(period['start']),
                        l10n_date_medium(period['end']),
                        period['start'] > timezone.now().date(),
                        '',
                        '',
                        period['start'].isoformat(),
                        period['end'].isoformat(),
                    ] for period in PeriodicTarget.generate_for_frequency(4)
                          (program.reporting_period_start,
                           program.reporting_period_end)],
                    '5': [[
                        l10n_date_medium(period['start']),
                        l10n_date_medium(period['end']),
                        period['start'] > timezone.now().date(),
                        '',
                        '',
                        period['start'].isoformat(),
                        period['end'].isoformat(),
                    ] for period in PeriodicTarget.generate_for_frequency(5)
                          (program.reporting_period_start,
                           program.reporting_period_end)],
                    '6': [[
                        l10n_date_medium(period['start']),
                        l10n_date_medium(period['end']),
                        period['start'] > timezone.now().date(),
                        '',
                        '',
                        period['start'].isoformat(),
                        period['end'].isoformat(),
                    ] for period in PeriodicTarget.generate_for_frequency(6)
                          (program.reporting_period_start,
                           program.reporting_period_end)],
                    '7': [[
                        l10n_date_medium(period['start']),
                        l10n_date_medium(period['end']),
                        l10n_monthname(period['start']), period['start'].year,
                        period['start'] > timezone.now().date(),
                        period['start'].isoformat(), period['end'].isoformat()
                    ] for period in PeriodicTarget.generate_for_frequency(7)
                          (program.reporting_period_start,
                           program.reporting_period_end)],
                }
            })
    return programs