def __init__(self, electionId, fromBallotId, toBallotId): fromBallot = Ballot.get_all(ballotId=fromBallotId, electionId=electionId) toBallot = Ballot.get_all(ballotId=toBallotId, electionId=electionId) if len(fromBallot) is 0: raise NotFoundException("Ballot not found (ballotId=%s)" % fromBallotId) else: fromBallot = fromBallot[0] if len(toBallot) is 0: raise NotFoundException("Ballot not found (ballotId=%s)" % toBallotId) else: toBallot = toBallot[0] stationary_item = StationaryItem.create( electionId=electionId, stationaryItemType=StationaryItemTypeEnum.Ballot) super(BallotBookModel, self).__init__( fromBallotStationaryItemId=fromBallot.stationaryItemId, toBallotStationaryItemId=toBallot.stationaryItemId, stationaryItemId=stationary_item.stationaryItemId) db.session.add(self) db.session.flush()
def get_all(ballotId=None, ballotType=None, electionId=None): result = Ballot.get_all( ballotId=ballotId, ballotType=ballotType, electionId=electionId ) return Schema(many=True).dump(result).data
def create(body): request_body = RequestBody(body) result = Ballot.create(electionId=request_body.get("electionId"), ballotId=request_body.get("ballotId"), ballotType=get_ballot_type( request_body.get("ballotType"))) db.session.commit() return Schema().dump(result).data, 201
def get_all(ballotId=None): result = Ballot.get_all(ballotId=ballotId) return Schema(many=True).dump(result).data
def create(body): request_body = RequestBody(body) result = Ballot.create(electionId=request_body.get("electionId"), ballotId=request_body.get("ballotId")) return Schema().dump(result).data, 201