def notify_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in notify_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id
        )
        response = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
            result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        url = "%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL,
            NOTIFY_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            # result_dissemination_result_type,
            response['result_code']
        )

        print("#### RESULT_DISSEMINATION_API - Notify #### ", [url, response])
        return requests.post(url, verify=False)
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be notified.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_NOTIFIED
        )
Пример #2
0
def release_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in release_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id)
        response, result_code = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
            result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        response['type'] = result_dissemination_result_type

        url = "%s/%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL, RELEASE_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            result_dissemination_result_type, result_code)

        print("#### RESULT_DISSEMINATION_API - Release #### ", [url, response])
        result = requests.post(url, verify=False, json=response)
        print(result.status_code, result.content)

        upload_proof_last_image(tally_sheet, tally_sheet_version)

        return result
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be released.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_RELEASED)
def submit(tallySheetId, body):
    request_body = RequestBody(body)
    tallySheetVersionId = request_body.get("submittedVersionId")

    tally_sheet: TallySheetModel = TallySheet.get_by_id(tallySheetId=tallySheetId)

    if tally_sheet is None:
        raise NotFoundException(
            message="Tally sheet not found (tallySheetId=%d)" % tallySheetId,
            code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND
        )

    if tally_sheet.tallySheetCode not in [TallySheetCodeEnum.PRE_41, TallySheetCodeEnum.CE_201,
                                          TallySheetCodeEnum.CE_201_PV, TallySheetCodeEnum.PRE_34_CO]:
        raise ForbiddenException(
            message="Submit operation is not supported for this tally sheet type.",
            code=MESSAGE_CODE_TALLY_SHEET_SUBMIT_IS_NOT_SUPPORTED
        )

    tally_sheet_version = TallySheetVersion.get_by_id(tallySheetVersionId=tallySheetVersionId,
                                                      tallySheetId=tallySheetId)

    if tally_sheet_version is None:
        raise NotFoundException(
            message="Tally sheet version not found (tallySheetVersionId=%d)" % tallySheetVersionId,
            code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND
        )

    tally_sheet.set_submitted_version(tally_sheet_version)

    if tally_sheet.tallySheetCode in [TallySheetCodeEnum.CE_201, TallySheetCodeEnum.CE_201_PV]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusCE201.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Submitted"

    if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_41]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusPRE41.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Submitted"

    if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_34_CO]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusPRE34.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Submitted"

    db.session.commit()

    return TallySheetSchema().dump(tally_sheet).data, 201
def get_by_id(tallySheetId, tallySheetVersionId):
    result = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId,
        tallySheetVersionId=tallySheetVersionId
    )

    return TallySheetVersionCE201Schema().dump(result).data
Пример #5
0
def get_by_id(tallySheetId, tallySheetVersionId):
    result = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId,
        tallySheetVersionId=tallySheetVersionId
    )

    return TallySheetVersion_PRE_ALL_ISLAND_RESULT_BY_ELECTORAL_DISTRICTS_Schema().dump(result).data
def lock(tallySheetId, body):
    request_body = RequestBody(body)
    tallySheetVersionId = request_body.get("lockedVersionId")

    tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId)

    if tally_sheet is None:
        raise NotFoundException("Tally sheet not found (tallySheetId=%d)" %
                                tallySheetId)

    tally_sheet_version = TallySheetVersion.get_by_id(
        tallySheetVersionId=tallySheetVersionId, tallySheetId=tallySheetId)

    if tally_sheet_version is None:
        raise NotFoundException(
            message="Tally sheet version not found (tallySheetVersionId=%d)" %
            tallySheetVersionId,
            code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND)

    if not tally_sheet_version.isComplete:
        raise NotFoundException(
            message="Incomplete tally sheet version (tallySheetVersionId=%d)" %
            tallySheetVersionId,
            code=
            MESSAGE_CODE_TALLY_SHEET_INCOMPLETE_TALLY_SHEET_CANNOT_BE_LOCKED)

    tally_sheet.set_locked_version(tally_sheet_version)

    if tally_sheet.tallySheetCode in [
            TallySheetCodeEnum.CE_201, TallySheetCodeEnum.CE_201_PV
    ]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusCE201.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Verified"

    if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_41]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusPRE41.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Verified"

    if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_34_CO]:
        election = tally_sheet.submission.election
        electionId = election.parentElectionId
        countingCentreId = tally_sheet.areaId
        results = StatusPRE34.get_status_records(electionId, countingCentreId)

        for item in results:
            item.status = "Verified"

    db.session.commit()

    return TallySheetSchema().dump(tally_sheet).data, 201
Пример #7
0
def html(tallySheetId, tallySheetVersionId):
    tallySheetVersion = TallySheetVersion.get_by_id(
        tallySheetVersionId=tallySheetVersionId)

    db.session.commit()

    return Response(tallySheetVersion.html(), mimetype='text/html')
