def get_all(election_id=None, area_name=None, associated_area_id=None, area_type=None):
    election = Election.get_by_id(electionId=election_id)

    if associated_area_id is not None and area_type is not None:
        associated_area = get_by_id(areaId=associated_area_id)
        query = get_associated_areas_query(area=associated_area, areaType=area_type, electionId=election_id)
    else:
        query = Model.query

    if area_name is not None:
        query = query.filter(Model.areaName.like(area_name))

    if election is not None:
        query = query.filter(
            or_(
                Model.electionId.in_(election.mappedElectionIds),
                Model.electionId.in_(election.subElectionIds)
            )
        )

    if area_type is not None:
        query = query.filter(Model.areaType == area_type)

    query = query.order_by(Model.areaId)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 2
0
def get_all(electionId=None, officeId=None, tallySheetCode=None):
    query = Model.query.join(
        Submission.Model,
        Submission.Model.submissionId == Model.tallySheetId
    ).join(
        Election.Model,
        Election.Model.electionId == Submission.Model.electionId
    )

    if electionId is not None:
        query = query.filter(
            or_(
                Election.Model.electionId == electionId,
                Election.Model.parentElectionId == electionId
            )
        )

    if officeId is not None:
        query = query.filter(Submission.Model.areaId == officeId)

    if tallySheetCode is not None:
        query = query.filter(Model.tallySheetCode == get_tally_sheet_code(tallySheetCode))

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 3
0
def get_all(electionId=None,
            issuingOfficeId=None,
            receivingOfficeId=None,
            issuedBy=None,
            issuedTo=None):
    query = Model.query.filter(Model.delete == False)

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if issuingOfficeId is not None:
        query = query.filter(Model.issuingOfficeId == issuingOfficeId)

    if receivingOfficeId is not None:
        query = query.filter(Model.receivingOfficeId == receivingOfficeId)

    if issuedBy is not None:
        query = query.filter(Model.issuedBy == issuedBy)

    if issuedTo is not None:
        query = query.filter(Model.issuedTo == issuedTo)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 4
0
def get_all(election_id=None,
            area_name=None,
            associated_area_id=None,
            area_type=None):
    if associated_area_id is not None and area_type is not None:
        associated_area = get_by_id(areaId=associated_area_id)
        query = get_associated_areas_query(area=associated_area,
                                           areaType=area_type,
                                           electionId=election_id)
    else:
        query = Model.query

    if area_name is not None:
        query = query.filter(Model.areaName.like(area_name))

    # if election_id is not None:
    #     query = query.filter(
    #         or_(
    #             Election.Model.electionId == election_id,
    #             Election.Model.parentElectionId == election_id
    #         )
    #     )

    if area_type is not None:
        query = query.filter(Model.areaType == area_type)

    query = query.order_by(Model.areaId)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 5
0
def get_all(electionId=None, officeId=None, tallySheetCode=None):
    election = Election.get_by_id(electionId=electionId)

    query = Model.query.join(
        Submission.Model,
        Submission.Model.submissionId == Model.tallySheetId).join(
            Election.Model,
            Election.Model.electionId == Submission.Model.electionId)

    if electionId is not None:
        query = query.filter(
            Election.Model.electionId.in_(election.mappedElectionIds))

    if officeId is not None:
        query = query.filter(Submission.Model.areaId == officeId)

    if tallySheetCode is not None:
        query = query.filter(
            Model.tallySheetCode == get_tally_sheet_code(tallySheetCode))

    # Filter by authorized areas
    user_access_area_ids: Set[int] = get_user_access_area_ids()
    query = query.filter(Submission.Model.areaId.in_(user_access_area_ids))

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 6
0
def get_all(ballotBoxId=None):
    query = Model.query
    if ballotBoxId is not None:
        query = query.filter(Model.ballotBoxId.like(ballotBoxId))

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 7
0
def get_all():
    query = Model.query.filter(
        Model.parentElectionId == None
    )

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 8
0
def get_all(ballotId=None, ballotType=None, electionId=None):
    result = Ballot.get_all(ballotId=ballotId,
                            ballotType=ballotType,
                            electionId=electionId)

    result = get_paginated_query(result).all()

    return Schema(many=True).dump(result).data
def getAll(electionId=None, areaId=None, tallySheetCode=None):
    result = TallySheet.get_all(electionId=electionId,
                                areaId=areaId,
                                tallySheetCode=tallySheetCode)

    result = get_paginated_query(result).all()

    return TallySheetSchema(many=True).dump(result).data
