Esempio n. 1
0
def sendVotingCards():
    electionId = request.json["election"]

    try:
        voteSvc = VoteService(electionId)  # prepare voteService
        voteSvc.sendVotingCards()
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        # update election status
        voteSvc.updateStatus(3)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})
Esempio n. 2
0
def setUpElection():
    data = request.json
    electionId = data["election"]
    numberOfVoters = json.loads(data["numberOfVoters"])
    candidates = data["candidates"]
    countingCircles = json.loads(data["countingCircles"])
    numberOfSelections = data["numberOfSelections"]
    numberOfCandidates = data["numberOfCandidates"]
    titles = data["titles"]

    try:
        # validate vote parameters
        if len(candidates) != sum(numberOfCandidates):
            raise RuntimeError(
                "The numberOfCandidates must match the number of candidates")
        if numberOfVoters != len(countingCircles):
            raise RuntimeError(
                "The length of countingCircles must match the number of voters"
            )
        if len(numberOfSelections) != len(numberOfCandidates):
            raise RuntimeError(
                "The length of numberOfSelections must match the length of numberOfCandidates"
            )

        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.setupElection(numberOfVoters, countingCircles, candidates,
                              numberOfCandidates, numberOfSelections, titles)

        #patches = voteSvc.getJSONPatches()
        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        # update election status
        voteSvc.updateStatus(1)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'result': 'success'})
Esempio n. 3
0
def startMixingPhase():
    data = request.json
    electionId = data["election"]
    try:
        # prepare voteService
        voteSvc = VoteService(electionId)

        # perform action
        voteSvc.startMixing()

        # retrieve and persist modified state
        patches = voteSvc.persist()
        syncPatches(electionId, SyncType.ROOM, patches)

        voteSvc.updateStatus(4)
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        return make_error(500, '%s:%s: %s' % (fname, exc_tb.tb_lineno, e))

    return json.dumps({'id': str(id)})