Ver código fonte

clean up settings

Mohammed Khan 1 ano atrás
pai
commit
3e2d35c2b4

+ 2 - 1
backend/UnTube/settings/__init__.py

@@ -15,7 +15,7 @@ LOCAL_SETTINGS_PATH = os.getenv(f'{ENVVAR_SETTINGS_PREFIX}LOCAL_SETTINGS_PATH')
 if not LOCAL_SETTINGS_PATH:  # default to development mode - use local dev settings
     LOCAL_SETTINGS_PATH = 'local/settings.dev.py'
 
-if not os.path.isabs(LOCAL_SETTINGS_PATH):
+if not os.path.isabs(LOCAL_SETTINGS_PATH):  # always make sure to have the absolute path
     LOCAL_SETTINGS_PATH = str(BASE_DIR / LOCAL_SETTINGS_PATH)
 
 include(
@@ -25,6 +25,7 @@ include(
     # 'channels.py',
     # 'aws.py',
     'custom.py',
+    'allauth.py',
     optional(LOCAL_SETTINGS_PATH),  # `optional` means the file may or may not exist - it is fine if it does not
     'envvars.py',
     'docker.py',

+ 19 - 0
backend/UnTube/settings/allauth.py

@@ -0,0 +1,19 @@
+"""
+Django AllAuth package related settings
+"""
+
+SITE_ID = 10  # increment/decrement site ID as necessary
+
+SOCIALACCOUNT_PROVIDERS = {
+    'google': {
+        'SCOPE': [
+            'profile',
+            'email',
+            'https://www.googleapis.com/auth/youtube',
+        ],
+        'AUTH_PARAMS': {
+            # To refresh authentication in the background, set AUTH_PARAMS['access_type'] to offline.
+            'access_type': 'offline',
+        }
+    }
+}

+ 0 - 28
backend/UnTube/settings/base.py

@@ -10,15 +10,11 @@ For the full list of settings and their values, see
 https://docs.djangoproject.com/en/3.2/ref/settings/
 """
 import os
-from backend.UnTube.secrets import SECRETS
 from backend.UnTube.settings import BASE_DIR
 
 DEBUG = False
 SECRET_KEY = NotImplemented
 
-YOUTUBE_V3_API_KEY = SECRETS['YOUTUBE_V3_API_KEY']
-
-
 ALLOWED_HOSTS = ['127.0.0.1']
 
 # Application definition
@@ -46,8 +42,6 @@ INSTALLED_APPS = [
     'backend.search',
 ]
 
-CRISPY_TEMPLATE_PACK = 'bootstrap4'
-
 MIDDLEWARE = [
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
@@ -82,22 +76,6 @@ AUTHENTICATION_BACKENDS = [
     'allauth.account.auth_backends.AuthenticationBackend'
 ]
 
-SOCIALACCOUNT_PROVIDERS = {
-    'google': {
-        'SCOPE': [
-            'profile',
-            'email',
-            'https://www.googleapis.com/auth/youtube',
-        ],
-        'AUTH_PARAMS': {
-            # To refresh authentication in the background, set AUTH_PARAMS['access_type'] to offline.
-            'access_type': 'offline',
-        }
-    }
-}
-
-SITE_ID = 10
-
 LOGIN_URL = '/'
 
 LOGIN_REDIRECT_URL = '/home/'
@@ -114,12 +92,6 @@ DATABASES = {
     }
 }
 
-# DATABASES = {}
-# DATABASES['default'] = dj_database_url.config(conn_max_age=600)
-
-# DATABASE_URL = os.environ['DATABASE_URL']
-# conn = psycopg2.connect(DATABASE_URL, sslmode='require')
-
 # Password validation
 # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
 AUTH_PASSWORD_VALIDATORS = [

+ 8 - 1
backend/UnTube/settings/custom.py

@@ -2,7 +2,14 @@
 Settings specific to this application only (no Django or third party settings)
 """
 
+YOUTUBE_V3_API_KEY = NotImplemented
+GOOGLE_OAUTH_CLIENT_ID = NotImplemented
+GOOGLE_OAUTH_CLIENT_SECRET = NotImplemented
+CRISPY_TEMPLATE_PACK = 'bootstrap4'
+
+# hosting environments
 IN_PYTHONANYWHERE = False  # PA has PYTHONANYWHERE_SITE in its env
 IN_DOCKER = False
+
 STOKEN_EXPIRATION_SECONDS = 10
-USE_ON_COMMIT_HOOK = True
+USE_ON_COMMIT_HOOK = True

+ 3 - 2
backend/UnTube/settings/docker.py

@@ -1,11 +1,12 @@
 import os
 
 if IN_DOCKER or os.path.isfile('/.dockerenv'):  # type: ignore # noqa: F821
-    print("IN DOCKER")
     # We need it to serve static files with DEBUG=False
     assert MIDDLEWARE[:1] == [  # type: ignore # noqa: F821
         'django.middleware.security.SecurityMiddleware'
     ]
     MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware')  # type: ignore # noqa: F821
     DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
-    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
+    STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
+
+    print("Using Docker settings...")

+ 1 - 1
backend/UnTube/settings/envvars.py

@@ -5,7 +5,7 @@ from backend.general.utils.settings import get_settings_from_environment
 This takes env variables with a matching prefix (set by you), strips out the prefix, and adds it to globals
 
 Eg. 
-export UNTUBE_SETTINGs_IN_DOCKER=true (environment variable)
+export UNTUBE_SETTINGS_IN_DOCKER=true (environment variable)
 
 could be then referenced in the globals() dictionary as
 IN_DOCKER (where the value will be set to Pythonic True)

+ 2 - 0
backend/UnTube/settings/pythonanywhere.py

@@ -44,3 +44,5 @@ if IN_PYTHONANYWHERE:  # type: ignore
             }
         }
     }
+
+    print("Using Pythonanywhere settings...")

+ 12 - 13
backend/main/models.py

@@ -3,7 +3,6 @@ from django.contrib.auth.models import User
 from allauth.socialaccount.models import SocialApp
 from .util import *
 import pytz
-from backend.UnTube.secrets import SECRETS
 from django.db import models
 from google.oauth2.credentials import Credentials
 from google.auth.transport.requests import Request
@@ -1394,18 +1393,18 @@ class Playlist(models.Model):
 
         return [num_channels, channels_list]
 
-    def generate_playlist_thumbnail_url(self):
-        """
-        Generates a playlist thumnail url based on the playlist name
-        """
-        pl_name = self.name
-        response = requests.get(
-            f'https://api.unsplash.com/search/photos/?client_id={SECRETS["UNSPLASH_API_ACCESS_KEY"]}&page=1&query={pl_name}')
-        image = response.json()["results"][0]["urls"]["small"]
-
-        print(image)
-
-        return image
+    # def generate_playlist_thumbnail_url(self):
+    #     """
+    #     Generates a playlist thumnail url based on the playlist name
+    #     """
+    #     pl_name = self.name
+    #     response = requests.get(
+    #         f'https://api.unsplash.com/search/photos/?client_id={SECRETS["UNSPLASH_API_ACCESS_KEY"]}&page=1&query={pl_name}')
+    #     image = response.json()["results"][0]["urls"]["small"]
+    #
+    #     print(image)
+    #
+    #     return image
 
     def get_playlist_thumbnail_url(self):
         playlist_items = self.playlist_items.filter(