gealogiuya
This commit is contained in:
0
apps/shared/management/commands/__init__.py
Normal file
0
apps/shared/management/commands/__init__.py
Normal file
25
apps/shared/management/commands/createadmin.py
Normal file
25
apps/shared/management/commands/createadmin.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
user = get_user_model()
|
||||
self.create_superuser(user, "jahongir", "jahongirhakimjonov@gmail.com", "1253")
|
||||
self.create_superuser(
|
||||
user, "Jahongir", "jahongirhakimjonov@gmail.com", "20030307mart"
|
||||
)
|
||||
self.create_superuser(
|
||||
user, "998330078587", "jahongirhakimjonov@gmail.com", "20030307mart"
|
||||
)
|
||||
|
||||
def create_superuser(self, user, username, email, password):
|
||||
if not user.objects.filter(username=username).exists():
|
||||
user.objects.create_superuser(username, email, password)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Superuser {username} created successfully.")
|
||||
)
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(f"Superuser {username} already exists.")
|
||||
)
|
||||
52
apps/shared/management/commands/makeapp.py
Normal file
52
apps/shared/management/commands/makeapp.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (
|
||||
"Creates a new Django app inside the apps folder and sets the name in apps.py"
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument("app_name", type=str, help="The name of the app to create")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
app_name = options["app_name"]
|
||||
app_directory = os.path.join("apps", app_name)
|
||||
|
||||
os.makedirs(app_directory, exist_ok=True)
|
||||
|
||||
init_file_path = os.path.join("apps", "__init__.py")
|
||||
|
||||
if not os.path.exists(init_file_path):
|
||||
open(init_file_path, "w").close()
|
||||
|
||||
call_command("startapp", app_name, app_directory)
|
||||
|
||||
apps_file_path = os.path.join(app_directory, "apps.py")
|
||||
with open(apps_file_path, "r") as file:
|
||||
filedata = file.read()
|
||||
|
||||
filedata = filedata.replace(f'name = "{app_name}"', f'name = "apps.{app_name}"')
|
||||
|
||||
with open(apps_file_path, "w") as file:
|
||||
file.write(filedata)
|
||||
|
||||
for file_name in ["admin.py", "models.py", "views.py", "tests.py"]:
|
||||
os.remove(os.path.join(app_directory, file_name))
|
||||
|
||||
urls_file_path = os.path.join(app_directory, "urls.py")
|
||||
with open(urls_file_path, "w") as file:
|
||||
file.write("from django.urls import path\n\nurlpatterns = []\n")
|
||||
|
||||
def create_package(package_name): # noqa
|
||||
os.makedirs(package_name, exist_ok=True)
|
||||
with open(os.path.join(package_name, "__init__.py"), "w"):
|
||||
pass
|
||||
|
||||
for package_name in ["models", "views", "admin", "serializers", "tests"]:
|
||||
create_package(os.path.join(app_directory, package_name))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(f"App {app_name} created successfully!"))
|
||||
43
apps/shared/management/commands/nginx.py
Normal file
43
apps/shared/management/commands/nginx.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
|
||||
from colorama import Fore, Style
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generates a new nginx config file with custom domain and project path"
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
domain_name = input(
|
||||
Fore.LIGHTCYAN_EX + "Please enter the domain name: " + Style.RESET_ALL
|
||||
)
|
||||
project_name = input(
|
||||
Fore.LIGHTMAGENTA_EX + "\nPlease enter the project name: " + Style.RESET_ALL
|
||||
)
|
||||
project_port = input(
|
||||
Fore.LIGHTBLUE_EX + "\nPlease enter the project port: " + Style.RESET_ALL
|
||||
)
|
||||
|
||||
source_file_path = "./deployments/compose/nginx/nginx.conf"
|
||||
target_dir_path = "./deployments/nginx"
|
||||
target_file_path = f"{target_dir_path}/{domain_name}.conf"
|
||||
|
||||
with open(source_file_path, "r") as file:
|
||||
file_contents = file.read()
|
||||
|
||||
file_contents = file_contents.replace("yourdomain.uz", domain_name)
|
||||
file_contents = file_contents.replace("/path/project", project_name)
|
||||
file_contents = file_contents.replace("PROJECT_PORT", project_port)
|
||||
|
||||
os.makedirs(target_dir_path, exist_ok=True)
|
||||
|
||||
with open(target_file_path, "w") as file:
|
||||
file.write(file_contents)
|
||||
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
Fore.LIGHTGREEN_EX
|
||||
+ f"\n\n\nSuccessfully created {target_file_path}\n\n"
|
||||
+ Style.RESET_ALL
|
||||
)
|
||||
)
|
||||
21
apps/shared/management/commands/secret_key.py
Normal file
21
apps/shared/management/commands/secret_key.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from colorama import Fore, Style
|
||||
from django.core.management import utils
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Generates a new Django secret key"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
print(
|
||||
Fore.LIGHTCYAN_EX
|
||||
+ "<======================================================>"
|
||||
)
|
||||
print(
|
||||
"<=" + Style.RESET_ALL,
|
||||
Fore.LIGHTMAGENTA_EX + utils.get_random_secret_key() + Style.RESET_ALL,
|
||||
Fore.LIGHTCYAN_EX + "=>",
|
||||
)
|
||||
print(
|
||||
"<======================================================>" + Style.RESET_ALL
|
||||
)
|
||||
Reference in New Issue
Block a user