コード例 #1
0
def link_to_current_champ(user):
    chapter = user.get_profile().get_chapter()
    if chapter and chapter.is_chapter():
        return reverse('champ_dashboard', kwargs={'group_slug': chapter.slug,
                                                  'year': schoolyear.school_year()})
    else:
        return reverse('champ_dashboard', kwargs={'year': schoolyear.school_year()})
コード例 #2
0
ファイル: views.py プロジェクト: tanveerahmad1517/myewb2
def yearplan(request, group_slug, year=None):
    group = get_object_or_404(Network, slug=group_slug)
    if year == None:
        year = schoolyear.school_year()
        
    yp, created = YearPlan.objects.get_or_create(group=group, year=year,
                                                 defaults={'last_editor': request.user})
    
    if request.method == 'POST':
        form = YearPlanForm(request.POST,
                            instance=yp)
        
        if form.is_valid():
            yp = form.save(commit=False)
            yp.last_editor = request.user
            yp.save()
            
            request.user.message_set.create(message="Year plan updated")
            return HttpResponseRedirect(reverse('champ_dashboard', kwargs={'group_slug': group_slug, 'year': year}))
    else:
        form = YearPlanForm(instance=yp)
        
    return render_to_response('champ/yearplan.html',
                              {'group': group,
                               'form': form,
                               'year': year,
                               'is_group_admin': True,
                               'is_president': group.user_is_president(request.user)
                               },
                               context_instance=RequestContext(request))
コード例 #3
0
def build_stats_for(group_slug=None, metric=None, year=None):
    if not year:
        year = schoolyear.school_year()
        
    activity_filters, metric_filters = build_filters(year)
    
    if group_slug:
        grp = get_object_or_404(Network, slug=group_slug)
        
        if grp.is_chapter():
            metric_filters.append({'activity__group__slug': group_slug})

    metric_filters.append({'activity__visible': True})
    metric_filters.append({'activity__confirmed': True})
    context = run_stats_for(metric_filters, metric)

    natl_activity_filters, natl_metric_filters = build_filters(year)
    natl_metric_filters.append({'activity__visible': True})
    natl_metric_filters.append({'activity__confirmed': True})
    natl_context = run_stats_for(natl_metric_filters, metric)

    return context, natl_context
