Example #1
0
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
    })
Example #2
0
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)
Example #3
0
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)
Example #4
0
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})
Example #5
0
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)
Example #6
0
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,
	})
Example #7
0
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,
        })
Example #8
0
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,
	})
Example #9
0
	def wrap(request, game_id, **kwargs):
		player = get_player(request, game_id)
		game = player.game

		return func(request, game=game, player=player, **kwargs)
Example #10
0
    def wrap(request, game_id, **kwargs):
        player = get_player(request, game_id)
        game = player.game

        return func(request, game=game, player=player, **kwargs)