Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cart #9

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion books/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
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')
}
4 changes: 3 additions & 1 deletion books/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import path
from .views import book_list, book_details, author_books, book_list_cat
from .views import book_list, book_details, author_books, book_list_cat, \
book_search

app_name = 'books'

Expand All @@ -9,4 +10,5 @@
path('<slug:slug>/', book_details, name='book_details'),
path('author/<slug:slug>/', author_books, name='author_books'),
# path('category/<slug:slug>/', author_books, name='category_books'),
path('search/', book_search, name='search_books'),
]
18 changes: 17 additions & 1 deletion books/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from django.shortcuts import render, get_object_or_404
from .models import Author, Category, Product
from django.db.models import Q

# Create your views here.


def book_list(request):
# query with custom model manager product
books = Product.products_available.all()
search_post = request.GET.get('search')
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(description__icontains=search_post)
)
else:
books = Product.products_available.all()

context = {
'books': books
Expand Down Expand Up @@ -53,3 +65,7 @@ def categorywise_list(request, slug):
}

return context


def book_search(request):
pass
27 changes: 14 additions & 13 deletions bookstore/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
},
Expand All @@ -69,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
Expand Down
1 change: 0 additions & 1 deletion cart/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@


def cart(request):
print('from cart context processor!!!!!!!!!!!!!')
return {'basket': CartManager(request)}
6 changes: 3 additions & 3 deletions cart/templates/cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ <h2 id="total_price" class="mb-5">Summary</h2>

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);
}
})
Expand Down
26 changes: 26 additions & 0 deletions static/css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
:root {
--radiant-blue: #1cbfff;
}


body{
/* margin: 0; */
/* padding: 0; */
/* display: flex; */
/* justify-content: center; */
/* align-items: center; */
/* min-height: 100vh; */
color: var(--radiant-blue);
font-family: 'Jost', sans-serif;
background: linear-gradient(to bottom, #0f0c29, #302b63, #24243e);
}

h2 {
margin: 0 auto;
font-weight: bold;
font-size: 70px;
}

.login-form {
/* border: 2px solid red; */
}
21 changes: 17 additions & 4 deletions templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>


{% comment %} books dorpdown {% endcomment %}
<li class="nav-item dropdown dropdown-cat">
<a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Categories</a>
<ul class="dropdown-menu dropdown-menu-cat" aria-labelledby="navbarScrollingDropdown">
Expand All @@ -26,14 +27,26 @@
{% endfor %}
</ul>
</li>
{% comment %} authors dropdown {% endcomment %}
<li class="nav-item dropdown dropdown-cat">
<a class="nav-link dropdown-toggle" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Authors</a>
<ul class="dropdown-menu dropdown-menu-cat" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="{% url 'books:all_books' %}">All Books</a></li>
<li><hr class="dropdown-divider"></li>
{% for author in authors %}
<li><a class="dropdown-item" href="">{{ author.name|title }}</a></li>
{% endfor %}
</ul>
</li>

<li class="nav-item">
<a class="nav-link">Disabled</a>
</li>

</ul>
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
{% comment %} search field {% endcomment %}
<form class="d-flex" role="search" action="{% url 'books:all_books' %}">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name="search" >
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
Expand All @@ -60,7 +73,7 @@
<div class="mr-4">

<div class="nav-item dropdown me-5 pe-3">
<a class="nav-link dropdown-toggle text-white" href="#" id="navbarScrollingDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">Hello, {{ user.username|title }}</a>
<a class="nav-link dropdown-toggle text-white" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Hello, {{ user.username|title }}</a>
<ul class="dropdown-menu" aria-labelledby="navbarScrollingDropdown">
<li><a class="dropdown-item" href="{% url 'users:logout_user' %}">Logout</a></li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Meta:

class LoginForm(forms.ModelForm):
class Meta:
username = forms.CharField(widget=forms.Textarea())
model = User
fields = [
"username",
Expand Down
13 changes: 9 additions & 4 deletions users/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

{% block title %}Login{% endblock %}
{% block content %}
{% load static %}

<link rel="stylesheet" href="{% static 'css/login.css' %}" type="text/css">


<section class="vh-100">
<div class="d-flex">
<div class="justify-content-center align-item-center">
<h2>LogIn</h2>
<form method="post" class="ligin-form">
<form method="post" class="login-form d-flex flex-column">
{% csrf_token %}
{% for f in form %}
<div class="mb-5">
<div class="mb-5 mt-3">
{{ f.label_tag }}<br>
{{f.field.value}}
{{f}} <br>
{{ f.field.value }}
{{ f }}<br>
</div>
{% endfor %}
<button type="submit" class="btn btn-success btn-lg mb-1">LogIn</button>
Expand Down
19 changes: 10 additions & 9 deletions users/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ <h2 class="m-5">Sign up</h2>
<form method="post" class="signup-form mx-1 mx-md-4">
{% csrf_token %}
{% for field in user_form %}
<p class="">
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
<p class="form-label mb-3">
{{ field.label_tag }}<br>
{{ field }}
{% if field.help_text %}
<br>
<small style="color: grey">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
<button type="submit" class="btn btn-success btn-lg mb-1">Sign up</button>
Expand Down
2 changes: 1 addition & 1 deletion users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down