From a99086b4acb0bdef6216266e0bc0fb8cb3678326 Mon Sep 17 00:00:00 2001 From: killewolf Date: Thu, 4 Feb 2021 18:43:54 +0530 Subject: [PATCH 1/4] few changes --- Pipfile | 1 + Pipfile.lock | 9 +- accounts/models.py | 16 +- book_seling/settings.py | 3 +- book_seling/urls.py | 7 +- books/urls.py | 25 +-- books/views.py | 11 +- orders/views.py | 4 +- static/js/api handling/component.js | 2 +- .../js/api handling/constructBookmarkPage.js | 8 +- static/js/main.js | 48 ++++++ templates/genresList.html | 150 +++++++----------- uwsgi.ini | 8 + 13 files changed, 148 insertions(+), 144 deletions(-) create mode 100644 static/js/main.js create mode 100644 uwsgi.ini diff --git a/Pipfile b/Pipfile index dec8868..6202070 100644 --- a/Pipfile +++ b/Pipfile @@ -20,6 +20,7 @@ daphne = "*" asgi-runserver = "*" uvloop = "*" httptools = "*" +uwsgi = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 8e2c29e..c0e0a20 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "1fa3831d2b5ce829ace7a82c274f8660cc6713c2c7af57cefd3c5b3438f0ee59" + "sha256": "35d2d20b6270dad89f1d66e8215e3b9518585e80f62f5cead1a06e473e30979a" }, "pipfile-spec": 6, "requires": { @@ -543,6 +543,13 @@ "index": "pypi", "version": "==0.14.0" }, + "uwsgi": { + "hashes": [ + "sha256:faa85e053c0b1be4d5585b0858d3a511d2cd10201802e8676060fd0a109e5869" + ], + "index": "pypi", + "version": "==2.0.19.1" + }, "vine": { "hashes": [ "sha256:4c9dceab6f76ed92105027c49c823800dd33cacce13bdedc5b914e3514b7fb30", diff --git a/accounts/models.py b/accounts/models.py index 0dbf02a..90b61e6 100755 --- a/accounts/models.py +++ b/accounts/models.py @@ -9,10 +9,11 @@ def auto_prof_create(sender, instance: User, created, **kwargs): if created: Profile.objects.create(user=instance) - subject = "ThankYou Registering" + subject = "Welcome to Bookstore 🤩🤩" - print(instance.email) - body = f"Hey {instance.first_name} Welcome to BookStore. " + body = f"Hey {instance.first_name} Welcome to Bookstore 🤩🤩 \n" \ + f"Bookstore is your best source to buy cheap book online, make " \ + f"online book purchase, making us the best book website in India to read book online" send_email_to_user.delay([instance.email], subject, body) @@ -61,12 +62,3 @@ class Meta: post_save.connect(auto_prof_create, sender=User) post_delete.connect(auto_user_delete, sender=Profile) - - -""" - -{'user': {'username': 'priyansh2001', 'first_name': 'Priyansh', 'last_name': 'Singh', 'password': 'Fiitjee13', 'fav_genres': ['Business', 'Crime Thriller', 'History', 'Pyschology', 'Self Help']}, 'address': '113 North City Pilibhit Road Bareilly', 'contact_number': '7618166335'} - -{'user': {'username': 'priyansh2001', 'first_name': 'Priyansh', 'last_name': 'Singh', 'password': 'Fiitjee13', 'fav_genres': ['Cooking', 'Historical Fiction', 'Physics']}, 'address': '113 North City Pilibhit Road Bareilly', 'contact_number': '7618166335'} - -""" \ No newline at end of file diff --git a/book_seling/settings.py b/book_seling/settings.py index 499246b..73fcfbd 100755 --- a/book_seling/settings.py +++ b/book_seling/settings.py @@ -33,7 +33,6 @@ INSTALLED_APPS = [ - 'asgi_runserver', 'django.contrib.admin', 'django.contrib.auth', @@ -52,7 +51,7 @@ 'orders' ] -ASGI_APPLICATION = 'book_seling.asgi.application' +# ASGI_APPLICATION = 'book_seling.asgi.application' LOGIN_URL = "/login" diff --git a/book_seling/urls.py b/book_seling/urls.py index da29ec4..69eaf9c 100755 --- a/book_seling/urls.py +++ b/book_seling/urls.py @@ -22,6 +22,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.urls import path, include +from django.views.decorators.cache import cache_page, cache_control from django.views.generic import TemplateView from .decorators import AnonymousRequired, CheckoutValidation @@ -52,7 +53,7 @@ ] urlpatterns += [ - path('login', AnonymousRequired(TemplateView.as_view(template_name='login.html'))), + path('login', (AnonymousRequired(TemplateView.as_view(template_name='login.html')))), path('signup', AnonymousRequired(TemplateView.as_view(template_name='signup.html'))), path('', TemplateView.as_view(template_name='index.html')), path('author/', TemplateView.as_view(template_name='author.html')), @@ -66,11 +67,9 @@ path('confirm-order', login_required(CheckoutValidation(TemplateView.as_view(template_name='confirmOrder.html')))), path('order-complete', login_required(TemplateView.as_view(template_name='orderComplete.html'))), path('your-orders', login_required(TemplateView.as_view(template_name='orders.html'))), + path('genre-list', TemplateView.as_view(template_name='genresList.html')) ] urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += staticfiles_urlpatterns() - -""" -""" diff --git a/books/urls.py b/books/urls.py index 467b318..cf39c40 100644 --- a/books/urls.py +++ b/books/urls.py @@ -1,35 +1,16 @@ -from asgiref.sync import sync_to_async from django.urls import path from . import views -# urlpatterns = [ -# path('books/all', views.BookListView.as_view()), -# path('authors/all', views.AuthorListView.as_view()), -# -# path('authors/', views.AuthorActionView.as_view()), -# # todo optimization -# path('books/recommended', views.GetRecommendedBooks.as_view()), -# path('books/best-sellers', views.BestSellerView.as_view()), -# path('authors/top', views.TopAuthors.as_view()), -# # todo optimization -# path('books/new', views.GetNewReleases.as_view()), -# path('books/popular', views.GetPopularBooks.as_view()), -# -# path('books//similar', views.SimilarBookView.as_view()), -# path('books/', views.BookActionView.as_view()), -# path('genre/', views.GenreRetrieveView.as_view()), -# ] - urlpatterns = [ - path('books/all', sync_to_async(views.BookListView.as_view())), + path('books/all', views.BookListView.as_view()), path('authors/all', views.AuthorListView.as_view()), path('authors/', views.AuthorActionView.as_view()), # todo optimization path('books/recommended', views.GetRecommendedBooks.as_view()), - path('books/best-sellers', sync_to_async(views.BestSellerView.as_view())), - path('authors/top', sync_to_async(views.TopAuthors.as_view())), + path('books/best-sellers', views.BestSellerView.as_view()), + path('authors/top', views.TopAuthors.as_view()), # todo optimization path('books/new', views.GetNewReleases.as_view()), path('books/popular', views.GetPopularBooks.as_view()), diff --git a/books/views.py b/books/views.py index 63e708c..5db9801 100755 --- a/books/views.py +++ b/books/views.py @@ -72,18 +72,19 @@ def get(self, request): fav_genres = user.fav_genres.all() data = Book.objects.filter(genre__in=fav_genres).order_by('-sold_quantity').filter( - all_deals__isnull=False).order_by('-rating')[:9] + all_deals__isnull=False).order_by('-rating').distinct()[:9] data = BookIconSerializer(data, many=True).data cache.set(f'{user.id}', data, 60 * 5) # cache timeout=5 min - + else: + print('in cache') return Response(data=data, status=status.HTTP_200_OK) class BestSellerView(ListAPIView): serializer_class = BookIconSerializer - queryset = Book.objects.order_by('-date_created').filter(all_deals__isnull=False).order_by('-rating')[:9] + queryset = Book.objects.order_by('-date_created').filter(all_deals__isnull=False).distinct().order_by('-rating')[:9] # @method_decorator(cache_page(60 * 60)) # def list(self, request, *args, **kwargs): @@ -129,7 +130,7 @@ def get_queryset(self): class GetNewReleases(ListAPIView): serializer_class = BookIconSerializer - queryset = Book.objects.order_by('-released_date')[:9] + queryset = Book.objects.filter(all_deals__isnull=False).distinct().order_by('-released_date')[:9] # @method_decorator(cache_page(60 * 15)) # def list(self, request, *args, **kwargs): @@ -139,7 +140,7 @@ class GetNewReleases(ListAPIView): class GetPopularBooks(ListAPIView): serializer_class = BookIconSerializer - queryset = Book.objects.all().order_by('-sold_quantity')[:9] + queryset = Book.objects.all().filter(all_deals__isnull=False).distinct().order_by('-sold_quantity')[:9] # @method_decorator(cache_page(60 * 15)) # def list(self, request, *args, **kwargs): diff --git a/orders/views.py b/orders/views.py index 7a67c7a..4255eee 100644 --- a/orders/views.py +++ b/orders/views.py @@ -187,7 +187,9 @@ def post(self, request): in_stock.select_for_update() if not in_stock.exists(): - return Response(status=status.HTTP_400_BAD_REQUEST) + return Response(data={ + 'message': 'Product went out of stock' + },status=status.HTTP_400_BAD_REQUEST) total_cost = in_stock.aggregate(total_amount=Sum(F('quantity') * F('deal__price')))['total_amount'] total_cost = total_cost - (total_cost * discount_percent // 100) diff --git a/static/js/api handling/component.js b/static/js/api handling/component.js index 9f10153..93b84cc 100644 --- a/static/js/api handling/component.js +++ b/static/js/api handling/component.js @@ -152,7 +152,7 @@ export function constructHomepageTopBar(genreNames) { Self Help Science Fiction Young Adult - More.. + More.. diff --git a/static/js/api handling/constructBookmarkPage.js b/static/js/api handling/constructBookmarkPage.js index 7d5ad04..867a277 100644 --- a/static/js/api handling/constructBookmarkPage.js +++ b/static/js/api handling/constructBookmarkPage.js @@ -10,9 +10,7 @@ function constructBookmarkedList(data) { console.log(data) var bookmarkedBooks = ''; for (let i = 0; i < data.length; i++) { - let obj = { - // sb deta yha nikallene, uske baad obj.variableName Niche Html me kr dena - } + bookmarkedBooks += `
@@ -29,7 +27,7 @@ function constructBookmarkedList(data) {
-