Example #1
0
def init_app():
    try:
        app.logger.debug("Adding users")
        load_users()

        app.logger.debug("Adding voters")
        for box in BOXES:
            app.logger.debug(f"Processing box: {box}")

            box_obj = Box.objects(number=box).first()
            if not box_obj:
                box_obj = Box(number=box)
                load_votes_matrix(box_obj)
            for i in range(1, 350 + 1):
                voter_obj = Voter.objects(order=i, box=box_obj).first()
                if not voter_obj:
                    circuit_obj = Circuit.objects(name=CIRCUIT).first()
                    if not circuit_obj:
                        circuit_obj = Circuit(name=CIRCUIT).save()
                    try:
                        Voter(
                            order=i,
                            box=box_obj,
                            circuit=circuit_obj,
                        ).save()
                    except mongoengine.errors.NotUniqueError:
                        continue
    except Exception:
        app.logger.exception("There was something wrong with init.")

    app.logger.debug("Done init")
Example #2
0
def save_state(order):
    app.logger.debug("Saving order: %s" % order)
    box = Box.objects(number=request.form.get("box")).first()
    voter = Voter.objects(order=order, box=box).first()
    voter.update(status=request.form.get("intencion"),
                 last_updated=datetime.now())
    return Response(status=200)
Example #3
0
def telegram():
    app.logger.debug("Entered telegram")
    _filter = get_current_user_roles(current_user)

    box = Box.objects(number__in=_filter).first()
    if box:
        return redirect(url_for('telegram_box', box_number=box.number))
    else:
        return redirect(url_for('padron'))
Example #4
0
def telegram_box(box_number):
    box_permission = Permission(RoleNeed(box_number))
    app.logger.debug("Entered telegram %s" % box_number)
    _roles = get_current_user_roles(current_user)

    boxes = Box.objects(number__in=_roles).order_by("number")
    pager = Pager(int(box_number), [int(box.number) for box in boxes])
    pages = pager.get_pages()
    if box_permission.can():
        box = Box.objects(number=box_number).first()
        if box:
            return render_template('telegram.html',
                                   parties=box.parties,
                                   other_votes=box.other_votes,
                                   pages=pages,
                                   box_number=box.number)
        else:
            flash("Mesa inexistente")
            return redirect(url_for('padron'))
    else:
        abort(403)
Example #5
0
def export():
    boxes = Box.objects()
    padron = []
    for box in boxes:
        voters = Voter.objects(box=box)
        for voter in voters:
            padron.append([
                voter.order,
                voter.status,
                box.number,
            ])
    return render_template(
        'export.html',
        padron=padron,
    )
Example #6
0
def summary():
    _filter = get_current_user_roles(current_user)

    boxes = Box.objects(number__in=_filter).order_by("-number")
    custom_boxes = []
    for box in boxes:
        custom_box = {
            'number': box.number,
            "recurrido": Voter.objects(box=box, status=2).count(),
            "voto": Voter.objects(box=box, status=3).count(),
            "ausentes": Voter.objects(box=box, status=4).count()
        }

        custom_boxes.append(custom_box)
    votos_recurrido = Voter.objects(status=2, box__in=boxes).count()
    votos_ns_nc = Voter.objects(status=3, box__in=boxes).count()
    votos_ausentes = Voter.objects(status=4, box__in=boxes).count()
    data = [
        {
            "intention": "Recurrido",
            "count": votos_recurrido
        },
        {
            "intention": "Voto",
            "count": votos_ns_nc
        },
        {
            "intention": "Ausentes",
            "count": votos_ausentes
        },
    ]
    values = [votos_recurrido, votos_ns_nc, votos_ausentes]
    labels = ["Recurrido", "Voto", "Ausentes"]

    return render_template(
        'summary.html',
        values=values,
        labels=labels,
        colors=COLORS,
        boxes=custom_boxes,
        data=data,
    )
Example #7
0
def padron_box(box_number):
    box_permission = Permission(RoleNeed(str(box_number)))
    app.logger.info("Entered Padron for box: %s" % box_number)
    _roles = get_current_user_roles(current_user)
    app.logger.debug("Roles: %s" % _roles)
    app.logger.debug("box_permission: %s" % box_permission)

    pager = Pager(int(box_number), [int(role) for role in _roles])
    pages = pager.get_pages()
    box = Box.objects(number=box_number).first()
    _padron = Voter.objects(box=box)
    if box_permission.can():
        return render_template(
            'padron.html',
            padron=_padron,
            pages=pages,
            box_number=box_number,
        )
    else:
        abort(403)
Example #8
0
def totales():
    candidates = [
        "president", "gobernor", "diputado", "senador", "intendente", "general"
    ]
    other_votes = ["blank", "nulled", "recurrent", "refuted"]
    app.logger.debug("Entered totales")
    _filter = get_current_user_roles(current_user)

    boxes = Box.objects(number__in=_filter)
    results = {}
    other_results = {}
    for box in boxes:
        for party in box.parties:
            if not results.get(party.name):
                results[party.name] = {}
            for candidate in candidates:
                if not results[party.name].get(candidate):
                    results[party.name][candidate] = {}
                results[party.name][candidate]["count"] = \
                    results[party.name][candidate].get("count", 0) + party.votes[candidate].count
                results[party.name][candidate]["enabled"] = party.votes[
                    candidate].enabled
        for vote_type in other_votes:
            if not other_results.get(vote_type):
                other_results[vote_type] = {}
            for candidate in candidates:
                if not other_results[vote_type].get(candidate):
                    other_results[vote_type][candidate] = {}
                other_results[vote_type][candidate]["count"] = \
                    other_results[vote_type][candidate].get("count", 0) + box.other_votes[vote_type][candidate].count
                other_results[vote_type][candidate][
                    "enabled"] = box.other_votes[vote_type][candidate].enabled

    if results:
        return render_template('totales.html',
                               results=results,
                               other_results=other_results)
    else:
        return redirect(url_for('padron'))
Example #9
0
def boxes():
    app.logger.info("Entered Mesas")
    boxes = Box.objects()
    return render_template('boxes.html', boxes=boxes)