def dashboard(request, year=None, month=None, term=None, group_slug=None): activity_filters, metric_filters = build_filters(year, month, term) journals = 0 grp = None if group_slug: grp = get_object_or_404(Network, slug=group_slug) if grp.is_chapter(): activity_filters.append({'group__slug': group_slug}) metric_filters.append({'activity__group__slug': group_slug}) journals = run_query(Journal.objects.all(), activity_filters).count() else: grp = None activity_filters.append({'visible': True}) metric_filters.append({'activity__visible': True}) metric_filters.append({'activity__confirmed': True}) context = run_stats(metric_filters) context['unconfirmed'] = run_query(Activity.objects.filter(confirmed=False), activity_filters).count() context['confirmed'] = run_query(Activity.objects.filter(confirmed=True), activity_filters).count() context['journals'] = journals natl_activity_filters, natl_metric_filters = build_filters(year, month, term) natl_activity_filters.append({'visible': True}) natl_metric_filters.append({'activity__visible': True}) natl_metric_filters.append({'activity__confirmed': True}) natl_context = run_stats(natl_metric_filters) natl_context['unconfirmed'] = run_query(Activity.objects.filter(confirmed=False), natl_activity_filters).count() natl_context['confirmed'] = run_query(Activity.objects.filter(confirmed=True), natl_activity_filters).count() # stuff all national values into context, prepending key with natl_ for x, y in natl_context.items(): context['natl_' + x] = y context['group'] = None context['yearplan'] = None context['is_group_admin'] = False if grp: context['group'] = grp context['is_group_admin'] = grp.user_is_admin(request.user) context['is_president'] = grp.user_is_president(request.user) if year: yp = YearPlan.objects.filter(group=grp, year=year) else: yp = YearPlan.objects.filter(group=grp, year=date.today().year) if yp.count(): context['yearplan'] = yp[0] context['year'] = year context['month'] = month context['term'] = term context['nowyear'] = schoolyear.school_year() if year: context['prevyear'] = int(year) - 1 context['nextyear'] = int(year) + 1 context['nowmonth'] = ("%d" % date.today().month).rjust(2, '0') if month: if month == "01": context['prevmonth'] = (12, int(year)-1) else: context['prevmonth'] = (("%d" % (int(month)-1)).rjust(2, '0'), year) if month == "12": context['nextmonth'] = ("01", int(year)+1) else: context['nextmonth'] = (("%d" % (int(month)+1)).rjust(2, '0'), year) context['nowterm'] = schoolyear.term() if term: context['prevterm'] = schoolyear.prevterm(term, year) context['nextterm'] = schoolyear.nextterm(term, year) context['allgroups'] = Network.objects.filter(chapter_info__isnull=False, is_active=True).order_by('name') return render_to_response('champ/dashboard.html', context, context_instance=RequestContext(request))
def dashboard(request, year=None, month=None, term=None, group_slug=None): activity_filters, metric_filters = build_filters(year, month, term) journals = 0 grp = None if group_slug: grp = get_object_or_404(Network, slug=group_slug) if grp.is_chapter(): activity_filters.append({'group__slug': group_slug}) metric_filters.append({'activity__group__slug': group_slug}) journals = run_query(Journal.objects.all(), activity_filters).count() else: grp = None activity_filters.append({'visible': True}) metric_filters.append({'activity__visible': True}) metric_filters.append({'activity__confirmed': True}) context = run_stats(metric_filters) context['unconfirmed'] = run_query(Activity.objects.filter(confirmed=False), activity_filters).count() context['confirmed'] = run_query(Activity.objects.filter(confirmed=True), activity_filters).count() context['journals'] = journals natl_activity_filters, natl_metric_filters = build_filters(year, month, term) natl_activity_filters.append({'visible': True}) natl_metric_filters.append({'activity__visible': True}) natl_metric_filters.append({'activity__confirmed': True}) natl_context = run_stats(natl_metric_filters) natl_context['unconfirmed'] = run_query(Activity.objects.filter(confirmed=False), natl_activity_filters).count() natl_context['confirmed'] = run_query(Activity.objects.filter(confirmed=True), natl_activity_filters).count() # stuff all national values into context, prepending key with natl_ for x, y in natl_context.items(): context['natl_' + x] = y context['group'] = None context['yearplan'] = None context['is_group_admin'] = False if grp: context['group'] = grp context['is_group_admin'] = grp.user_is_admin(request.user) context['is_president'] = grp.user_is_president(request.user) if year: yp = YearPlan.objects.filter(group=grp, year=year) else: yp = YearPlan.objects.filter(group=grp, year=schoolyear.school_year()) if yp.count(): context['yearplan'] = yp[0] context['year'] = year context['month'] = month context['term'] = term context['nowyear'] = date.today().year context['nowschoolyear'] = schoolyear.school_year() if year: context['prevyear'] = int(year) - 1 context['nextyear'] = int(year) + 1 context['nowmonth'] = ("%d" % date.today().month).rjust(2, '0') if month: if month == "01": context['prevmonth'] = (12, int(year)-1) else: context['prevmonth'] = (("%d" % (int(month)-1)).rjust(2, '0'), year) if month == "12": context['nextmonth'] = ("01", int(year)+1) else: context['nextmonth'] = (("%d" % (int(month)+1)).rjust(2, '0'), year) context['nowterm'] = schoolyear.term() if term: context['prevterm'] = schoolyear.prevterm(term, year) context['nextterm'] = schoolyear.nextterm(term, year) context['allgroups'] = Network.objects.filter(chapter_info__isnull=False, is_active=True).order_by('name') context['national'] = run_natl_goals() return render_to_response('champ/dashboard.html', context, context_instance=RequestContext(request))