From 49febaa59bb48ffb75a41af82b4bf55cdabdf4d3 Mon Sep 17 00:00:00 2001 From: biplob14 Date: Tue, 18 Jul 2023 18:22:07 +0600 Subject: [PATCH 1/3] feat: author list on nvabar --- books/context_processors.py | 7 ++++++- books/views.py | 2 -- bookstore/settings.py | 1 + cart/context_processors.py | 1 - cart/templates/cart.html | 6 +++--- templates/navbar.html | 16 ++++++++++++++-- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/books/context_processors.py b/books/context_processors.py index 2de5442..48b09d5 100644 --- a/books/context_processors.py +++ b/books/context_processors.py @@ -1,7 +1,12 @@ -from .models import Category +from .models import Category, Author def category_list(request): return { "categories": Category.objects.all().order_by('name') } + +def author_list(request): + return { + "authors": Author.objects.all().order_by('name').values('name') + } diff --git a/books/views.py b/books/views.py index 17b53e0..43f1e8d 100644 --- a/books/views.py +++ b/books/views.py @@ -31,7 +31,6 @@ def book_details(request, slug): } return render(request, 'book_details.html', context) - def author_books(request, slug): author_object = get_object_or_404(Author, slug_field=slug) books = Product.objects.filter(author=author_object, in_stock=True) @@ -42,7 +41,6 @@ def author_books(request, slug): } return render(request, 'author.html', context) - def categorywise_list(request, slug): category_object = get_object_or_404(Category, slug=slug) books = Product.objects.filter(category=category_object, in_stock=True) diff --git a/bookstore/settings.py b/bookstore/settings.py index 842ad3b..c8985b7 100644 --- a/bookstore/settings.py +++ b/bookstore/settings.py @@ -57,6 +57,7 @@ 'django.contrib.messages.context_processors.messages', # context processor which will allow all templates to get these values 'books.context_processors.category_list', + 'books.context_processors.author_list', 'cart.context_processors.cart', ], }, diff --git a/cart/context_processors.py b/cart/context_processors.py index 1541e42..b33866b 100644 --- a/cart/context_processors.py +++ b/cart/context_processors.py @@ -2,5 +2,4 @@ def cart(request): - print('from cart context processor!!!!!!!!!!!!!') return {'basket': CartManager(request)} diff --git a/cart/templates/cart.html b/cart/templates/cart.html index 47156b8..a0eecb4 100644 --- a/cart/templates/cart.html +++ b/cart/templates/cart.html @@ -140,9 +140,9 @@

Summary

