Pārlūkot izejas kodu

Structure settings and wsgi for development and production environment

Mohidul Islam 5 gadi atpakaļ
vecāks
revīzija
8d6d46db79

+ 4 - 4
README.md

@@ -28,12 +28,12 @@ mysql> SHOW TABLES;
 
 ### 4. Run the development server
 ```bash
-(env) ➜ python manage.py runserver
+(env) ➜ python manage.py runserver --settings=review_automation.settings.dev
 ```
 
 ### 5. Add all corn jobs
 ```bash
-(env) ➜ python manage.py crontab add
+(env) ➜ python manage.py crontab add --settings=review_automation.settings.dev
 # Make sure corn job has added successfully
 (env) ➜ crontab -l                                     # Return list of cronjobs
 ```
@@ -41,11 +41,11 @@ mysql> SHOW TABLES;
 ### 6. Some usefull management command
 - Store all un-recorded reviews to the database.
     ```bash
-    (env) ➜ python manage.py collect_reviews
+    (env) ➜ python manage.py collect_reviews --settings=review_automation.settings.dev
     ```
 - Get model prediction report.
     ```bash
     (env) ➜ python manage.py model_report n_days
     # Example for last 30 days:
-    (env) ➜ python manage.py model_report 30
+    (env) ➜ python manage.py model_report 30 --settings=review_automation.settings.dev
     ```

+ 0 - 0
review_automation/settings/__init__.py


+ 12 - 79
review_automation/settings.py → review_automation/settings/base.py

@@ -1,39 +1,37 @@
 import os
+from .config import *
 
-# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
-
-# SECURITY WARNING: keep the secret key used in production secret!
 SECRET_KEY = '0t@j@klm8b@2rdl@po$$24pirh$&cg#p6f#)@$@n8^kn7k2%9b'
 
-# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = True
-
-ALLOWED_HOSTS = []
-
-
 # Application definition
 
-INSTALLED_APPS = [
+DJANGO_DEFAULT_APPS = [
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+]
 
+THIRD_PARTY_APPS = [
+    'crispy_forms',
+    'django_crontab',
+]
+
+PROJECTS_APPS = [
     'gauth.apps.GauthConfig',
     'review.apps.ReviewConfig',
     'dashboard.apps.DashboardConfig',
     'nlu_job.apps.NluJobConfig',
     'analytics.apps.AnalyticsConfig',
     'name_extractor.apps.NameExtractorConfig',
-
-    'crispy_forms',
-    'django_crontab',
 ]
 
+INSTALLED_APPS = DJANGO_DEFAULT_APPS + THIRD_PARTY_APPS + PROJECTS_APPS
+
 MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
@@ -65,39 +63,6 @@ TEMPLATES = [
 WSGI_APPLICATION = 'review_automation.wsgi.application'
 
 
-# Database
-
-DATABASES = {
-    'default': {
-        'ENGINE': 'django.db.backends.mysql',
-        'NAME': 'review_automation',
-        'USER': 'bytetrek',
-        'PASSWORD': 'sad2002S1',
-        'HOST': 'localhost',
-        'PORT': '3306',
-    }
-}
-
-
-
-# Password validation
-
-AUTH_PASSWORD_VALIDATORS = [
-    {
-        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
-    },
-    {
-        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
-    },
-]
-
-
 # Internationalization
 
 LANGUAGE_CODE = 'en-us'
@@ -119,35 +84,3 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
 LOGIN_URL = '/admin/login'
 LOGIN_REDIRECT_URL = '/'
 CRISPY_TEMPLATE_PACK = 'bootstrap4'
-
-
-# Google credentials
-CLIENT_ID = "174657415928-0bt50gt42pslq47gf21ao67n15rom96r.apps.googleusercontent.com"
-CLIENT_SECRET = "ZXYpt07Su0pW3y3jPGOXY_C_"
-TOKEN_URI = "https://oauth2.googleapis.com/token"
-HOST_URI = "http://127.0.0.1:8000"
-NLU_SERVER_URI = 'http://10.0.0.33:5005'
-
-
-# Cron-Jobs of the project
-CRONJOBS = [
-    ('0 */6 * * *', 'review.background_job.background_task_6_hours_interval'),
-]
-
-
-# Configure Email Server
-EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
-
-EMAIL_USE_TLS = True
-
-EMAIL_HOST = 'smtp.gmail.com'
-
-EMAIL_HOST_USER = 'webmaster@ercare24.com'
-EMAIL_HOST_PASSWORD = 'Webdev#7182'
-
-
-EMAIL_PORT = 587
-
-ADMIN_MAINTEINER_EMAILS = [
-    'hannan@ercare24.com'
-    ]

+ 29 - 0
review_automation/settings/config.py

@@ -0,0 +1,29 @@
+# Cron-Jobs of the project
+CRONJOBS = [
+    ('0 */6 * * *', 'review.background_job.background_task_6_hours_interval'),
+]
+
+
+# Google credentials
+
+CLIENT_ID = "174657415928-0bt50gt42pslq47gf21ao67n15rom96r.apps.googleusercontent.com"
+CLIENT_SECRET = "ZXYpt07Su0pW3y3jPGOXY_C_"
+TOKEN_URI = "https://oauth2.googleapis.com/token"
+
+
+# Configure Email Server
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+
+EMAIL_USE_TLS = True
+
+EMAIL_HOST = 'smtp.gmail.com'
+
+EMAIL_HOST_USER = 'webmaster@ercare24.com'
+EMAIL_HOST_PASSWORD = 'Webdev#7182'
+
+
+EMAIL_PORT = 587
+
+ADMIN_MAINTEINER_EMAILS = [
+    'hannan@ercare24.com'
+    ]

+ 25 - 0
review_automation/settings/dev.py

@@ -0,0 +1,25 @@
+from .base import *
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Database
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'review_automation',
+        'USER': 'bytetrek',
+        'PASSWORD': 'sad2002S1',
+        'HOST': 'localhost',
+        'PORT': '3306',
+    }
+}
+
+# Host URLS
+
+HOST_URI = "http://127.0.0.1:8000"
+NLU_SERVER_URI = 'http://10.0.0.33:5005'

+ 42 - 0
review_automation/settings/prod.py

@@ -0,0 +1,42 @@
+from .base import *
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = False
+
+ALLOWED_HOSTS = ['10.0.0.36', 'bytetrek.com']
+
+
+# Database
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': 'bt_review_bot',
+        'USER': 'root',
+        'PASSWORD': 'sad2002S1',
+        'HOST': 'localhost',
+        'PORT': '3306',
+    }
+}
+
+# Password validation
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+# Host URLS
+
+HOST_URI = "http://10.0.0.36:5005"
+NLU_SERVER_URI = 'http://10.0.0.25:5005'

+ 0 - 0
review_automation/wsgi/__init__.py


+ 1 - 1
review_automation/wsgi.py → review_automation/wsgi/dev.py

@@ -2,6 +2,6 @@ import os
 
 from django.core.wsgi import get_wsgi_application
 
-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'review_automation.settings')
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'review_automation.settings.dev')
 
 application = get_wsgi_application()

+ 7 - 0
review_automation/wsgi/prod.py

@@ -0,0 +1,7 @@
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'review_automation.settings.prod')
+
+application = get_wsgi_application()