feat: initial commit - Band Management application

This commit is contained in:
2026-01-06 03:11:46 +01:00
commit 34e12e00b3
24543 changed files with 3991790 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# from web_project.bootstrap import TemplateBootstrap
from web_project.template_helpers.theme import TemplateHelper
from django.conf import settings
class TemplateLayout:
# Initialize the bootstrap files and page layout
def init(self, context):
# Init the Template Context using TEMPLATE_CONFIG
context = TemplateHelper.init_context(context)
# Set a default layout globally using settings.py. Can be set in the page level view file as well.
layout = context["layout"]
# Set the selected layout
context.update(
{
"layout_path": TemplateHelper.set_layout(
"layout_" + layout + ".html", context
),
# Set default rtl True if the language Arabic else use rtl_mode value from TEMPLATE_CONFIG
"rtl_mode": True
if self.request.COOKIES.get('django_text_direction') == "rtl"
else settings.TEMPLATE_CONFIG.get("rtl_mode"),
}
)
# Map context variables
TemplateHelper.map_context(context)
return context

View File

@@ -0,0 +1,144 @@
from django.conf import settings
from pprint import pprint
import os
from importlib import import_module, util
# Core TemplateHelper class
class TemplateHelper:
# Init the Template Context using TEMPLATE_CONFIG
def init_context(context):
context.update(
{
"layout": settings.TEMPLATE_CONFIG.get("layout"),
"primary_color": settings.TEMPLATE_CONFIG.get("primary_color"),
"theme": settings.TEMPLATE_CONFIG.get("theme"),
"skins": settings.TEMPLATE_CONFIG.get("my_skins"),
"semiDark": settings.TEMPLATE_CONFIG.get("has_semi_dark"),
"rtl_mode": settings.TEMPLATE_CONFIG.get("rtl_mode"),
"has_customizer": settings.TEMPLATE_CONFIG.get("has_customizer"),
"display_customizer": settings.TEMPLATE_CONFIG.get( "display_customizer" ),
"content_layout": settings.TEMPLATE_CONFIG.get("content_layout"),
"navbar_type": settings.TEMPLATE_CONFIG.get("navbar_type"),
"header_type": settings.TEMPLATE_CONFIG.get("header_type"),
"menu_fixed": settings.TEMPLATE_CONFIG.get("menu_fixed"),
"menu_collapsed": settings.TEMPLATE_CONFIG.get("menu_collapsed"),
"footer_fixed": settings.TEMPLATE_CONFIG.get("footer_fixed"),
"show_dropdown_onhover": settings.TEMPLATE_CONFIG.get( "show_dropdown_onhover" ),
"customizer_controls": settings.TEMPLATE_CONFIG.get( "customizer_controls" ),
}
)
return context
# ? Map context variables to template class/value/variables names
def map_context(context):
#! Header Type (horizontal support only)
if context.get("layout") == "horizontal":
if context.get("header_type") == "fixed":
context["header_type_class"] = "layout-menu-fixed"
elif context.get("header_type") == "static":
context["header_type_class"] = ""
else:
context["header_type_class"] = ""
else:
context["header_type_class"] = ""
#! Navbar Type (vertical/front support only)
if context.get("layout") != "horizontal":
if context.get("navbar_type") == "fixed":
context["navbar_type_class"] = "layout-navbar-fixed"
elif context.get("navbar_type") == "static":
context["navbar_type_class"] = ""
else:
context["navbar_type_class"] = "layout-navbar-hidden"
else:
context["navbar_type_class"] = ""
# Menu collapsed
context["menu_collapsed_class"] = (
"layout-menu-collapsed" if context.get("menu_collapsed") else ""
)
#! Menu Fixed (vertical support only)
if context.get("layout") == "vertical":
if context.get("menu_fixed") is True:
context["menu_fixed_class"] = "layout-menu-fixed"
else:
context["menu_fixed_class"] = ""
# Footer Fixed
context["footer_fixed_class"] = (
"layout-footer-fixed" if context.get("footer_fixed") else ""
)
# RTL Mode/Layout
context["rtl_mode_value"], context["text_direction_value"] = (
("rtl", "rtl") if context.get("rtl_mode") else ("ltr", "ltr")
)
#! Show dropdown on hover (Horizontal menu)
context["show_dropdown_onhover_value"] = (
"true" if context.get("show_dropdown_onhover") else "false"
)
context["semi_dark_value"] = (
"true" if context.get("semiDark") else "false"
)
# Display Customizer
context["display_customizer_class"] = (
"" if context.get("display_customizer") else "customizer-hide"
)
# Content Layout
if context.get("content_layout") == "wide":
context["container_class"] = "container-fluid"
context["content_layout_class"] = "layout-wide"
else:
context["container_class"] = "container-xxl"
context["content_layout_class"] = "layout-compact"
# Detached Navbar
if context.get("navbar_detached") == True:
context["navbar_detached_class"] = "navbar-detached"
else:
context["navbar_detached_class"] = ""
# Get theme variables by scope
def get_theme_variables(scope):
return settings.THEME_VARIABLES[scope]
# Get theme config by scope
def get_theme_config(scope):
return settings.TEMPLATE_CONFIG[scope]
# Set the current page layout and init the layout bootstrap file
def set_layout(view, context={}):
# Extract layout from the view path
layout = os.path.splitext(view)[0].split("/")[0]
# Get module path
module = f"templates.{settings.THEME_LAYOUT_DIR.replace('/', '.')}.bootstrap.{layout}"
# Check if the bootstrap file is exist
if util.find_spec(module) is not None:
# Auto import and init the default bootstrap.py file from the theme
TemplateBootstrap = TemplateHelper.import_class(
module, f"TemplateBootstrap{layout.title().replace('_', '')}"
)
TemplateBootstrap.init(context)
else:
module = f"templates.{settings.THEME_LAYOUT_DIR.replace('/', '.')}.bootstrap.default"
TemplateBootstrap = TemplateHelper.import_class(
module, "TemplateBootstrapDefault"
)
TemplateBootstrap.init(context)
return f"{settings.THEME_LAYOUT_DIR}/{view}"
# Import a module by string
def import_class(fromModule, import_className):
pprint(f"Loading {import_className} from {fromModule}")
module = import_module(fromModule)
return getattr(module, import_className)