Ejemplo n.º 10
0
def get_all(submissionId, submissionCode=None):
    query = Model.query.filter(Model.submissionId == submissionId)

    if submissionCode is not None:
        query = query.filter(Model.submissionCode == submissionCode)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 11
0
def get_all(tallySheetId, tallySheetCode=None):
    query = Model.query.filter(Model.tallySheetId == tallySheetId)

    if tallySheetCode is not None:
        query = query.filter(Model.tallySheetCode == tallySheetCode)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 12
0
def get_all(electionId=None,
            areaId=None,
            tallySheetCode=None,
            voteType=None,
            partyId=None,
            limit=None,
            offset=None):
    # Filter by authorized areas
    user_access_area_ids: Set[int] = get_user_access_area_ids()

    query_args = [Model]
    query_filters = [
        Submission.Model.areaId.in_(user_access_area_ids),
        Template.Model.templateId == Model.templateId,
        Submission.Model.submissionId == Model.tallySheetId,
        Election.Model.electionId == Submission.Model.electionId
    ]
    query_group_by = [Model.tallySheetId]

    if areaId is not None:
        query_filters.append(Submission.Model.areaId == areaId)

    if electionId is not None:
        election = Election.get_by_id(electionId=electionId)
        query_filters.append(
            Election.Model.electionId.in_(
                election.get_this_and_below_election_ids()))

    if tallySheetCode is not None:
        query_filters.append(Template.Model.templateName == tallySheetCode)

    if voteType is not None:
        query_filters.append(Election.Model.voteType == voteType)

    if partyId is not None:
        query_filters += [
            MetaData.Model.metaId == Model.metaId,
            MetaData.Model.metaDataKey == "partyId",
            MetaData.Model.metaDataValue == partyId
        ]

    tally_sheet_list = db.session.query(*query_args).filter(
        *query_filters).group_by(*query_group_by).order_by(Model.tallySheetId)

    tally_sheet_list = get_paginated_query(query=tally_sheet_list,
                                           limit=limit,
                                           offset=offset)

    authorized_tally_sheet_list = []
    for tally_sheet in tally_sheet_list:
        if has_role_based_access(election=tally_sheet.submission.election,
                                 tally_sheet_code=tally_sheet.tallySheetCode,
                                 access_type=WORKFLOW_ACTION_TYPE_VIEW):
            authorized_tally_sheet_list.append(tally_sheet)

    return authorized_tally_sheet_list
Ejemplo n.º 13
0
def get_all(ballotId=None):
    query = Model.query
    # if ballotId is not None:
    #     query = query.filter(
    #         Model.ballotId.like(ballotId)
    #     )

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 14
0
def get_all(tallySheetId):
    tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId)
    if tallySheet is None:
        raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" %
                                tallySheetId)

    result = TallySheetVersion.get_all(tallySheetId=tallySheetId)

    result = get_paginated_query(result).all()

    return TallySheetVersion_CE_201_PV_Schema(many=True).dump(result).data
def get_all(electionId=None, electorateName=None, parentElectorateId=None, electorateType=None):
    result = Electorate.get_all(
        electionId=electionId,
        electorateName=electorateName,
        parentElectorateId=parentElectorateId,
        electorateType=electorateType
    )

    result = get_paginated_query(result).all()

    return Schema(many=True).dump(result).data
Ejemplo n.º 16
0
def get_all(electionId=None, categoryDescription=None):
    query = Model.query

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if categoryDescription is not None:
        query = query.filter(Model.categoryDescription == categoryDescription)

    result = get_paginated_query(query).all()

    return result
def get_all(electionId=None, officeId=None):
    query = Model.query

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if officeId is not None:
        query = query.filter(Model.officeId == officeId)

    result = get_paginated_query(query).all()

    return result
def get_all(electionId=None,
            officeName=None,
            parentOfficeId=None,
            officeType=None):
    result = Office.get_all(electionId=electionId,
                            officeName=officeName,
                            parentOfficeId=parentOfficeId,
                            officeType=officeType)

    result = get_paginated_query(result).all()

    return Schema(many=True).dump(result).data
Ejemplo n.º 19
0
def get_all(electionId=None,
            areaName=None,
            associatedAreaId=None,
            areaType=None):
    query = Area.get_all(election_id=electionId,
                         area_name=areaName,
                         associated_area_id=associatedAreaId,
                         area_type=get_area_type(area_type=areaType))
    query = get_paginated_query(query)
    result = query.all()

    return AreaSchema(many=True).dump(result).data
