diff --git a/apps/gto/views/views_main.py b/apps/gto/views/views_main.py index 246dfa0..bc1b050 100644 --- a/apps/gto/views/views_main.py +++ b/apps/gto/views/views_main.py @@ -25,6 +25,7 @@ from django.db.models import Q from django.shortcuts import render from django.shortcuts import redirect +from apps.gto.models.model_type_icons import ModelTypeIcons from sabron.util import logging from apps.util import generalmodule @@ -46,6 +47,11 @@ def update_object(request): object_list = Equipment.objects.filter(my_filter).all() m_list = [] for obj in object_list: + type_g = obj.model + icon = '' + icon_obj = ModelTypeIcons.objects.filter(model=type_g).last() + if icon_obj is not None: + icon = "/" + icon_obj.path m_list.append({ 'id': obj.id, 'name': obj.name, @@ -54,6 +60,7 @@ def update_object(request): 'time': obj.time.astimezone(zoneinfo.ZoneInfo(settings.TIME_ZONE)).strftime('%d.%m.%Y, %H:%M:%S'), 'statenum': obj.statenum, 'model': obj.model, + 'icon': icon }) return generalmodule.ReturnJson(200, m_list) else: diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 29969f3..9c30793 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -102,7 +102,7 @@ function GTOStyleFunction(feature, resolution) { return new ol.style.Style({ image: new ol.style.Icon({ - src: '/static/img/belaz.png', + src: feature.get('icon'), width: 30, height: 20 }), @@ -573,7 +573,8 @@ lat: equipment.lat, lon: equipment.lon, statenum: equipment.statenum, - model: equipment.model + model: equipment.model, + icon: equipment.icon }); GTOSource.addFeature(feature); GTOMarkers[equipment.id] = feature; 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 %} + +
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+
+ +
+ +
+ +
+ +
+
+
+{% endblock %} +{% block script_footer %} + + +{% endblock script_footer %} + diff --git a/apps/management/templates/settings.html b/apps/management/templates/settings.html index df003f6..3f5f50e 100644 --- a/apps/management/templates/settings.html +++ b/apps/management/templates/settings.html @@ -279,7 +279,7 @@
{% csrf_token %}
-
{% csrf_token %}
+
{% csrf_token %}
@@ -337,18 +337,19 @@
+
Изображения загружаются автоматически при выборе
{% for gto_icon in gto_icons %}

- Сейчас выбран: {{ gto_icon.path }} - Сейчас выбран: /{{ gto_icon.path }} +
{% endfor %} - + Добавить изображение
@@ -513,7 +514,16 @@ }); return false; + } + const fileForm = document.getElementById('gto_icon_save') + const fileInputs = document.querySelectorAll('.autosubmit') + for (const fileInput of fileInputs) { + fileInput.addEventListener('change', async (ev) => { + console.log(ev) + console.log(ev.target.value) + fileForm.submit() + }) } 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 15da6ad..8f89ac6 100644 --- a/apps/management/views/views_settings.py +++ b/apps/management/views/views_settings.py @@ -15,6 +15,7 @@ from django.shortcuts import render from django.shortcuts import redirect from django.contrib.auth.models import User +from apps.gto.models.model_type_icons import ModelTypeIcons from apps.management.views import views_user from apps.general.models.model_settings import Settings @@ -110,6 +111,67 @@ def file_save(request): logging.error(traceback.format_exc()) return redirect('/management/') + +@login_required(login_url='/') +@never_cache +def gto_icon_save(request): + try: + for file in request.FILES: + file_obj = request.FILES[file] + 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=file).first() + if icon is None: + ModelTypeIcons.objects.create(model=file, 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 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): @@ -125,6 +187,8 @@ def main_index(request): return oset_save(request) if get_param['cmd']=='file_save': return file_save(request) + if get_param['cmd'] =='gto_icon_save': + return gto_icon_save(request) context = generalmodule.get_context_template() return render(request, 'settings.html',context) except Exception as err: diff --git a/apps/seismicproc/admin.py b/apps/seismicproc/admin.py index 352d24d..3e2a891 100644 --- a/apps/seismicproc/admin.py +++ b/apps/seismicproc/admin.py @@ -8,5 +8,5 @@ from .models.model_earthquake import Earthquake @admin.register(Earthquake) class EarthquakeAdmin(admin.ModelAdmin): #Зоны ordering = ('date_time',) - list_display = ('date_time','latitude','longitude','region') + list_display = ('date_time','latitude','longitude','region','magnitude')