예제 #1
0
파일: election.py 프로젝트: gchatzip/zeus
def report(request, election, format):
    reports_list = request.GET.get('report',
                                   'election,voters,votes,results').split(",")

    _reports = OrderedDict()
    if 'election' in reports_list:
        _reports['election'] = list(reports.election_report([election],
                                                            True, False))
    if 'voters' in reports_list:
        _reports['voters'] = list(reports.election_voters_report([election]))
    if 'votes' in reports_list:
        _reports['votes'] = list(reports.election_votes_report([election],
                                                               True, True))
    if 'results' in reports_list:
        _reports['results'] = list(reports.election_results_report([election]))

    if format == "html":
        return render_template(request, "election_report", {
            'election': election,
            'reports': _reports,
        })
    else:
        def handler(obj):
            if hasattr(obj, 'isoformat'):
                return obj.isoformat()
            raise TypeError

        return HttpResponse(json.dumps(_reports, default=handler),
                            mimetype="application/json")
예제 #2
0
파일: election.py 프로젝트: teloniusz/zeus
def report(request, election, format):
    reports_list = request.GET.get('report',
                                   'election,voters,votes,results').split(",")

    _reports = OrderedDict()
    if 'election' in reports_list:
        _reports['election'] = list(
            reports.election_report([election], True, False))
    if 'voters' in reports_list:
        _reports['voters'] = list(reports.election_voters_report([election]))
    if 'votes' in reports_list:
        _reports['votes'] = list(
            reports.election_votes_report([election], True, True))
    if 'results' in reports_list:
        _reports['results'] = list(reports.election_results_report([election]))

    if format == "html":
        return render_template(request, "election_report", {
            'election': election,
            'reports': _reports,
        })
    else:

        def handler(obj):
            if hasattr(obj, 'isoformat'):
                return obj.isoformat()
            raise TypeError

        return HttpResponse(json.dumps(_reports, default=handler),
                            content_type="application/json")
예제 #3
0
def election_reports(election):
    data = {}
    data['election'] = list(reports.election_report([election], True, True))[0]
    data['votes'] = list(reports.election_votes_report([election], True, True))[0]
    data['voters'] = list(reports.election_voters_report([election]))[0]
    data['results'] = list(reports.election_results_report([election]))[0]
    return data
예제 #4
0
def election_reports(election):
    data = {}
    data['election'] = list(reports.election_report([election], True, True))[0]
    data['votes'] = list(reports.election_votes_report([election], True, True))[0]
    data['voters'] = list(reports.election_voters_report([election]))[0]
    data['results'] = list(reports.election_results_report([election]))[0]
    return data
예제 #5
0
    def handle(self, *args, **options):
      elections = Election.objects.filter(uuid__in=args)
      for e in args:

        _reports = OrderedDict()
        _reports['election'] = list(reports.election_report(elections))
        _reports['voters'] = list(reports.election_voters_report(elections))
        _reports['votes'] = list(reports.election_votes_report(elections,
                                                               False))

        json.dump(_reports, sys.stdout, default=json_handler, ensure_ascii=False,
                 indent=4)
예제 #6
0
    def handle(self, *args, **options):
        elections = Election.objects.filter(uuid__in=args)
        for e in args:

            _reports = OrderedDict()
            _reports['election'] = list(reports.election_report(elections))
            _reports['voters'] = list(
                reports.election_voters_report(elections))
            _reports['votes'] = list(
                reports.election_votes_report(elections, False))

            json.dump(_reports,
                      sys.stdout,
                      default=json_handler,
                      ensure_ascii=False,
                      indent=4)
예제 #7
0
def election_report(request, election, format="html"):

  user = get_user(request)
  if not user.superadmin_p:
    raise PermissionDenied('12')

  reports_list = request.GET.get('report', 'election,voters,votes,results').split(",")

  _reports = OrderedDict()
  if 'election' in reports_list:
    _reports['election'] = list(reports.election_report([election], True, False))
  if 'voters' in reports_list:
    _reports['voters'] = list(reports.election_voters_report([election]))
  if 'votes' in reports_list:
    _reports['votes'] = list(reports.election_votes_report([election], True,
                                                           True))
  if 'results' in reports_list:
    _reports['results'] = list(reports.election_results_report([election]))

  if format == "html":
    return render_template(request, "election_report", {
        'election': election,
        'reports': _reports,
    })

  if format == "json":
    def handler(obj):
      if hasattr(obj, 'isoformat'):
        return obj.isoformat()
      raise TypeError

    return HttpResponse(jsonlib.dumps(_reports, default=handler),
                        mimetype="application/json")

  if format == "csv":
    pass

  raise PermissionDenied('13')
예제 #8
0
파일: election.py 프로젝트: grnet/zeus
def report(request, election, format="json"):
    reports_list = request.GET.get('report',
                                   'election,voters,votes,results').split(",")

    _reports = OrderedDict()
    if 'election' in reports_list:
        _reports['election'] = list(reports.election_report([election],
                                                            True, False))
    if 'voters' in reports_list:
        _reports['voters'] = list(reports.election_voters_report([election]))
    if 'votes' in reports_list:
        _reports['votes'] = list(reports.election_votes_report([election],
                                                               True, True))
    if 'results' in reports_list:
        _reports['results'] = list(reports.election_results_report([election]))

    def handler(obj):
        if hasattr(obj, 'isoformat'):
            return obj.isoformat()
        raise TypeError

    return HttpResponse(json.dumps(_reports, default=handler, indent=4),
                        content_type="application/json")