コード例 #4
0
def year_draw(request):
    metric = request.GET.get('metric', '')
    group = request.GET.get('group', '')
    context = {}

    champsays = []
    history = []

    for y in range(2007, schoolyear.school_year() + 1):
        if group and group != "none":
            stats, natlstats = build_stats_for(metric=metric, group_slug=group, year=y)
        else:
            stats, natlstats = build_stats_for(metric=metric, year=y)
        history.append((y, stats, natlstats))

    context['history'] = history
    context['champsays'] = champsays
    context['metric'] = metric
    context['group'] = group
    context['namedict'] = aggregates.CHAMP_AGGREGATES    
    
    return render_to_response('champ/champalytics/years.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: gorner/myewb2
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))
コード例 #6
0
ファイル: views.py プロジェクト: tanveerahmad1517/myewb2
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))
コード例 #7
0
def progress_draw(request):
    metric = request.GET.get('metric', '')
    group = request.GET.get('group', '')
    progressby = request.GET.get('progressby', '')
    context = {}

    natl_goals = aggregates.CHAMP_AGGREGATES
    champsays = []
    
    if progressby == 'formetric' and metric:
        allgroups = Network.objects.filter(chapter_info__isnull=False, is_active=True).order_by('name')

        progress = {}
        stats, natlstats = build_stats_for(metric=metric)
        name, ngoal = natl_goals[metric]
        useabsolute = request.GET.get('useabsolute', None)
        
        if useabsolute:
            progress['national'] = (stats, stats, ngoal)
        else:
            if ngoal:
                progress['national'] = (stats * 100 / ngoal, stats, ngoal)
            else:
                progress['national'] = (100, stats, ngoal)
        
        for g in allgroups:
            yp = YearPlan.objects.filter(group=g, year=schoolyear.school_year())
            if yp.count():
                yearplan = yp[0]
            else:
                yearplan = None
                
            if yearplan or useabsolute:
                stats, nstats = build_stats_for(g.slug, metric)

                if yearplan:                
                    yearplan_name = aggregates.YEARPLAN_MAP[metric]
                    goal = getattr(yearplan, yearplan_name)
                else:
                    goal = 0
                
                if useabsolute or goal:
                    if useabsolute:
                        progress[g.slug] = (stats, stats, goal)
                    else:
                        progress[g.slug] = (stats * 100 / goal, stats, goal)
                    
                        if g.slug == group:
                            myprogress,temp1,temp2 = progress[g.slug]
                            natlprogress,temp1,temp2 = progress['national']
                            if myprogress == 0:
                                champsays.append("Looks like you haven't done much yet; need a hand?");
                            elif myprogress - natlprogress > 20:
                                champsays.append("Way to go, you're well above national average!");
                            elif myprogress - natlprogress > 0:
                                champsays.append("You're above average here, keep it up!");
                            elif myprogress - natlprogress == 0:
                                champsays.append("You're right on national average.  What are the odds...");
                            elif myprogress - natlprogress > -20:
                                champsays.append("You're just under national average... a bit of work and you'll be on top!");
                            elif myprogress - natlprogress < -20:
                                champsays.append("Looks like this is an area for improvement; need a hand?");
                            
            # can be used to test the graph with more lines...
            #else:
            #    progress[g.slug] = 35
            
        context['progress'] = progress
        context['useabsolute'] = useabsolute
        template = 'progress_metric'
        
    
    elif progressby == 'forchapter' and group:
        yp = YearPlan.objects.filter(group__slug=group, year=schoolyear.school_year())
        if yp.count():
            yearplan = yp[0]
            stats, national = build_stats(group)
            
            chapter_progress = {}
            national_progress = {}

            for s in stats:
                yearplan_name = aggregates.YEARPLAN_MAP[s]
                goal = getattr(yearplan, yearplan_name)
                
                name, ngoal = natl_goals[s]
                if ngoal:
                    nprogress = national[s] * 100 / ngoal
                else:
                    nprogress = 0
                
                if goal:
                    progress = stats[s] * 100 / goal

                    mname, natlgoal = aggregates.CHAMP_AGGREGATES[s]
                    if progress >= 100:
                        champsays.append("You've hit your goal for %s, you champion!" % mname);
                    elif progress < 100 and progress > 80:
                        champsays.append("You've almost hit your %s goal - way to go!" % mname);
                    elif progress < 30 and progress > 10:
                        champsays.append("Your %s numbers are a bit low... need some help?" % mname);
                    elif progress < 10:
                        champsays.append("Woah, watch out for %s - better get moving..." % mname);
                    
                else:
                    progress = -1
                    
                chapter_progress[s] = (progress, stats[s], goal, nprogress, national[s], ngoal)
            
            context['chapter_progress'] = chapter_progress
            
            if request.GET.get('includenatl', None):
                context['includenatl'] = True
            
        else:
            context['noyearplan'] = True
    
        context['champsays'] = champsays
        template = 'progress_chapter'
                
    else:
        return HttpResponse('oops')
    
    context['champsays'] = champsays
    context['group'] = group
    context['metric'] = metric
    context['namedict'] = aggregates.CHAMP_AGGREGATES    
    return render_to_response('champ/champalytics/' + template + '.html',
                              context,
                              context_instance=RequestContext(request))
コード例 #8
0
def link_to_current_champ_national():
        return reverse('champ_dashboard', kwargs={'year': schoolyear.school_year()})
コード例 #9
0
def link_to_current_champ_by_group(user, group):
        return reverse('champ_dashboard', kwargs={'group_slug': group.slug,
                                                  'year': schoolyear.school_year()})