def description(request, game_id): game = get_object_or_404(Game, pk=game_id) context = {} # If game not available if not (game.available): if (request.user.is_authenticated and (Collection.isUserOwning(user=request.user, game=game) or game.owner == request.user)): context['extra_message'] = "Game is not in sale anymore." else: return render(request, '404.html') # if game available or already bought if (request.user.is_authenticated): # If user have bought the game if (Collection.isUserOwning(user=request.user, game=game)): owned = True # User is developer and owns the game elif (game.owner == request.user): owned = True # User is developer but not owner elif (request.user.groups.all()[0].name == 'Developer'): owned = -1 else: owned = False in_cart = Cart.isItemInCart(request.user, game) else: owned = None in_cart = False game.priceTag = decimalToPriceTag(game.price) categories = game.category.all() context['game'] = game context[ 'owned'] = owned # True if player and bought or owner. False if not bought. -1 if other developer. context[ 'in_cart'] = in_cart # Shows if the game is already added to the cart context['categories'] = categories # All categories of the game return render(request, "game/description.html", context)
def play_view(request, id): context = {} if request.user.is_authenticated: game = get_object_or_404( Game, pk=id) ##from the model find the id corresponding game if (Collection.isUserOwning(request.user, game)): context['game'] = game return render(request, "game/play.html", context) if request.user == game.owner: #develop has the game.owenership so they can play the game context['game'] = game return render(request, "game/play.html", context) return render(request, "403.html")