View File

@@ -0,0 +1,92 @@
from django.utils.safestring import mark_safe
from django import template
from web_project.template_helpers.theme import TemplateHelper
from django.contrib.auth.decorators import user_passes_test
register = template.Library()
# Register tags as an adapter for the Theme class usage in the HTML template
@register.simple_tag
def get_theme_variables(scope):
return mark_safe(TemplateHelper.get_theme_variables(scope))
@register.simple_tag
def get_theme_config(scope):
return mark_safe(TemplateHelper.get_theme_config(scope))
@register.filter
def filter_by_url(submenu, url):
if submenu:
for subitem in submenu:
subitem_url = subitem.get("url")
if subitem_url == url.path or subitem_url == url.resolver_match.url_name:
return True
# Recursively check for submenus
elif subitem.get("submenu"):
if filter_by_url(subitem["submenu"], url):
return True
return False
# Check if the user has the group
@register.filter
def has_group(user, group):
if user.groups.filter(name=group).exists():
return True
# Check if the user has the permission
@register.filter
def has_permission(user, permission):
if user.has_perm(permission):
return True
# For checking if the user group is admin
@register.filter(name="is_admin")
def is_admin(user):
return user.groups.filter(name="admin").exists()
@register.filter(name="admin_required")
def admin_required(view_func):
return user_passes_test(is_admin, login_url='login')(view_func)
# For checking if the user group is client
@register.filter(name="is_client")
def is_client(user):
return user.groups.filter(name="client").exists()
@register.filter(name="client_required")
def client_required(view_func):
return user_passes_test(is_client, login_url='login')(view_func)
# For checking if is_superuser
@register.filter(name="is_superuser")
def is_superuser(user):
return user.is_superuser
@register.filter(name="superuser_required")
def superuser_required(view_func):
return user_passes_test(is_superuser, login_url='login')(view_func)
# For checking if is_staff
@register.filter(name="is_staff")
def is_staff(user):
return user.is_staff
@register.filter(name="staff_required")
def staff_required(view_func):
return user_passes_test(is_staff, login_url='login')(view_func)
@register.simple_tag
def current_url(request):
return request.build_absolute_uri()

View File

@@ -0,0 +1,23 @@
from django.views.generic import TemplateView
from web_project import TemplateLayout
from web_project.template_helpers.theme import TemplateHelper
class SystemView(TemplateView):
template_name = "pages/system/not-found.html"
status = ""
def get_context_data(self, **kwargs):
# A function to init the global layout. It is defined in web_project/__init__.py file
context = TemplateLayout.init(self, super().get_context_data(**kwargs))
# Define the layout for this module
# _templates/layout/system.html
context.update(
{
"layout_path": TemplateHelper.set_layout("system.html", context),
"status": self.status,
}
)
return context