def getPollDetails(poll_id): try: user = users.get_current_user() user_id = user.user_id() poll = Poll.get_by_id(poll_id) if poll is not None: result = { "poll_id": poll_id, "title": poll.title, "description": poll.description, "ownerID": poll.ownerID, "status":poll.status, "type": poll.type, "date_added": poll.date_added.strftime('%m/%d/%Y'), "user_vote": getUserVoteInPoll(user_id, poll_id), "photoURL": poll.photoURL } else: result = {"error": "No poll found with that Id"} except LookupError as e: result = {"error": "There has been an error %s"%e } except AttributeError as e: result = {"error": "There is no logged in user. Kindly ensure the user is logged in before retrying"} return result
def getPollsUserVoted(user_id): try: votes = Vote.query(Vote.voter == user_id).fetch() user_polls = list() if votes: for vote in votes: poll_vote = Poll.get_by_id(int(vote.poll)) user_polls.append({"poll_id": poll_vote.key.id(), "title": poll_vote.title, "description": poll_vote.description, "user_vote": getUserVoteInPoll(user_id, poll_vote.key.id()) }) return {"user_id": user_id, "voted_polls": user_polls} else: return {"error": "No Polls have been created by user yet"} except LookupError as e: return {"error": "There has been an error: %s"%e} except AttributeError as e: return {"error": "There has been an error: %s"%e}