From 7acfba0045e9cbc10dbe8f249edefdfa04932937 Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Tue, 21 Jan 2025 16:42:23 +0700 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=D0=BA=D0=BE=D0=BD=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/management/templates/icon_add.html | 104 ++++++++++++++++++++++++ apps/management/templates/settings.html | 2 +- apps/management/urls.py | 3 +- apps/management/views/views_settings.py | 32 ++++++++ 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 apps/management/templates/icon_add.html diff --git a/apps/management/templates/icon_add.html b/apps/management/templates/icon_add.html new file mode 100644 index 0000000..5cb8c0f --- /dev/null +++ b/apps/management/templates/icon_add.html @@ -0,0 +1,104 @@ +{% extends "default.html" %} +{% load static %} +{% load mysettings %} + + +{% block header_link %} + + + + + + +{% endblock header_link %} +{% block content %} + + + + + Добавление изображения горнотранспортного оборудования + + + + Главная + Параметры системы + + + + + + + + + {% csrf_token %} + + + + + + + {% if error %} + + × + + Внимание ! + {% for com in error_comment %} + {{ com }} + {% endfor %} + + {% endif %} + + + Вид + оборудования: + + + + + + Изображение: + + {{ gto_icon.model }} + + Выберите + изображение + + + + + + + + + + + + + + + +{% endblock %} +{% block script_footer %} + + +{% endblock script_footer %} + diff --git a/apps/management/templates/settings.html b/apps/management/templates/settings.html index 86f41f3..3f5f50e 100644 --- a/apps/management/templates/settings.html +++ b/apps/management/templates/settings.html @@ -349,7 +349,7 @@ {% endfor %} - Добавить + Добавить изображение diff --git a/apps/management/urls.py b/apps/management/urls.py index 0b4ba65..4082bc4 100644 --- a/apps/management/urls.py +++ b/apps/management/urls.py @@ -5,10 +5,11 @@ from apps.management.views import views_user from django.contrib.auth.decorators import login_required from django.conf.urls import include # Используйте include() чтобы добавлять URL из каталога приложения - +from apps.management.views.views_settings import gto_icon_add urlpatterns = [ url(r'^$', views_management.main_index, name='main_index'), + url(r'^gto_icon_add/$', gto_icon_add, name='gto_icon_add'), url(r'^user/add/$', views_user.user_add, name='user_add'), url(r'^user/$', views_user.user_edit, name='user_edit'), url(r'^user/password/$', views_user.user_password_edit, name='user_password_edit'), diff --git a/apps/management/views/views_settings.py b/apps/management/views/views_settings.py index 9f11e51..8f89ac6 100644 --- a/apps/management/views/views_settings.py +++ b/apps/management/views/views_settings.py @@ -140,6 +140,38 @@ def gto_icon_save(request): return redirect('/management/') +@login_required(login_url='/') +@never_cache +def gto_icon_add(request): + try: + if request.method == "GET": + return render(request, 'icon_add.html') + if request.method == "POST": + file_obj = request.FILES['icon'] + model = request.POST['model'] + save_path = os.path.join('media/map/gto', file_obj.name) + + # Убедитесь, что директория существует + os.makedirs(os.path.dirname(save_path), exist_ok=True) + + # Открываем файл для записи + with open(save_path, 'wb') as destination: + for chunk in file_obj.chunks(): + destination.write(chunk) + + icon = ModelTypeIcons.objects.filter(model=model).first() + if icon is None: + ModelTypeIcons.objects.create(model=model, path=save_path) + else: + icon.path = save_path + icon.save() + + return redirect('/management/?module=settings') + except Exception as err: + logging.error(traceback.format_exc()) + return redirect('/management/') + + @login_required(login_url='/') @never_cache def main_index(request):
{{ com }}