def add_order(request, game_id, order_type): player = get_player(request, game_id) # Retrieve OrderClass try: SubOrder = get_order_by_name(order_type) except ValueError: raise Http404("This is not an Order.") instance = SubOrder(player=player) if request.method == 'POST': form = instance.get_form(request.POST) if form.is_valid(): form.save() return redirect('website.views.orders.orders', game_id=game_id) else: form = instance.get_form() order = { "game": player.game, "title": instance.title, "name": SubOrder.__name__, "form": form } return render(request, 'game/add_order.html', { "game": player.game, "order": order })
def delete_order(request, game_id, order_id): player = get_player(request, game_id) order = get_object_or_404(Order, pk=order_id, player=player) order.delete() return redirect('website.views.orders.orders', game_id=game_id)
def add_order(request, game_id, order_type): player = get_player(request, game_id) # Retrieve OrderClass try: SubOrder = get_order_by_name(order_type) except ValueError: raise Http404("This is not an Order.") instance = SubOrder(player=player) if request.method == 'POST': form = instance.get_form(request.POST) if form.is_valid(): form.save() return redirect('website.views.orders.orders', game_id=game_id) else: form = instance.get_form() order = { "game": player.game, "title": instance.title, "name": SubOrder.__name__, "form": form } return render(request, 'game/add_order.html', {"game": player.game, "order": order})
def delete_order(request, game_id, order_id): player = get_player(request, game_id) order = get_object_or_404(Order, pk=order_id, player=player) if not order.cancellable: raise Http404("Cet ordre n'est pas annulable") order.delete() return redirect('website.views.orders.orders', game_id=game_id)
def orders(request, game_id): player = get_player(request, game_id) existing_orders = [order.to_child() for order in player.order_set.filter(turn=player.game.current_turn)] existing_orders_cost = sum(o.cost for o in existing_orders) available_orders = get_orders_availability(player) return render(request, 'game/orders.html', { "game": player.game, "available_orders": available_orders, "existing_orders": existing_orders, "existing_orders_cost": existing_orders_cost, "remaining_money": player.money - existing_orders_cost, })
def orders(request, game_id): player = get_player(request, game_id) existing_orders = [ order.to_child() for order in player.order_set.filter(turn=player.game.current_turn) ] existing_orders_cost = sum(o.cost for o in existing_orders) available_orders = get_orders_availability(player) return render( request, 'game/orders.html', { "game": player.game, "available_orders": available_orders, "existing_orders": existing_orders, "existing_orders_cost": existing_orders_cost, "remaining_money": player.money - existing_orders_cost, })
def add_order(request, game_id, order_type): player = get_player(request, game_id) # Retrieve OrderClass try: SubOrder = get_order_by_name(order_type) except ValueError: raise Http404("This is not an Order.") instance = SubOrder(player=player) if request.method == 'POST': form = instance.get_form(request.POST) if form.is_valid(): form.save() return redirect('website.views.orders.orders', game_id=game_id) else: form = instance.get_form() path = '%s/data/order_description/%s.md' % (settings.BASE_DIR, SubOrder.__name__) order = { "game": player.game, "title": instance.title, "info": mark_safe(read_markdown_nullable(path)), "name": SubOrder.__name__, "form": form, } return django_render(request, 'game/add_order.html', { "game": player.game, "player": player, "order": order, "pods": ['d_inc', 'current_player', 'players', ], "request": request, "turn": player.game.current_turn, })
def wrap(request, game_id, **kwargs): player = get_player(request, game_id) game = player.game return func(request, game=game, player=player, **kwargs)