From f320eafc55f3efbc7eb5c9330b652aa7383ee12e Mon Sep 17 00:00:00 2001 From: Andrey Smakotin Date: Fri, 12 Dec 2025 19:21:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B4=D0=B5=D0=BF?= =?UTF-8?q?=D0=BB=D0=BE=D1=8F=20=D0=BD=D0=B0=20NAS:=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D0=B0,=20=D0=BC=D0=B5=D0=B4=D0=B8=D0=B0,=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B5=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BA=D1=83=D0=BF=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/create_public_tenant.py | 17 ++++++++++++++++- myproject/myproject/urls.py | 10 ++++++++++ myproject/myproject/urls_public.py | 9 +++++++++ .../commands/activate_registration.py | 6 ++++++ .../management/commands/create_tenant.py | 6 ++++++ requirements.txt | 1 + 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/docker/create_public_tenant.py b/docker/create_public_tenant.py index 85be4b5..6bd3196 100644 --- a/docker/create_public_tenant.py +++ b/docker/create_public_tenant.py @@ -17,10 +17,17 @@ def ensure_public_tenant(): domain_name = os.environ.get('DOMAIN_NAME', 'localhost') print(f"Checking public tenant for domain: {domain_name}") + email = os.environ.get('TENANT_ADMIN_EMAIL', 'admin@example.com') + name = os.environ.get('TENANT_ADMIN_NAME', 'System Administrator') + # 1. Ensure Client exists client, created = Client.objects.get_or_create( schema_name='public', - defaults={'name': 'Main Tenant'} + defaults={ + 'name': 'System Tenant', + 'owner_email': email, + 'owner_name': name + } ) if created: print("Created public tenant client.") @@ -41,5 +48,13 @@ def ensure_public_tenant(): if domain.tenant != client: print(f"WARNING: Domain {domain_name} is assigned to another tenant!") + # 3. Init system data (System Customer, etc.) + print("Initializing system data for public tenant...") + from django.core.management import call_command + try: + call_command('init_tenant_data', schema='public') + except Exception as e: + print(f"Error initializing system data: {e}") + if __name__ == '__main__': ensure_public_tenant() diff --git a/myproject/myproject/urls.py b/myproject/myproject/urls.py index 2660ffe..8348564 100644 --- a/myproject/myproject/urls.py +++ b/myproject/myproject/urls.py @@ -8,6 +8,8 @@ from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static +from django.urls import re_path +from django.views.static import serve from . import views urlpatterns = [ @@ -25,7 +27,15 @@ urlpatterns = [ path('pos/', include('pos.urls')), # POS Terminal ] +# Serve media files during development # Serve media files during development if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +else: + # Force serve media files in production (for NAS setup) + urlpatterns += [ + re_path(r'^media/(?P.*)$', serve, { + 'document_root': settings.MEDIA_ROOT, + }), + ] diff --git a/myproject/myproject/urls_public.py b/myproject/myproject/urls_public.py index 4d062e9..5f06673 100644 --- a/myproject/myproject/urls_public.py +++ b/myproject/myproject/urls_public.py @@ -10,6 +10,8 @@ from django.contrib import admin from django.urls import path, include from django.conf import settings from django.conf.urls.static import static +from django.urls import re_path +from django.views.static import serve urlpatterns = [ path('admin/', admin.site.urls), @@ -21,3 +23,10 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +else: + # Force serve media files in production (for NAS setup) + urlpatterns += [ + re_path(r'^media/(?P.*)$', serve, { + 'document_root': settings.MEDIA_ROOT, + }), + ] diff --git a/myproject/tenants/management/commands/activate_registration.py b/myproject/tenants/management/commands/activate_registration.py index ab28908..282392b 100644 --- a/myproject/tenants/management/commands/activate_registration.py +++ b/myproject/tenants/management/commands/activate_registration.py @@ -115,6 +115,12 @@ class Command(BaseCommand): f'истекает: {subscription.expires_at.strftime("%Y-%m-%d")}' )) + # Инициализация системных данных + self.stdout.write('Инициализация системных данных...') + from django.core.management import call_command + call_command('init_tenant_data', schema=client.schema_name) + self.stdout.write(self.style.SUCCESS('✓ Системные данные созданы')) + # Обновляем заявку registration.status = TenantRegistration.STATUS_APPROVED registration.processed_at = timezone.now() diff --git a/myproject/tenants/management/commands/create_tenant.py b/myproject/tenants/management/commands/create_tenant.py index 2c87a6c..dc54a77 100644 --- a/myproject/tenants/management/commands/create_tenant.py +++ b/myproject/tenants/management/commands/create_tenant.py @@ -65,6 +65,12 @@ class Command(BaseCommand): ) self.stdout.write(self.style.SUCCESS(f'✓ Домен создан: {domain}')) + # Инициализация системных данных + self.stdout.write('Инициализация системных данных...') + from django.core.management import call_command + call_command('init_tenant_data', schema=schema_name) + self.stdout.write(self.style.SUCCESS('✓ Системные данные созданы')) + self.stdout.write('\n' + '='*60) self.stdout.write(self.style.SUCCESS('✓ Магазин успешно создан!')) self.stdout.write('='*60 + '\n') diff --git a/requirements.txt b/requirements.txt index cb62d56..1b04b82 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,3 +33,4 @@ Unidecode==1.4.0 vine==5.1.0 wcwidth==0.2.14 gunicorn==21.2.0 +whitenoise==6.6.0