def status(): attendee = get_attendee(request) if not request.args.get('StaffQuery') and not attendee.first_use: attendee.first_use = time.time() attendee.save() PuzzleBucket.init(attendee) return attendee.to_json()
def deliver_puzzle(attendee, deliverer=None): try: puzzle_bucket = PuzzleBucket.objects( public_token=attendee.public_token).get() except DoesNotExist: puzzle_bucket = PuzzleBucket.init(attendee) if deliverer is not None: if deliverer in puzzle_bucket.deliverer: raise Error('Already take from this deliverer') else: puzzle_bucket.deliverer.append(deliverer) total = PuzzleStatus.objects(puzzle='total').get().quantity for i in range(len(puzzle_config)): puzzle = list(puzzle_config.keys())[randint(0, len(puzzle_config) - 1)] if i == len(puzzle_config) - 1 or total == 0 or PuzzleStatus.objects( puzzle=puzzle).get().currency / total < puzzle_rate[puzzle]: puzzle_bucket.puzzle.append(puzzle) PuzzleStatus.objects(puzzle='total').update_one(inc__quantity=1, inc__currency=1) PuzzleStatus.objects(puzzle=puzzle).update_one(inc__quantity=1, inc__currency=1) break puzzle_bucket.save()