gealogiuya
This commit is contained in:
0
apps/shared/__init__.py
Normal file
0
apps/shared/__init__.py
Normal file
33
apps/shared/admin.py
Normal file
33
apps/shared/admin.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from django.contrib.auth.models import Group, User
|
||||
from unfold.admin import ModelAdmin # noqa
|
||||
from unfold.forms import (
|
||||
UserChangeForm,
|
||||
UserCreationForm,
|
||||
AdminPasswordChangeForm,
|
||||
) # noqa
|
||||
|
||||
admin.site.unregister(Group)
|
||||
admin.site.unregister(User)
|
||||
|
||||
|
||||
@admin.register(Group)
|
||||
class GroupAdmin(BaseGroupAdmin, ModelAdmin):
|
||||
list_display = ("name",)
|
||||
search_fields = ("name",)
|
||||
filter_vertical = ("permissions",)
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(BaseUserAdmin, ModelAdmin):
|
||||
change_password_form = AdminPasswordChangeForm
|
||||
add_form = UserCreationForm
|
||||
form = UserChangeForm
|
||||
list_display = ("username", "email", "is_active", "is_staff", "is_superuser")
|
||||
list_filter = ("is_active", "is_staff", "is_superuser")
|
||||
search_fields = ("username", "email")
|
||||
ordering = ("username",)
|
||||
list_editable = ("is_active", "is_staff", "is_superuser")
|
||||
filter_vertical = ("groups", "user_permissions")
|
||||
6
apps/shared/apps.py
Normal file
6
apps/shared/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class SharedConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "apps.shared"
|
||||
0
apps/shared/management/__init__.py
Normal file
0
apps/shared/management/__init__.py
Normal file
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
|
||||
)
|
||||
0
apps/shared/migrations/__init__.py
Normal file
0
apps/shared/migrations/__init__.py
Normal file
9
apps/shared/models.py
Normal file
9
apps/shared/models.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
class AbstractBaseModel(models.Model):
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
1
apps/shared/tests.py
Normal file
1
apps/shared/tests.py
Normal file
@@ -0,0 +1 @@
|
||||
# Create your tests here.
|
||||
6
apps/shared/urls.py
Normal file
6
apps/shared/urls.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from .views import HomeView
|
||||
|
||||
urlpatterns = [
|
||||
path("", HomeView.as_view(), name="home"),
|
||||
]
|
||||
5
apps/shared/views.py
Normal file
5
apps/shared/views.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
template_name = "index.html"
|
||||
Reference in New Issue
Block a user