Esempio n. 1
0
def wg_page(request, export=None):
    if request.GET.get('refresh'):
        for b in Ballot.objects.filter(ballot_type=Ballot.WGInitial.code):
            DenormalizedBallot.request_update(ballot_pk=b.number)
        for b in Ballot.objects.filter(ballot_type=Ballot.WGRecirc.code):
            DenormalizedBallot.request_update(ballot_pk=b.number)
        return http.HttpResponseRedirect(reverse('ballot.views.wg_page'))
    next_page = reverse('ballot.views.wg_page')
    if request.GET.get('redraw', None) is not None:
        try:
            redraw = int(request.GET.get('redraw', 0))
        except ValueError:
            redraw = 0
        cc = CacheControl()
        if redraw == 0:
            cc.open_ver = cc.open_ver + 1
        elif redraw == 1:
            cc.closed_ver = cc.closed_ver + 1
        return http.HttpResponseRedirect(next_page)
    ballots = list(
        DenormalizedBallot.objects.filter(
            ballot_type=DenormalizedBallot.WGInitial.code)) + list(
                DenormalizedBallot.objects.filter(
                    ballot_type=DenormalizedBallot.WGRecirc.code)) + list(
                        DenormalizedBallot.objects.filter(
                            ballot_type=DenormalizedBallot.Procedural.code))
    return ballot_page(request,
                       ballots,
                       export,
                       sponsor=False,
                       next=next_page,
                       export_page='LetterBallots')
Esempio n. 2
0
def main_page(request):
    next_page=reverse('ballot.views.main_page')
    if request.GET.get('refresh'):
        for b in Ballot.objects.all():
            DenormalizedBallot.request_update(ballot_pk=b.number)
        return http.HttpResponseRedirect(next_page)
    needs_update = not DenormalizedBallot.backlog_poll().idle 
    return render_to_response('ballot/index.html', locals(), context_instance=RequestContext(request))
Esempio n. 3
0
def main_page(request):
    next_page = reverse('ballot.views.main_page')
    if request.GET.get('refresh'):
        for b in Ballot.objects.all():
            DenormalizedBallot.request_update(ballot_pk=b.number)
        return http.HttpResponseRedirect(next_page)
    needs_update = not DenormalizedBallot.backlog_poll().idle
    return render_to_response('ballot/index.html',
                              locals(),
                              context_instance=RequestContext(request))
Esempio n. 4
0
def ballot_page(request, ballots, export, sponsor, next, export_page):
    closed_ballots = []
    open_ballots = []
    needs_update = not DenormalizedBallot.backlog_poll().idle
    for b in ballots:
        if b.is_open:
            open_ballots.append(b)
        else:
            closed_ballots.append(b)
    if sponsor:
        open_ballots.sort(key=lambda x: x.closed, reverse=True)
        closed_ballots.sort(key=lambda x: x.closed, reverse=True)
    else:
        open_ballots.sort(key=lambda x: x.number, reverse=True)
        closed_ballots.sort(key=lambda x: x.number, reverse=True)
    context = dict(has_open=len(open_ballots)>0, open=open_ballots, \
                   closed=closed_ballots, next_page=next, export=export, \
                   sponsor=sponsor, needs_update=needs_update, \
                   export_page=reverse('ballot.views.main_page')+export_page)
    context_instance = RequestContext(request)
    context_instance['cache'].export = export
    if export:
        return export_html('ballot/ballots.html',
                           context,
                           context_instance=context_instance,
                           filename='%s.%s' % (export_page, export))
    return render_to_response('ballot/ballots.html',
                              context,
                              context_instance=context_instance)
Esempio n. 5
0
def backlog_worker(request):
    try:
        dn = DenormalizedBallot.denormalize(ballot_pk=request.POST['ballot'],
                                            commit=True)
        return HttpResponse(content='DenormalizedBallot %s' % (dn.task_group),
                            mimetype='text/plain')
    except DenormalizedBallot.DoesNotExist:
        return HttpResponse(content='DenormalizedBallot %s does not exist' %
                            str(request.POST['ballot']),
                            mimetype='text/plain')
