Skip to content

Commit

Permalink
feat[backend]: add django cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulgpt committed Aug 2, 2022
1 parent 2577d8d commit b237270
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 82 deletions.
3 changes: 2 additions & 1 deletion backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
'gallery.apps.GalleryConfig',
'shop.apps.ShopConfig',
'about.apps.AboutConfig',
'emailverification',
# 'emailverification',
'storages',
'django_cleanup.apps.CleanupConfig',
]

SITE_ID = 3
Expand Down
7 changes: 0 additions & 7 deletions emailverification/urls.py
Original file line number Diff line number Diff line change
@@ -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<key>[-:\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<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[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')
]
5 changes: 0 additions & 5 deletions emailverification/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
134 changes: 66 additions & 68 deletions frontend/src/actions/cartActions.js
Original file line number Diff line number Diff line change
@@ -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);
});
};
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion shop/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b237270

Please sign in to comment.