def edit(request, id): img = ProfileImage.objects.all().filter(user=id).first().image fav_games, fav_consoles = find_fav(id) account = get_object_or_404(User, pk=id) image = ProfileImage.objects.all().filter(user=id).first() if request.method == 'POST': form = EditAccountForm(data=request.POST, instance=account) img_form = EditImageForm(data=request.POST, instance=image) if form.is_valid() and img_form.is_valid(): account = form.save() img = img_form.save() profile_image = ProfileImage(image=request.POST['image'], user=account) profile_image.save() return redirect('account-id-index', id=id) else: form = EditAccountForm(instance=account) img_form = EditImageForm(instance=image) context = { 'account': account, 'fav_games': fav_games, 'fav_consoles': fav_consoles, 'form': form, 'id': id, 'img_form': img_form, 'profile_image': img } return renderTemplate(request, 'account/edit.html', context)
def index(request): if 'search_filter' in request.GET: user_id = request.user.id if user_id != None: search_history(user_id, request.GET['hidden'], request.GET['search_filter']) if 'prod_id' in request.GET: add_favorite(user_id, request.GET['hidden'], request.GET['prod_id']) info = Consoles.objects.exclude(description=' ') if 'sort_by' in request.GET: sort_by = request.GET['sort_by'] info = sort_items(sort_by, info) if 'check' in request.GET: consoleCat = request.GET['check'] info = filter_by_category(consoleCat, info) if 'on_sale' in request.GET: sale = request.GET['on_sale'] info = info.filter(onSale=sale) info = info.filter(name__icontains=request.GET['search_filter']) consoles = [{ 'id': x.id, 'name': x.name, 'price': x.price, 'description': x.description, 'first_image': x.consoleimage_set.first().image } for x in info] return JsonResponse({'data': consoles}) context = { 'consoles': Consoles.objects.all(), 'categories': ConsoleCategory.objects.all(), 'on_sale': {'On Sale'} } return renderTemplate(request, 'consoles/index.html', context)
def success(request): # Sækja í localStorage # Setja í DB # Tæma localStorage request_data = u'{}'.format(request.body) decoded_data = urllib.parse.unquote(request_data) cart_index = decoded_data.find("cart") cart_str = decoded_data[cart_index+5:-1] cart = json.loads(cart_str) user_id = request.user.id # býr til nýtt order user = User.objects.get(id=user_id) order = Order(user_id=user) order.save() for item in cart: order_item = OrderItems() order_item.order = order ids = item["product_id"].split("_") _type = ids[0] _id = ids[1] if _type == "game": game = Games.objects.get(id=_id) order_item.game_id = game else: console = Consoles.objects.get(id=_id) order_item.console_id = console amount = item["amount"] order_item.amount = amount order_item.save() return renderTemplate(request, 'cart/success.html')
def register(request): if request.method == 'POST': form = RegistrationForm(data=request.POST) #image = ProfileImage.objects.all().filter(user=id).first() if form.is_valid(): user = form.save() profile_image = ProfileImage(image=request.POST['image'], user=user) profile_image.save() username = form.cleaned_data.get('username') messages.success(request, f"New account created: {username}") #ProfileImage.img_form = EditImageForm(data=request.POST, instance=image) return redirect('login') else: for msg in form.error_messages: messages.error(request, f"{msg}: {form.error_messages[msg]}") return renderTemplate(request, "user/register.html", {"form": form}) form = RegistrationForm return renderTemplate(request, 'user/register.html', {'form': form})
def checkout_card(request): if request.method == 'POST': form = CheckoutCardForm(data=request.POST) # if form.is_valid(): return redirect('confirmation-index') form = CheckoutCardForm() return renderTemplate(request, 'cart/checkout_payment.html', { 'form': form })
def index(request): if 'search_filter' in request.GET: search_filter = request.GET['search_filter'] products = [ { 'id': x.id, 'name': x.name, 'description': x.description # 'firstImage':x.gameimage_set.first().image } for x in Games.objects.filter(name__icontains=search_filter) ] return JsonResponse({'data': products}) return renderTemplate(request, 'search/search.html')
def checkout_address(request): address = Location.objects.filter(user=request.user).first() if request.method == 'POST': form = CheckoutAddressForm(instance=address, data=request.POST) if form.is_valid(): address = form.save(commit=False) address.user = request.user address.save() return redirect('checkout-card') form = CheckoutAddressForm(instance=address) return renderTemplate(request, 'cart/checkout.html', { 'form': form })
def get_account_id(request, id): img = ProfileImage.objects.all().filter(user=id).first().image fav_games, fav_consoles = find_fav(id) game_history, console_history = get_search_history(id) context = { 'account': get_object_or_404(User, pk=id), 'game': Games.objects.all(), 'fav_games': fav_games, 'fav_consoles': fav_consoles, 'game_history': game_history, 'console_history': console_history, 'profile_image': img } return renderTemplate(request, 'account/index.html', context)
def index(request): if 'search_filter' in request.GET: user_id = request.user.id if user_id != None: search_history(user_id, request.GET['hidden'], request.GET['search_filter']) if 'prod_id' in request.GET: add_favorite(user_id, request.GET['hidden'], request.GET['prod_id']) info = Games.objects.all() if 'sort_by' in request.GET: sort_by = request.GET['sort_by'] info = sort_items(sort_by, info) if 'check' in request.GET: consoles = request.GET['check'] if consoles != "": for id in consoles.split(','): info = info.filter(console_id=int(id)) if 'type' in request.GET: typeCat = request.GET['type'] info = filter_by_category(typeCat, info) if 'on_sale' in request.GET: sale = request.GET['on_sale'] if sale == 'True': info = info.filter(onSale=sale) info = info.exclude(description=' ') info = info.filter(name__icontains=request.GET['search_filter']) games = [{ 'id': x.id, 'name': x.name, 'price': x.price, 'description': x.description, 'first_image': x.gameimage_set.first().image } for x in info] return JsonResponse({'data': games}) context = {'indi_games': Games.objects.exclude(description=' '), 'games': Games.objects.all(), 'consoles': ConsoleCategory.objects.all(), 'current_user_id': request.user.id, 'on_sale': {'On Sale'}, 'types': GameCategory.objects.all()} return renderTemplate(request, 'games/index.html', context)
def get_console_by_id(request, id): return renderTemplate(request, 'consoles/console_details.html', {'console': get_object_or_404(Consoles, pk=id)})
def index(request): consoles = Consoles.objects.filter(onSale=True) games = Games.objects.filter(onSale=True) games = games.exclude(description=' ') context = {'consoles': consoles, 'games': games} return renderTemplate(request, 'sales/index.html', context)
def get_game_by_id(request, id): return renderTemplate(request, 'games/game_details.html', { 'game': get_object_or_404(Games, pk=id) })
def confirmation(request): return renderTemplate(request, 'cart/confirm.html')
def index(request): return renderTemplate(request, 'cart/index.html')
def index(request): return renderTemplate(request, 'account/login.html')
def index(request): return renderTemplate(request, 'about_us/index.html')