Skip to content

Commit

Permalink
config: django debug toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-inic committed May 28, 2024
1 parent 3a3b774 commit 470eb16
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 88 deletions.
160 changes: 81 additions & 79 deletions procentapi/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path
import os
from pathlib import Path
from django.utils.translation import gettext_lazy as _
from dotenv import load_dotenv
load_dotenv('.env.local')
import braintree

load_dotenv(".env.local")

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -24,116 +26,114 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
SECRET_KEY = os.environ["SECRET_KEY"]


# Application definition

INSTALLED_APPS = [
#ovveride django auth with users auth
'users.apps.UsersConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

# ovveride django auth with users auth
"users.apps.UsersConfig",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# third part apps
'rest_framework',
'rosetta',
'parler',
'localflavor',
'storages',

"rest_framework",
"rosetta",
"parler",
"localflavor",
"storages",
"debug_toolbar",
# apps
'shop.apps.ShopConfig',
'cart.apps.CartConfig',
'orders.apps.OrdersConfig',
'payment.apps.PaymentConfig',
'coupon.apps.CouponConfig',
"shop.apps.ShopConfig",
"cart.apps.CartConfig",
"orders.apps.OrdersConfig",
"payment.apps.PaymentConfig",
"coupon.apps.CouponConfig",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.locale.LocaleMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
]

ROOT_URLCONF = 'procentapi.urls'
ROOT_URLCONF = "procentapi.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'cart.context_processors.cart',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"cart.context_processors.cart",
],
},
},
]

WSGI_APPLICATION = 'procentapi.wsgi.application'
WSGI_APPLICATION = "procentapi.wsgi.application"


# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]

LOGIN_REDIRECT_URL = 'shop:product_list'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = "shop:product_list"
LOGIN_URL = "login"
LOGOUT_URL = "logout"

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en'
LANGUAGE_CODE = "en"
LANGUAGES = (
('en', _('English')),
('sw', _('Swahili')),
)
LOCALE_PATHS =(
os.path.join(BASE_DIR, 'locale/'),
("en", _("English")),
("sw", _("Swahili")),
)
LOCALE_PATHS = (os.path.join(BASE_DIR, "locale/"),)

PARLER_LANGUAGES = {
None: (
{'code': 'en'},
{'code': 'sw'},
{"code": "en"},
{"code": "sw"},
),
'default': {
'fallback': 'en',
'hide_untranslated': False,
}
"default": {
"fallback": "en",
"hide_untranslated": False,
},
}

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -143,36 +143,38 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles/')
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, "static"),
]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")

CART_SESSION_ID = 'cart'
CART_SESSION_ID = "cart"

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

# braintree settings
BRAINTREE_MERCHANT_ID = os.environ['BRAINTREE_MERCHANT_ID']
BRAINTREE_PUBLIC_KEY = os.environ['BRAINTREE_PUBLIC_KEY']
BRAINTREE_PRIVATE_KEY = os.environ['BRAINTREE_PRIVATE_KEY']
# braintree settings
BRAINTREE_MERCHANT_ID = os.environ["BRAINTREE_MERCHANT_ID"]
BRAINTREE_PUBLIC_KEY = os.environ["BRAINTREE_PUBLIC_KEY"]
BRAINTREE_PRIVATE_KEY = os.environ["BRAINTREE_PRIVATE_KEY"]

import braintree
BRAINTREE_CONF = braintree.Configuration(
braintree.Environment.Sandbox,
BRAINTREE_MERCHANT_ID,
BRAINTREE_PUBLIC_KEY,
BRAINTREE_PRIVATE_KEY
BRAINTREE_PRIVATE_KEY,
)

INTERNAL_IPS = [
"127.0.0.1",
]
20 changes: 11 additions & 9 deletions procentapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
Expand All @@ -22,16 +23,17 @@


urlpatterns = i18n_patterns(
path(_('admin/'), admin.site.urls),
path(_('cart/'), include('cart.urls', namespace='cart')),
path(_('orders/'), include('orders.urls', namespace='orders')),
path(_('payment/'), include('payment.urls', namespace='payment')),
path(_('coupons/'), include('coupon.urls', namespace='coupons')),
path('rosetta/', include('rosetta.urls')),
path('users/', include('users.urls')),
path('', include('shop.urls', namespace='shop')),
path(_("admin/"), admin.site.urls),
path(_("cart/"), include("cart.urls", namespace="cart")),
path(_("orders/"), include("orders.urls", namespace="orders")),
path(_("payment/"), include("payment.urls", namespace="payment")),
path(_("coupons/"), include("coupon.urls", namespace="coupons")),
path("rosetta/", include("rosetta.urls")),
path("users/", include("users.urls")),
path("__debug__/", include("debug_toolbar.urls")),
path("", include("shop.urls", namespace="shop")),
# path('api-auth/', include('rest_framework.urls')),
)

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

0 comments on commit 470eb16

Please sign in to comment.