total = (parseFloat(json.subtotal) + 11.50).toFixed(2); console.log(json) - document.getElementById("basket-qty").innerHTML = json.qty; - document.getElementById("item-subtotal-"+prod_id).innerHTML = json.item_total; - document.getElementById("subtotal-amount").innerHTML = json.cart_total; + document.getElementById("basket-qty").innerHTML = json.qty + " BDT"; + document.getElementById("item-subtotal-"+prod_id).innerHTML = json.item_total + " BDT"; + document.getElementById("subtotal-amount").innerHTML = json.cart_total + " BDT"; console.log(prod_id); } }) diff --git a/templates/navbar.html b/templates/navbar.html index 77e9f91..c436aee 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -15,7 +15,8 @@ - + + {% comment %} books dorpdown {% endcomment %} + {% comment %} authors dropdown {% endcomment %} + - diff --git a/users/forms.py b/users/forms.py index a58fd4e..bf42b1d 100644 --- a/users/forms.py +++ b/users/forms.py @@ -22,6 +22,7 @@ class Meta: class LoginForm(forms.ModelForm): class Meta: + username = forms.CharField(widget=forms.Textarea()) model = User fields = [ "username", diff --git a/users/templates/login.html b/users/templates/login.html index d4aa1fc..1381753 100644 --- a/users/templates/login.html +++ b/users/templates/login.html @@ -2,17 +2,22 @@ {% block title %}Login{% endblock %} {% block content %} +{% load static %} + + + +

LogIn

-
+ {% csrf_token %} {% for f in form %} -
+
{{ f.label_tag }}
- {{f.field.value}} - {{f}}
+ {{ f.field.value }} + {{ f }}
{% endfor %} diff --git a/users/templates/signup.html b/users/templates/signup.html index 56499ab..8a31414 100644 --- a/users/templates/signup.html +++ b/users/templates/signup.html @@ -11,15 +11,16 @@

Sign up

{% csrf_token %} {% for field in user_form %} -

- {{ field.label_tag }}
- {{ field }} - {% if field.help_text %} - {{ field.help_text }} - {% endif %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} +

+ {{ field.label_tag }}
+ {{ field }} + {% if field.help_text %} +
+ {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %}

{% endfor %} diff --git a/users/views.py b/users/views.py index b6f2119..df51d05 100644 --- a/users/views.py +++ b/users/views.py @@ -30,7 +30,7 @@ def user_registration(request): def login_user(request): - form = form = AuthenticationForm(request, data=request.POST) + form = AuthenticationForm(request, data=request.POST) if request.method == "POST": if form.is_valid(): username = form.cleaned_data.get('username') From 552ceaa2b62a3420701ae0fe3b94c2ebe27cc5e5 Mon Sep 17 00:00:00 2001 From: biplob14 Date: Tue, 24 Oct 2023 01:22:33 +0600 Subject: [PATCH 3/3] rebase: falake indentation --- books/context_processors.py | 1 + books/views.py | 13 ++++++++----- bookstore/settings.py | 26 +++++++++++++------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/books/context_processors.py b/books/context_processors.py index 48b09d5..2c3fd80 100644 --- a/books/context_processors.py +++ b/books/context_processors.py @@ -6,6 +6,7 @@ def category_list(request): "categories": Category.objects.all().order_by('name') } + def author_list(request): return { "authors": Author.objects.all().order_by('name').values('name') diff --git a/books/views.py b/books/views.py index d019dae..7e6cd87 100644 --- a/books/views.py +++ b/books/views.py @@ -11,10 +11,10 @@ def book_list(request): print("search values: ", search_post) if search_post: books = Product.products_available.filter( - Q(author__name__icontains=search_post) | \ - Q(title__icontains=search_post) | \ - Q(category__name__icontains=search_post) | \ - Q(publisher__name__icontains=search_post) | \ + Q(author__name__icontains=search_post) | + Q(title__icontains=search_post) | + Q(category__name__icontains=search_post) | + Q(publisher__name__icontains=search_post) | Q(description__icontains=search_post) ) else: @@ -43,6 +43,7 @@ def book_details(request, slug): } return render(request, 'book_details.html', context) + def author_books(request, slug): author_object = get_object_or_404(Author, slug_field=slug) books = Product.objects.filter(author=author_object, in_stock=True) @@ -53,6 +54,7 @@ def author_books(request, slug): } return render(request, 'author.html', context) + def categorywise_list(request, slug): category_object = get_object_or_404(Category, slug=slug) books = Product.objects.filter(category=category_object, in_stock=True) @@ -64,5 +66,6 @@ def categorywise_list(request, slug): return context + def book_search(request): - pass \ No newline at end of file + pass diff --git a/bookstore/settings.py b/bookstore/settings.py index c8985b7..3bd7027 100644 --- a/bookstore/settings.py +++ b/bookstore/settings.py @@ -70,24 +70,24 @@ # Database # https://docs.djangoproject.com/en/4.1/ref/settings/#databases -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.sqlite3', -# 'NAME': BASE_DIR / 'db.sqlite3', -# } -# } - DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'postgres', - 'USER': 'postgres', - 'PASSWORD': 'postgres', - 'HOST': 'db', - 'PORT': 5432 + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', } } +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.postgresql', +# 'NAME': 'postgres', +# 'USER': 'postgres', +# 'PASSWORD': 'postgres', +# 'HOST': 'db', +# 'PORT': 5432 +# } +# } + # Password validation # https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators