def get(self, match_id): registered_people = memcache.get(match_id, "match_players") if not registered_people: match = Match.getone(match_id) if match is None: raise MatchNotExistsError registered_people = [] for ple in match.registerdPeople: player = ple.get() play = Play.getbyMatchPeople(match_id, player.key.id()) registered_people.append({ "name": player.name, "id": player.key.id(), "playId": play.key.id(), "signupTime": play.signupTime, "signinTime": play.signinTime, "admin": player.admin, "team": play.team or None, "leave": play.leave, "signupMissing": play.signupMissing, "signinOntime": True if play.signinTime and play.signinTime <= match.signinLatest else False, "signinLate": True if play.signinTime and play.signinTime > match.signinLatest else False, "finePaid": 0 if play.finePaid is None else play.finePaid }) memcache.set(match_id, registered_people, namespace="match_players") else: logging.debug("get match players from memcache") return {"people": registered_people}
def status(cls, match_id, status): match = Match.getone(match_id) logging.debug("Set status to {}".format(status)) if match: match.status = status match.put() memcache.flush_all() return True
def manualSignin(cls, match_id, people_id): match = Match.getone(match_id) match.signin(people_id) play = Play.getbyMatchPeople(match_id, people_id) play.signinTime = match.signinLatest play.put() memcache.flush_all() return {"status": True}
def get(self, match_id, people_id): match = Match.getone(match_id) if match is None: raise MatchNotExistsError people = People.getone(people_id) if people.key in match.registerdPeople: return {"in": True} else: return {"in": False}
def post(self, match_id): logging.debug("SignMeUP") args = signup_parser.parse_args() code = args.get('code') status = MatchHelper.signup(match_id, code) if status: match = Match.getone(match_id) match.__setattr__('id', match_id) return {"match": match} return {"match": None}
def post(self): logging.debug("creating match") args = parser.parse_args() match_details = args match = Match.create(args.get('startTime'), args.get('finishTime'), args.get('signinEarliest'), args.get('signinLatest'), args.get('location')) match_details['id'] = match.id() memcache.flush_all() return {'match': match_details}
def post(self): logging.debug("creating play") args = parser.parse_args() play = Play.create(args.get('peopleId'), args.get('matchId')) play_details = args play_details['id'] = play.id() match = Match.getone(args.get('matchId')) match.register(args.get('peopleId')) logging.debug(match) return {'play': play_details}
def get(self): import datetime as levelone_datetime import calendar days_till_sunday = 6 - datetime.utcnow().weekday() this_sunday = datetime.utcnow() + levelone_datetime.timedelta(days=days_till_sunday) this_sunday_start = this_sunday.replace(hour=5, minute=00, second=00) logging.debug("creating match from cron {}".format(this_sunday_start)) match = Match.create(this_sunday_start, this_sunday_start + levelone_datetime.timedelta(hours=2), this_sunday_start - levelone_datetime.timedelta(minutes=30), this_sunday_start - levelone_datetime.timedelta(minutes=5), "Ted Howard Reserve - 11 Renown Rd, Baulkham Hills") match_id = match.id() memcache.flush_all() return {'match_id': match_id}
def signup(cls, match_id, code): match = Match.getone(match_id) people = People.getone(current_user.key_id) if people and people.key in match.registerdPeople: logging.debug("You have already signed up") return True if match and code == match.signupCode: logging.debug("Sign up user {}".format(current_user.key_id)) match.signup(current_user.key_id) Play.create(current_user.key_id, match_id) memcache.flush_all() return True return False
def askforleave(cls, match_id, status): match = Match.getone(match_id) people = People.getone(current_user.key_id) if people and people.key in match.registerdPeople: logging.debug("You have already signed up! Now switch leave") play = Play.getbyMatchPeople(match_id, current_user.key_id) if play: play.leave = status play.put() elif people and people.key: match.signup(current_user.key_id) Play.create(current_user.key_id, match_id, leave=status) memcache.flush_all() return True
def get(self, match_id): match_dict = memcache.get(match_id, "match") if not match_dict: match = Match.getone(match_id) match_dict = match.to_dict() match_dict['id'] = match_id match_dict['signinLink'] = "http://{}/match-signin/{}/{}".format(host_url, match_id, match.signinCode) match_dict['signupLink'] = "http://{}/match-signup/{}/{}".format(host_url, match_id, match.signupCode) match_dict['signupCode'] = match.signupCode memcache.set(match_id, match_dict, namespace="match") else: logging.debug("get match info from memcache {}") return {"match": match_dict}
def signin(cls, match_id, code): match = Match.getone(match_id) if datetime.now() < match.signinEarliest: logging.debug("You are too early for sign in") return {"status": False, "reason": "You are too early for sign in", "code": -1} if datetime.now() > match.signinLatest: logging.debug("You are too late for sign in") logging.debug("Sign in user {}".format(current_user.key_id)) match.signin(current_user.key_id) play = Play.getbyMatchPeople(match_id, current_user.key_id) if play is None: logging.debug("this guy didn't sign up, but is sign-in now") match.signup(current_user.key_id) Play.create(current_user.key_id, match_id, missing=True) else: play.signinTime = datetime.now() play.put() memcache.flush_all() return {"status": False, "reason": "You are too late for sign in", "code": 1} people = People.getone(current_user.key_id) if people and people.key in match.participatedPeople: logging.debug("You have already signed in") return {"status": False, "reason": "You have already signed in", "code": 0} if match and code == match.signinCode: logging.debug("Sign in user {}".format(current_user.key_id)) match.signin(current_user.key_id) play = Play.getbyMatchPeople(match_id, current_user.key_id) if play is None: logging.debug("this guy didn't sign up, but is sign-in now") match.signup(current_user.key_id) Play.create(current_user.key_id, match_id, missing=True) else: play.signinTime = datetime.now() play.put() memcache.flush_all() return {"status": True} return {"status": False}
def get(self): matches = Match.getall() matches_json = [] for match in matches: plays = Play.getbyMatch(match.key.id()) leaves = 0 ontimes = 0 for play in plays: if play.leave: leaves += 1 if play.signinTime and play.signinTime <= match.signinLatest: ontimes += 1 matches_json.append({ "id": match.key.id(), "start": match.startTime, "leave": leaves, "ontime": ontimes, "signup": len(match.registerdPeople) }) return {"matches": matches_json}
def get(self): matches_json = memcache.get("matches") if not matches_json: matches = Match.getall() matches_json = [] for match in matches: plays = Play.getbyMatch(match.key.id()) leaves = [play for play in plays if play.leave] matches_json.append({ "id": match.key.id(), "location": match.location, "startTime": match.startTime, "finishTime": match.finishTime, "signinEarliest": match.signinEarliest, "signinLatest": match.signinLatest, "createdTime": match.createdTime, "noleaves": len(leaves), "nosignups": len(match.registerdPeople), "status": match.status }) memcache.set("matches", matches_json) else: logging.debug("get matches from memcache") return {'matches': matches_json}
def comment(cls, match_id, comment): match = Match.getone(match_id) match.comment = comment match.put() return {"status": True}