From b237270469f5a2a0fdfcbc739abab6c77f6ada5a Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Tue, 2 Aug 2022 12:29:08 +0530 Subject: [PATCH] feat[backend]: add django cleanup --- backend/settings.py | 3 +- emailverification/urls.py | 7 -- emailverification/views.py | 5 -- frontend/src/actions/cartActions.js | 134 ++++++++++++++-------------- requirements.txt | 3 + shop/views.py | 3 +- 6 files changed, 73 insertions(+), 82 deletions(-) diff --git a/backend/settings.py b/backend/settings.py index 89ac6f2..e7fbc71 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -40,8 +40,9 @@ 'gallery.apps.GalleryConfig', 'shop.apps.ShopConfig', 'about.apps.AboutConfig', - 'emailverification', + # 'emailverification', 'storages', + 'django_cleanup.apps.CleanupConfig', ] SITE_ID = 3 diff --git a/emailverification/urls.py b/emailverification/urls.py index 324ce9e..e77d1b4 100644 --- a/emailverification/urls.py +++ b/emailverification/urls.py @@ -1,21 +1,14 @@ from django.conf.urls import url, include -from allauth.account.views import ConfirmEmailView, LoginView from django.urls import path from . import views -from .views import FacebookLogin urlpatterns = [ # Override urls url(r'^registration/account-email-verification-sent/', views.null_view, name='account_email_verification_sent'), - path('login/', LoginView.as_view(), name='account_login'), - path('auth/registration/', LoginView.as_view(), name='account_signup'), - url(r'^registration/account-confirm-email/(?P[-:\w]+)/$', - ConfirmEmailView.as_view(), name='account_confirm_email'), url(r'^registration/complete/$', views.complete_view, name='account_confirm_complete'), url(r'^password-reset/confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.null_view, name='password_reset_confirm'), # Default urls - path('facebook/', FacebookLogin.as_view(), name='fb_login') ] diff --git a/emailverification/views.py b/emailverification/views.py index 6cf2eb5..6849a69 100644 --- a/emailverification/views.py +++ b/emailverification/views.py @@ -3,14 +3,9 @@ from rest_framework.decorators import api_view from rest_framework.response import Response -from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter from dj_rest_auth.registration.views import SocialLoginView -class FacebookLogin(SocialLoginView): - adapter_class = FacebookOAuth2Adapter - - @api_view() def null_view(request): return Response(status=status.HTTP_400_BAD_REQUEST) diff --git a/frontend/src/actions/cartActions.js b/frontend/src/actions/cartActions.js index a68c9f4..42bdf78 100644 --- a/frontend/src/actions/cartActions.js +++ b/frontend/src/actions/cartActions.js @@ -1,76 +1,74 @@ -import { authAxios } from '../utils' -import { orderSummaryURL, removeFromCartURL, addToCartURL } from '../constants'; +import { authAxios } from "../utils"; +import { orderSummaryURL, removeFromCartURL, addToCartURL } from "../constants"; -export const FETCH_CART = 'FETCH_CART'; -export const CART_START = 'CART_START'; -export const CART_FAIL = 'CART_FAIL'; -export const ERROR = 'ERROR'; -export const SUCCESS_MESSAGE = 'SUCCESS_MESSAGE'; -export const SIGN_IN_TO_ADD_ITEMS = 'SIGN_IN_TO_ADD_ITEMS' +export const FETCH_CART = "FETCH_CART"; +export const CART_START = "CART_START"; +export const CART_FAIL = "CART_FAIL"; +export const ERROR = "ERROR"; +export const SUCCESS_MESSAGE = "SUCCESS_MESSAGE"; +export const SIGN_IN_TO_ADD_ITEMS = "SIGN_IN_TO_ADD_ITEMS"; -export const signInToAddItems = dispatch => { - dispatch({ - type: SIGN_IN_TO_ADD_ITEMS, - payload: 'Sign In to add items to the cart' - }) -} - -export const fetchCart = (cb) => dispatch => { - authAxios.get(orderSummaryURL) - .then(res => { - dispatch({ - type: FETCH_CART, - payload: res.data - }) - if (typeof cb === "function") cb(); - }) - .catch(error => { - if (error.response !== undefined) { - console.log(error.response.data) - } +export const signInToAddItems = (dispatch) => { + dispatch({ + type: SIGN_IN_TO_ADD_ITEMS, + payload: "Sign In to add items to the cart", + }); +}; - console.log(error) - - dispatch({ - type: CART_FAIL, - }) - }) +export const fetchCart = (cb) => (dispatch) => { + authAxios + .get(orderSummaryURL) + .then((res) => { + dispatch({ + type: FETCH_CART, + payload: res.data, + }); + if (typeof cb === "function") cb(); + }) + .catch((error) => { + if (error.response !== undefined) { + console.log(error.response.data); + } -} + console.log(error.response); + dispatch({ + type: CART_FAIL, + }); + }); +}; -export const addToCart = (slug, cb) => dispatch => { - authAxios.post(addToCartURL, { - slug: slug +export const addToCart = (slug, cb) => (dispatch) => { + authAxios + .post(addToCartURL, { + slug: slug, }) - .then(res => { - fetchCart(); - dispatch({ - type: SUCCESS_MESSAGE, - payload: res.data.message - }) - cb(); - }) - .catch(error => { - if (error.response !== undefined) { - dispatch({ - type: ERROR, - payload: error.response.data.errormessage - }) - } - else console.log(error) - }) -} - - -export const removeCart = id => { - authAxios.delete(removeFromCartURL + `${id}/delete/`) - .then(res => { - console.log(res); - fetchCart(); - }) - .catch(err => { - console.log(err); - }) -} + .then((res) => { + fetchCart(); + dispatch({ + type: SUCCESS_MESSAGE, + payload: res.data.message, + }); + cb(); + }) + .catch((error) => { + if (error.response !== undefined) { + dispatch({ + type: ERROR, + payload: error.response.data.errormessage, + }); + } else console.log(error); + }); +}; +export const removeCart = (id) => { + authAxios + .delete(removeFromCartURL + `${id}/delete/`) + .then((res) => { + console.log(res); + fetchCart(); + }) + .catch((err) => { + console.log(err); + }); +}; diff --git a/requirements.txt b/requirements.txt index 022746e..a07f6a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,8 @@ defusedxml==0.6.0 dj-rest-auth==1.0.9 Django==3.0.7 django-admin-interface==0.12.2 +django-allauth==0.51.0 +django-cleanup==6.0.0 django-colorfield==0.3.1 django-cors-headers==3.4.0 django-flat-responsive==2.0 @@ -30,6 +32,7 @@ outcome==1.1.0 Pillow==9.2.0 pycodestyle==2.6.0 pycparser==2.21 +PyJWT==2.4.0 pynvim==0.4.3 pyOpenSSL==21.0.0 python-dateutil==2.8.2 diff --git a/shop/views.py b/shop/views.py index 29af8e4..7975f41 100644 --- a/shop/views.py +++ b/shop/views.py @@ -1,3 +1,4 @@ +from django.http import Http404 from django.shortcuts import render, get_object_or_404 from rest_framework.response import Response from django.conf import settings @@ -215,7 +216,7 @@ def post(self, request, *args, **kwargs): except stripe.error.RateLimitError as e: # Too many requests made to the API too quickly - messages.warning(self.request, "Rate limit error") + # messages.warning(self.request, "Rate limit error") return Response({"message": "Rate limit error"}, status=HTTP_400_BAD_REQUEST) except stripe.error.InvalidRequestError as e: