def add_voter(): try: if (request.args.get('fetch_user') == "true"): data = request.get_json() voter_list = voters.get_all_voters() voter_list = [ x for x in voter_list if (x.firstName == data.get("firstName") and x.lastName == data.get("lastName") and x.ssn == data.get("ssn") and x.birthdate == datetime.date( *[int(num) for num in data['birthdate'].split("-")])) ] if len(voter_list) > 1: abort(500, "There was an internal issue: csp500") elif len(voter_list) < 1: abort(400, "Voter has not yet registered.") else: voter = voter_list[0] return jsonify({ "status": "registered", "voter_id": voter.id, "firstName": voter.firstName, "lastName": voter.lastName, "birthdate": voter.birthdate }) else: data = Voter.make_voter(request.get_json()) data = voters.add_voter(data) response = jsonify({ "status": "registered", "voter_id": data.id, "firstName": data.firstName, "lastName": data.lastName, "birthdate": data.birthdate }) print("Added new Voter: ", response) return response except ValueError as ex: abort(400, ex) except RuleErrors.RuleException as ex: abort(403, ex) except SecurityErrors.SecurityException as ex: abort(401, ex)
def get_voters_who_voted(self): return [Voter.make_voter(voter) for voter in self.voters.values() if Voter.make_voter(voter).has_voted is True]
def get_voter(self, voter_id: uuid.UUID): if str(voter_id) in self.voters: return Voter.make_voter(self.voters[str(voter_id)]) return None
def get_all_voters(self): return [Voter.make_voter(voter) for voter in self.voters.values()]