Ejemplo n.º 20
0
def get_all(tallySheetId):
    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_all(tallySheetId=tallySheetId)

    result = get_paginated_query(result).all()

    return TallySheetVersion_CE_201_PV_Schema(many=True).dump(result).data
Ejemplo n.º 21
0
def get_all(electionId=None, candidateId=None):
    query = Model.query

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if candidateId is not None:
        query = query.filter(Model.candidateId == candidateId)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 22
0
def get_all(ballotBoxId=None, electionId=None):
    query = Model.query
    if ballotBoxId is not None:
        query = query.filter(Model.ballotBoxId.like(ballotBoxId))

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    query = query.order_by(cast(Model.ballotBoxId, Integer))

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 23
0
def get_all(electionId=None,
            issuingOfficeId=None,
            receivingOfficeId=None,
            issuedBy=None,
            issuedTo=None):
    result = Model.get_all(electionId=electionId,
                           issuingOfficeId=issuingOfficeId,
                           receivingOfficeId=receivingOfficeId,
                           issuedBy=issuedBy,
                           issuedTo=issuedTo)

    result = get_paginated_query(result).all()

    return Schema(many=True).dump(result).data
Ejemplo n.º 24
0
def get_all(electionId=None, areaId=None, reportCode=None):
    query = Model.query

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if areaId is not None:
        query = query.filter(Model.areaId == areaId)

    if reportCode is not None:
        query = query.filter(Model.reportCode == get_report_code(reportCode))

    result = get_paginated_query(query).all()

    return result
def get_all(invoiceId=None,
            stationaryItemId=None,
            received=None,
            receivedFrom=None,
            receivedBy=None,
            receivedOffice=None):
    result = InvoiceStationaryItem.get_all(invoiceId=invoiceId,
                                           stationaryItemId=stationaryItemId,
                                           received=received,
                                           receivedFrom=receivedFrom,
                                           receivedBy=receivedBy,
                                           receivedOffice=receivedOffice)

    result = get_paginated_query(result).all()

    return Schema(many=True).dump(result).data
Ejemplo n.º 26
0
def get_all(electionId=None,
            officeName=None,
            parentOfficeId=None,
            officeType=None):
    query = Model.query

    if officeName is not None:
        query = query.filter(Model.officeName.like(officeName))

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if officeType is not None:
        query = query.filter(Model.officeType == officeType)
    else:
        query = query.filter(Model.parentOfficeId == parentOfficeId)

    result = get_paginated_query(query).all()

    return result
Ejemplo n.º 27
0
def get_all(invoiceId=None, stationaryItemId=None, received=None, receivedFrom=None,
            receivedBy=None, receivedOffice=None):
    query = Model.query.filter(Model.delete == False)

    if invoiceId is not None:
        query = query.filter(Model.invoiceId == invoiceId)
    if stationaryItemId is not None:
        query = query.filter(Model.stationaryItemId == stationaryItemId)
    if received is not None:
        query = query.filter(Model.received == received)
    if receivedFrom is not None:
        query = query.filter(Model.receivedFrom == receivedFrom)
    if receivedBy is not None:
        query = query.filter(Model.receivedBy == receivedBy)
    if receivedOffice is not None:
        query = query.filter(Model.receivedOffice == receivedOffice)

    result = get_paginated_query(query).all()

    return result
def get_all(ballotId=None,
            stationaryItemId=None,
            electionId=None,
            ballotType=None):
    query = Model.query
    if ballotId is not None:
        query = query.filter(Model.ballotId.like(ballotId))

    if stationaryItemId is not None:
        query = query.filter(Model.stationaryItemId == stationaryItemId)

    if ballotType is not None:
        query = query.filter(Model.ballotType == ballotType)

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    query = query.order_by(cast(Model.ballotId, Integer))

    result = get_paginated_query(query).all()
    return result
def get_all(electionId=None,
            officeName=None,
            parentOfficeId=None,
            officeType=None):
    query = Model.query.join(Area.AreaAreaModel,
                             Model.areaId == Area.AreaAreaModel.childAreaId,
                             isouter=True)

    if officeName is not None:
        query = query.filter(Model.officeName.like(officeName))

    if electionId is not None:
        query = query.filter(Model.electionId == electionId)

    if officeType is not None:
        query = query.filter(Model.officeType == officeType)

    if parentOfficeId is not None:
        query = query.filter(Area.AreaAreaModel.parentAreaId == parentOfficeId)

    result = get_paginated_query(query).all()

    return result
def get_all(tallySheetId):
    query = Model.query.filter(Model.tallySheetId == tallySheetId)

    result = get_paginated_query(query).all()

    return result