-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TL-4 add modules, users apps & postgres connection
- Loading branch information
1 parent
c87c949
commit 7c09139
Showing
21 changed files
with
259 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
SECRET_KEY='2w3e4r5t6y7u8i9o023e4r5t6y7u8i9o0-3e4r5t6y7' | ||
DEBUG=True | ||
SECRET_KEY='2w3e4r5t6y7u8i9o023e4r5t6y7u8i9o0-3e4r5t6y7' | ||
DATABASE_URL=postgres://postgres:postgres@localhost:5432/propel_pro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class UsersConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = "apps.users" | ||
label = "users" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Import necessary modules | ||
from importlib import import_module | ||
from pathlib import Path | ||
from django.conf import settings | ||
|
||
# WARNING: Do not remove or change this code snippet; it's essential for functionality | ||
|
||
try: | ||
# Define the directory where the modules are located | ||
modules_dir = f"{settings.BASE_DIR}/modules/" | ||
|
||
# Recursively search for 'admin.py' files within the modules directory | ||
admins = list(Path(modules_dir).rglob('admin.py')) | ||
|
||
# Iterate through the 'admin.py' files | ||
for admin in admins: | ||
# Extract the module name from the path | ||
module_name, _ = admin.as_posix().split('/')[-2:] | ||
|
||
# Check if the module name is not 'modules' | ||
if not module_name == "modules": | ||
# Dynamically import the 'admin' module for the current module | ||
module = import_module(f"modules.{module_name}.admin") | ||
|
||
# Import all items from the 'module' (admin module) into the current namespace | ||
from module import * # noqa | ||
except (ImportError, IndexError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ModulesConfig(AppConfig): | ||
name = 'modules' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Import the pathlib module for working with file paths | ||
from pathlib import Path | ||
|
||
# Define the name of the modules package and the path to the modules directory | ||
MODULES_PACKAGE_NAME = "modules" | ||
MODULES_DIR = f"{Path.cwd()}/{MODULES_PACKAGE_NAME}/" | ||
|
||
# Recursively search for 'apps.py' files within the modules directory | ||
APPS = Path(MODULES_DIR).rglob("apps.py") | ||
|
||
|
||
# Define a function to get a list of module names | ||
def get_modules(): | ||
try: | ||
# Initialize an empty list to store module names | ||
modules = [] | ||
|
||
# Define the separator for Python package names (dot) | ||
python_package_separator = "." | ||
|
||
# Iterate through the 'apps.py' files found in the modules directory | ||
for app in APPS: | ||
# Convert the path to a Python package-style name | ||
app_name = app.as_posix().replace(MODULES_DIR, f"{MODULES_PACKAGE_NAME}/") | ||
app_name = python_package_separator.join(app_name.split("/")[:-1]) | ||
|
||
# Add the module name to the list | ||
modules.append(app_name) | ||
|
||
# Return the list of module names | ||
return modules | ||
except (ImportError, IndexError): | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "module_options": {} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Import necessary modules | ||
from pathlib import Path | ||
from django.conf import settings | ||
from django.urls import path, include | ||
from django.db.utils import ProgrammingError | ||
|
||
# Initialize an empty list to hold URL patterns | ||
urlpatterns = [] | ||
|
||
# This code snippet is designed to dynamically include URL patterns from Django modules. | ||
# It should not be removed or modified for certain functionalities. | ||
|
||
# Try to include URL patterns from dynamically discovered modules. | ||
try: | ||
# Define the directory where the modules are located | ||
modules_dir = f"{settings.BASE_DIR}/modules/" | ||
|
||
# Recursively search for 'urls.py' files within the modules directory | ||
urls = Path(modules_dir).rglob("urls.py") | ||
|
||
# Iterate through the discovered 'urls.py' files | ||
for url in urls: | ||
# Extract the module name from the path | ||
module_name, _ = url.as_posix().split("/")[-2:] | ||
|
||
# Check if the module name is not 'modules' | ||
if not module_name == "modules": | ||
# Convert module_name to a URL-friendly format | ||
module_url = module_name.replace("_", "-") | ||
|
||
# Include the module's URL patterns using the 'include' function | ||
urlpatterns += [ | ||
path(f"{module_url}/", include(f"modules.{module_name}.urls")) | ||
] | ||
except (ImportError, IndexError, ProgrammingError): | ||
# Handle exceptions that may occur during module discovery | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Import necessary modules | ||
import importlib | ||
import json | ||
from pathlib import Path | ||
|
||
# Define the path to the global options JSON file | ||
GLOBAL_OPTIONS_FILE_PATH = f"{Path.cwd()}/modules/options.json" | ||
|
||
|
||
# Define a function to retrieve module-specific options | ||
def get_options(module_slug, option_key): | ||
# Open and read the global options JSON file | ||
with open(GLOBAL_OPTIONS_FILE_PATH, "r") as f: | ||
module_options = json.loads(f.read()) | ||
|
||
# Search for the specified module's options based on its slug | ||
option_value = [ | ||
module.get(option_key) | ||
for module in module_options["module_options"] | ||
if module.get("slug") == module_slug | ||
] | ||
|
||
# Get the default value for the option by dynamically importing the module | ||
default_value = getattr( | ||
importlib.import_module(f"modules.{module_slug}.options"), option_key | ||
) | ||
|
||
# Return the option value if found, otherwise return the default value | ||
return option_value[0] if option_value else default_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters