Пример #1
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
Пример #2
0
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 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")
Пример #4
0
def one_election_stats(request, election):
  user = get_user(request)
  admin_p = security.user_can_admin_election(user, election) or user.superadmin_p

  stats_data = {'stats': {'election': list(reports.election_report([election]))[0],
                          'votes': list(reports.election_votes_report([election],
                                                                 False))}}

  if request.GET.get('json', None):
    def handler(obj):
      if hasattr(obj, 'isoformat'):
        return obj.isoformat()
      raise TypeError

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

  return render_template(request, "election_stats", {
      'election': election,
      'admin_p': admin_p,
      'user': user,
      'menu_active': 'stats',
      'STATS_UPDATE_INTERVAL': getattr(settings, 'HELIOS_STATS_UPDATE_INTERVAL',
                                      2000)
  })
Пример #5
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
Пример #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 public_stats(request, election):
    stats = {}
    stats['election'] = list(reports.election_report([election], True, True))
    stats['votes'] = list(reports.election_votes_report([election], True, True))
    stats['results'] = list(reports.election_results_report([election]))

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

    return HttpResponse(json.dumps(stats, default=handler),
                        mimetype="application/json")
Пример #8
0
def public_stats(request, election):
    stats = {}
    stats['election'] = list(reports.election_report([election], True, True))
    stats['votes'] = list(reports.election_votes_report([election], True, True))
    stats['results'] = list(reports.election_results_report([election]))

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

    return HttpResponse(json.dumps(stats, default=handler),
                        content_type="application/json")
Пример #9
0
def one_election_public_stats(request, election_uuid):
  election = Election.objects.get(uuid=election_uuid, is_completed=True)

  stats = {}
  stats['election'] = list(reports.election_report([election], True, True))
  stats['votes'] = list(reports.election_votes_report([election], True, True))
  stats['results'] = list(reports.election_results_report([election]))

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

  return HttpResponse(jsonlib.dumps(stats, default=handler),
                      mimetype="application/json")
Пример #10
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)
Пример #11
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')
Пример #12
0
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")