Пример #8
0
def _cache_letter_pdf(user_access_area_ids, tally_sheet_id,
                      tally_sheet_version_id):
    tally_sheet = TallySheet.get_by_id(tallySheetId=tally_sheet_id)

    if tally_sheet is None:
        raise NotFoundException(
            message="Tally sheet not found (tallySheetId=%d)" % tally_sheet_id,
            code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND)

    tally_sheet_version = TallySheetVersion.get_by_id(
        tallySheetId=tally_sheet_id,
        tallySheetVersionId=tally_sheet_version_id)

    if tally_sheet_version is None:
        raise NotFoundException(
            message="Tally sheet version not found (tallySheetVersionId=%d)" %
            tally_sheet_version_id,
            code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND)

    file_response = FileApi.get_download_file(
        fileId=tally_sheet_version.get_exported_letter_pdf_file_id(
            tallySheetId=tally_sheet_id,
            tallySheetVersionId=tally_sheet_version_id))

    db.session.commit()

    return file_response
Пример #9
0
def get_by_id(tallySheetId, tallySheetVersionId):
    tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId)
    if tallySheet is None:
        raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" %
                                tallySheetId)

    result = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId)

    return TallySheetVersionPRE41Schema().dump(result).data
Пример #10
0
def get_by_id(tallySheetId, tallySheetVersionId):
    tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId)
    if tallySheet is None:
        raise NotFoundException(
            message="Tally sheet not found (tallySheetId=%d)" % tallySheetId,
            code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND)

    result = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId)

    return TallySheetVersionSchema().dump(result).data
Пример #11
0
    def get_extended_tally_sheet_version(self, tallySheetVersionId):
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=self.tallySheetId,
            tallySheetVersionId=tallySheetVersionId)
        extended_election = self.submission.election.get_extended_election()
        extended_tally_sheet_class = extended_election.get_extended_tally_sheet_class(
            self.template.templateName)
        extended_tally_sheet_version = extended_tally_sheet_class.ExtendedTallySheetVersion(
            tallySheet=self, tallySheetVersion=tally_sheet_version)

        return extended_tally_sheet_version
def html(tallySheetId, tallySheetVersionId):
    tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId)

    if tally_sheet is None:
        raise NotFoundException("Tally sheet not found (tallySheetId=%d)" %
                                tallySheetId)

    tally_sheet_version = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId)

    if tally_sheet_version is None:
        NotFoundException(
            "Tally sheet version not found (tallySheetVersionId=%d)" %
            tallySheetVersionId)

    return Response(tally_sheet_version.html(), mimetype='text/html')
Пример #13
0
def html(tallySheetId, tallySheetVersionId):
    tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId)

    if tally_sheet is None:
        raise NotFoundException(
            message="Tally sheet not found (tallySheetId=%d)" % tallySheetId,
            code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND)

    tally_sheet_version = TallySheetVersion.get_by_id(
        tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId)

    if tally_sheet_version is None:
        raise NotFoundException(
            message="Tally sheet version not found (tallySheetVersionId=%d)" %
            tallySheetVersionId,
            code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND)

    return Response(tally_sheet.html(tallySheetVersionId=tallySheetVersionId),
                    mimetype='text/html')
Пример #14
0
def notify_results(tally_sheet, tally_sheet_version_id):
    if tally_sheet.tallySheetCode in notify_allowed_tally_sheet_codes:
        tally_sheet_version = TallySheetVersion.get_by_id(
            tallySheetId=tally_sheet.tallySheetId,
            tallySheetVersionId=tally_sheet_version_id
        )
        response, result_code = tally_sheet_version.json_data()

        result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_VOTE
        # if tally_sheet.tallySheetCode in PREFERENCE_TALLY_SHEET_CODES:
        #     result_dissemination_result_type = RESULT_DISSEMINATION_SYSTEM_RESULT_TYPE_PREF

        response['type'] = result_dissemination_result_type

        url = "%s/%s/%s/%s/%s" % (
            RESULT_DISSEMINATION_SYSTEM_URL,
            NOTIFY_RESULTS_ENDPOINT,
            RESULT_DISSEMINATION_SYSTEM_ELECTION_CODE,
            result_dissemination_result_type,
            result_code
        )

        params = {
            "level": get_result_level(tally_sheet),
        }

        required_params_from_response = [PARAM_ED_NAME, PARAM_PD_NAME]
        for required_param in required_params_from_response:
            if required_param in response:
                params[required_param] = response[required_param]

        print("#### RESULT_DISSEMINATION_API - Notify #### ", [url, response, params])
        result = requests.post(url, verify=False, params=params)
        print(result.status_code, result.content)
        return result
    else:
        raise MethodNotAllowedException(
            message="Tally sheet is not allowed to be notified.",
            code=MESSAGE_CODE_TALLY_SHEET_NOT_ALLOWED_TO_BE_NOTIFIED
        )
def lock(tallySheetId, body):
    request_body = RequestBody(body)
    tallySheetVersionId = request_body.get("lockedVersionId")

    tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId)

    if tally_sheet is None:
        raise NotFoundException("Tally sheet not found (tallySheetId=%d)" %
                                tallySheetId)

    tally_sheet_version = TallySheetVersion.get_by_id(
        tallySheetVersionId=tallySheetVersionId, tallySheetId=tallySheetId)

    if tally_sheet_version is None:
        raise NotFoundException(
            "Tally sheet version not found (tallySheetVersionId=%d)" %
            tallySheetVersionId)

    tally_sheet.set_locked_version(tally_sheet_version)

    db.session.commit()

    return TallySheetSchema().dump(tally_sheet).data, 201