def get_reports_for_year(user, start_year, end_year=None, allow_empty=False, permission=REPORTS_PERMISSION_LEVEL['anonymous']): """Return a list of reports for year.""" reports_list = {} tmp_date = datetime.today() up = user.userprofile today = datetime(year=tmp_date.year, month=tmp_date.month, day=1) date_joined = up.date_joined_program tmp_date = go_fwd_n_months(date_joined) month_first_report = datetime(year=tmp_date.year, day=1, month=tmp_date.month) if not end_year: end_year = start_year for year in range(max(start_year, date_joined.year), end_year+1): reports = user.reports.filter(month__year=year) reports_list[year] = [] for month in range(1, 13): month = datetime(year=year, month=month, day=1) month_details = {'name': number2month(month.month, full_name=False), 'fullname': number2month(month.month, full_name=True)} if (reports.filter(month=month).exists() and ((permission > 1 and month == today) or (month < today))): report = reports.get(month=month) month_details['report'] = report month_details['class'] = 'exists' month_details['link'] = get_report_view_url(report) else: month_details['report'] = None if (permission < 3 or month_first_report > month or month > today): month_details['class'] = 'unavailable' month_details['link'] = '#' else: month_details['class'] = 'editable' link = reverse('reports_edit_report', kwargs={'display_name': up.display_name, 'year': year, 'month': month_details['fullname']}) month_details['link'] = link reports_list[year].append(month_details) return reports_list
def get_month_first_report(user): """Return the month that we should get the first report from a Rep.""" date_joined = user.userprofile.date_joined_program return go_fwd_n_months(date_joined, first_day=True)