Esempio n. 6
0
def sponsor_page(request, export=None):
    if request.GET.get('refresh'):
        for b in Ballot.objects.filter(ballot_type=Ballot.SBInitial.code):
            DenormalizedBallot.request_update(ballot_pk=b.number)
        for b in Ballot.objects.filter(ballot_type=Ballot.SBRecirc.code):
            DenormalizedBallot.request_update(ballot_pk=b.number)
        return http.HttpResponseRedirect(reverse('ballot.views.sponsor_page'))
    next_page=reverse('ballot.views.sponsor_page')
    if request.GET.get('redraw',None) is not None:
        try:
            redraw = int(request.GET.get('redraw',0))
        except ValueError:
            redraw = 0
        cc = CacheControl()
        if redraw==0:
            cc.open_ver = cc.open_ver + 1
        elif redraw==1:
            cc.closed_ver = cc.closed_ver + 1
        return http.HttpResponseRedirect(next_page)
    ballots = list(DenormalizedBallot.objects.filter(ballot_type=DenormalizedBallot.SBInitial.code))+list(DenormalizedBallot.objects.filter(ballot_type=DenormalizedBallot.SBRecirc.code))
    return ballot_page(request,ballots,export, sponsor=True, next=next_page, export_page='SponsorBallots')
Esempio n. 7
0
def ballot_page(request, ballots, export, sponsor, next, export_page):
    closed_ballots = []
    open_ballots = []
    needs_update = not DenormalizedBallot.backlog_poll().idle
    for b in ballots:
        if b.is_open:
            open_ballots.append(b)
        else:
            closed_ballots.append(b)
    if sponsor:
        open_ballots.sort(key=lambda x: x.closed, reverse=True)
        closed_ballots.sort(key=lambda x: x.closed, reverse=True)
    else:
        open_ballots.sort(key=lambda x: x.number, reverse=True)
        closed_ballots.sort(key=lambda x: x.number, reverse=True)
    context = dict(has_open=len(open_ballots)>0, open=open_ballots, \
                   closed=closed_ballots, next_page=next, export=export, \
                   sponsor=sponsor, needs_update=needs_update, \
                   export_page=reverse('ballot.views.main_page')+export_page)
    context_instance=RequestContext(request)
    context_instance['cache'].export = export
    if export:
        return export_html('ballot/ballots.html', context, context_instance=context_instance, filename='%s.%s'%(export_page,export))
    return render_to_response('ballot/ballots.html', context, context_instance=context_instance)
Esempio n. 8
0
def backlog_poll(request):
    stats = DenormalizedBallot.backlog_poll()
    return HttpResponse(
        content='{"backlog":%d, "count":%d}' %
        (stats.waiting + stats.active, DenormalizedBallot.objects.count()),
        mimetype='application/json')
Esempio n. 9
0
def backlog_worker(request):
    try:
        dn = DenormalizedBallot.denormalize(ballot_pk=request.POST['ballot'], commit=True)
        return HttpResponse(content='DenormalizedBallot %s'%(dn.task_group), mimetype='text/plain')
    except DenormalizedBallot.DoesNotExist:
        return HttpResponse(content='DenormalizedBallot %s does not exist'%str(request.POST['ballot']), mimetype='text/plain')
Esempio n. 10
0
def backlog_poll(request):
    stats = DenormalizedBallot.backlog_poll()
    return HttpResponse(content='{"backlog":%d, "count":%d}'%(stats.waiting+stats.active,DenormalizedBallot.objects.count()), mimetype='application/json')
Esempio n. 11
0
def refresh_ballots():
    logging.debug('refresh ballots')
    for ballot in Ballot.objects.all():
        DenormalizedBallot.request_update(ballot)
Esempio n. 12
0
def refresh_ballots():
    logging.debug('refresh ballots')
    for ballot in Ballot.objects.all():
        DenormalizedBallot.request_update(ballot)