def saveGame(team_one,team_two,date,time,location): game = Game() game.team_one = team_one game.team_two = team_two game.game_date = date game.game_time = time game.location = location num = datetime.datetime.strptime(date, "%Y-%m-%d") game.weeknum = str(num.isocalendar()[0])+str(num.isocalendar()[1]) game.week_index = num.weekday() game.save() return True
def populate_challenges(self): challenge = Challenge() challenge.title = "Dummiest Challenge created ever" challenge.start_time = timezone.now() challenge.end_time = timezone.now() + timedelta(days=1) challenge.registration_start_time = challenge.start_time challenge.registration_end_time = challenge.end_time challenge.registration_open = True challenge.team_size = 3 challenge.entrance_price = 1000 game = Game() game.name = "AIC Game 2018" game.save() challenge.game = game challenge.save()
def create(self, *args, **kwargs): heat = kwargs.get("heat") previous_game = heat.latest_game skip = [w.snake.id for w in heat.winners] print(skip) if previous_game is not None: skip.append(previous_game.winner.snake.id) next_snakes = [s for s in previous_game.snakes if s.id not in skip] else: next_snakes = heat.snakes snake_ids = [{"id": snake.id} for snake in next_snakes] from apps.game.models import Game game = Game(width=20, height=20, food=10, snakes=snake_ids) game.create() game.save() return super(HeatGameManager, self).create(*args, **kwargs, game=game)
def post(self, request): post_data = self.DATA valid_data = True session_user = request.user test_user = User.objects.get(id=1) session_user = test_user if not session_user.is_authenticated(): response = Response(403, {'statusCode': 403, 'message' : 'Not authorized'}) return self.render(response) name_list = post_data.getlist('name', None) # Title of the game type_list = post_data.getlist('type', None) # Game's type (game_type:slug) description_list = post_data.getlist('description', None) # some info cloned_list = post_data.getlist('cloned', None) # cloned game's slug authors_list = post_data.getlist('authors', None) # usernames of the game creators (array) # game title title = None if name_list and len(name_list): title = name_list[0] # description description = None if description_list and len(description_list): description = description_list[0] # game type type_slug = None if type_list and len(type_list): type_slug = type_list[0] try: type_slug = GameType.objects.get(slug=type_slug) except GameType.DoesNotExist: valid_data = False # cloned cloned_slug = None if cloned_list and len(cloned_list): cloned_slug = cloned_list[0] try: print cloned_slug cloned_slug = Game.objects.get(slug=cloned_slug) except Game.DoesNotExist: valid_data = False if valid_data: try: slug = slugify(title) cloned = None if cloned_slug: cloned = cloned_slug.id instance = Game(title=title, slug=slug, type=type_slug, description=description, cloned=cloned) instance.save() # handle authors if authors_list and len(authors_list): for author in authors_list: try: author_user = User.objects.get(username=author) author_instance = Author(user=author_user, game=instance) author_instance.save() except User.DoesNotExist: pass response=Response(200,{'statusCode' : 200 }) return self.render(response) except (ValueError, IntegrityError) as e: pass response=Response(400,{'message':'Invalid data'}) return self.render(response)