· 5 years ago · Jul 20, 2020, 03:34 PM
1"""
2Django settings for realestate project.
3
4Generated by 'django-admin startproject' using Django 3.0.7.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/3.0/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/3.0/ref/settings/
11"""
12
13import os
14import environ
15
16# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18# loading env file for database and other things
19env = environ.Env()
20env.read_env(env_file=os.path.join(BASE_DIR, '.env'))
21
22# Quick-start development settings - unsuitable for production
23# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
24
25# SECURITY WARNING: keep the secret key used in production secret!
26SECRET_KEY = 'z0*1)ins$t#$mn4d_$zdyra4rvz7xqr($3a+dd&a7a=aso63kf'
27
28# SECURITY WARNING: don't run with debug turned on in production!
29DEBUG = True
30
31ALLOWED_HOSTS = ['realestatemarket.idlewilddigital.com', '127.0.0.1']
32
33# Application definition
34
35INSTALLED_APPS = [
36 'django.contrib.admin',
37 'django.contrib.auth',
38 'django.contrib.contenttypes',
39 'django.contrib.sessions',
40 'django.contrib.messages',
41 'django.contrib.staticfiles',
42 'django.contrib.sites',
43
44 # Custom App
45 'corsheaders',
46 'core',
47 'property_management',
48 'profiles',
49
50 'rest_framework',
51 'rest_framework.authtoken',
52 'rest_auth',
53 'rest_auth.registration',
54 'allauth',
55 'allauth.account',
56 'allauth.socialaccount',
57 'allauth.socialaccount.providers.facebook',
58 'allauth.socialaccount.providers.twitter',
59 'drf_yasg',
60]
61
62SITE_ID = 1
63
64MIDDLEWARE = [
65 'django.middleware.security.SecurityMiddleware',
66 'django.contrib.sessions.middleware.SessionMiddleware',
67 'corsheaders.middleware.CorsMiddleware',
68 'django.middleware.common.CommonMiddleware',
69 'django.middleware.csrf.CsrfViewMiddleware',
70 'django.contrib.auth.middleware.AuthenticationMiddleware',
71 'django.contrib.messages.middleware.MessageMiddleware',
72 'django.middleware.clickjacking.XFrameOptionsMiddleware',
73]
74
75# For Now If this is used then `CORS_ORIGIN_WHITELIST` will not have any effect
76CORS_ORIGIN_ALLOW_ALL = True
77CORS_ALLOW_CREDENTIALS = True
78CORS_ORIGIN_WHITELIST = [
79 'http://localhost:3030',
80]
81
82CORS_ALLOW_METHODS = (
83 'DELETE',
84 'GET',
85 'OPTIONS',
86 'PATCH',
87 'POST',
88 'PUT',
89)
90
91ROOT_URLCONF = 'realestate.urls'
92
93TEMPLATES = [
94 {
95 'BACKEND': 'django.template.backends.django.DjangoTemplates',
96 'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
97 'APP_DIRS': True,
98 'OPTIONS': {
99 'context_processors': [
100 'django.template.context_processors.debug',
101 'django.template.context_processors.request',
102 'django.contrib.auth.context_processors.auth',
103 'django.contrib.messages.context_processors.messages',
104 ],
105 },
106 },
107]
108
109WSGI_APPLICATION = 'realestate.wsgi.application'
110
111# Database
112# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
113
114# DATABASES = {
115# 'default': {
116# 'ENGINE': 'django.db.backends.sqlite3',
117# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
118# }
119# }
120
121# setting up env so that password is not required to put on git repo
122if env.str('DATABASE_URL', default=''):
123 DATABASES = {
124 'default': env.db(),
125 }
126else:
127 # print("local db connecting ...")
128 DATABASES = {
129 'default': {
130 'ENGINE': 'django.db.backends.postgresql_psycopg2',
131 'NAME': 'DBNAME',
132 'USER': 'DBUSER',
133 'PASSWORD': 'DBPASSWORD',
134 'HOST': 'localhost',
135 'PORT': '5432',
136 }
137 }
138
139# Password validation
140# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
141
142AUTH_PASSWORD_VALIDATORS = [
143 {
144 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
145 },
146 {
147 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
148 },
149 {
150 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
151 },
152 {
153 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
154 },
155]
156
157# Internationalization
158# https://docs.djangoproject.com/en/3.0/topics/i18n/
159
160LANGUAGE_CODE = 'en-us'
161
162TIME_ZONE = 'UTC'
163
164USE_I18N = True
165
166USE_L10N = True
167
168USE_TZ = True
169
170# Custom adapter
171ADAPTER = 'profiles.adapter.AccountAdapter'
172# SOCIALACCOUNT_ADAPTER = 'profiles.adapter.SocialAccountAdapter'
173ACCOUNT_ADAPTER = 'profiles.adapter.AccountAdapter'
174
175ACCOUNT_USER_MODEL_USERNAME_FIELD = None
176ACCOUNT_AUTHENTICATION_METHOD = 'email'
177
178ACCOUNT_EMAIL_REQUIRED = True
179ACCOUNT_UNIQUE_EMAIL = True
180ACCOUNT_USERNAME_REQUIRED = False
181ACCOUNT_USER_EMAIL_FIELD = 'email'
182ACCOUNT_LOGOUT_ON_GET = True
183ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
184#ACCOUNT_CONFIRM_EMAIL_ON_GET = True
185
186#EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
187
188# Custom user model
189AUTH_USER_MODEL = 'profiles.SystemUser'
190
191REST_AUTH_SERIALIZERS = {
192 'LOGIN_SERIALIZER': 'profiles.serializers.LoginSerializer',
193 'TOKEN_SERIALIZER': 'profiles.serializers.TokenSerializer',
194 'USER_DETAILS_SERIALIZER': 'profiles.serializers.UserDetailsSerializer',
195}
196
197REST_AUTH_REGISTER_SERIALIZERS = {
198 'REGISTER_SERIALIZER': 'profiles.serializers.RegisterSerializer',
199}
200
201REST_FRAMEWORK = {
202 'DEFAULT_AUTHENTICATION_CLASSES': (
203 # 'rest_framework.authentication.BasicAuthentication',
204 'rest_framework.authentication.SessionAuthentication',
205 'rest_framework.authentication.TokenAuthentication',
206 ),
207}
208
209# Static files (CSS, JavaScript, Images)
210# https://docs.djangoproject.com/en/3.0/howto/static-files/
211
212STATIC_URL = '/static/'
213STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
214
215MEDIA_URL = '/media/'
216MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
217
218STATICFILES_DIRS = [
219 os.path.join(BASE_DIR, "staticfiles"),
220]
221
222LOGGING = {
223 'version': 1,
224 'disable_existing_loggers': False,
225 'formatters': {
226 'verbose': {
227 'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
228 'pathname=%(pathname)s lineno=%(lineno)s ' +
229 'funcname=%(funcName)s %(message)s'),
230 'datefmt': '%Y-%m-%d %H:%M:%S'
231 },
232 },
233 'handlers': {
234 'console': {
235 'level': 'DEBUG',
236 'class': 'logging.StreamHandler',
237 'formatter': 'verbose'
238 },
239 'mail_admins': {
240 'level': 'ERROR',
241 'class': 'django.utils.log.AdminEmailHandler',
242 'formatter': 'verbose'
243 }
244
245 },
246 'loggers': {
247 '': {
248 'handlers': ['console', 'mail_admins'],
249 'level': 'DEBUG',
250 'propagate': False,
251 },
252 'django': {
253 'handlers': ['console', 'mail_admins'],
254 'level': 'INFO',
255 'propagate': False,
256 },
257 'realestate': {
258 'handlers': ['console', 'mail_admins'],
259 'level': 'DEBUG',
260 'propagate': False,
261 },
262 }
263}
264
265EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
266EMAIL_HOST = 'smtp.gmail.com'
267EMAIL_USE_TLS = True
268EMAIL_PORT = 587
269EMAIL_HOST_USER = 'bdalomgir2441139@gmail.com'
270EMAIL_HOST_PASSWORD = 'Alomgir12345*#'
271
272# Local settings
273try:
274 from .local import *
275except ImportError:
276 pass
277
278
279# DATABASE_URL=psql://dbuser:DBPASSWORD@127.0.0.1:5432/dbname
280# DATABASE_URL=psql://postgres:StrongPassword@127.0.0.1:5432/postgres
281DATABASE_URL=sqlite:///db.sqlite3