Энергия НК (реперы)
This commit is contained in:
parent
161f1017d2
commit
5081ff3492
@ -3,10 +3,20 @@ from django import forms
|
||||
from apps.geoproc.models.model_point import Point
|
||||
from apps.geoproc.models.model_obstation import ObStation
|
||||
|
||||
|
||||
class PointForm(forms.ModelForm):
|
||||
name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control','autofocus':''}))
|
||||
obstation = forms.ModelChoiceField(queryset = ObStation.objects.all(),widget=forms.Select(attrs={'class':'form-control select2'}))
|
||||
name = forms.CharField(
|
||||
widget=forms.TextInput(
|
||||
attrs={'class': 'form-control', 'autofocus': ''}
|
||||
)
|
||||
)
|
||||
obstation = forms.ModelChoiceField(
|
||||
queryset=ObStation.objects.all(),
|
||||
widget=forms.Select(
|
||||
attrs={'class': 'form-control select2', 'id': 'id_obstation'}
|
||||
)
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model=Point
|
||||
fields = ('id','name','obstation')
|
||||
model = Point
|
||||
fields = ('id', 'name', 'obstation')
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<!-- path_to_your_template/point_dropdown_list_options.html -->
|
||||
<option value="">---------</option>
|
||||
{% for point in points %}
|
||||
<option value="{{ point.id }}">{{ point.name }}</option>
|
||||
{% for item in qs %}
|
||||
<option value="{{ item.id }}">{{ item.name }}</option>
|
||||
{% endfor %}
|
||||
@ -4,78 +4,99 @@
|
||||
|
||||
|
||||
{% block header_link %}
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet" href="{% static 'plugins/datatables/dataTables.bootstrap.css' %}?ver={% settings_value 'APP_VER' %}">
|
||||
<!-- DataTables -->
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'plugins/datatables/dataTables.bootstrap.css' %}?ver={% settings_value 'APP_VER' %}">
|
||||
|
||||
{% endblock header_link %}
|
||||
|
||||
|
||||
|
||||
{% block content %}
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h4>Репер</h4>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="/geoproc/">Главная</a></li>
|
||||
<li class="breadcrumb-item"><a href="/geoproc/point/list/">Список реперов </a></li>
|
||||
{% if point %}
|
||||
<li class="breadcrumb-item active">{{point.name}}</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active">Новый репер</li>
|
||||
{% endif %}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.container-fluid -->
|
||||
</section>
|
||||
|
||||
<section class="content">
|
||||
<form action="/geoproc/point/save/" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" value="{{mt}}" name="mt">
|
||||
<input type="hidden" value="{{point.id}}" name="id">
|
||||
<section class="content-header">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<!-- /.col -->
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header p-2">
|
||||
</div><!-- /.card-header -->
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label for="id_tabnomer" class="col-sm-2 col-form-label">Наблюдательная станция : </label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.obstation }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="id_tabnomer" class="col-sm-2 col-form-label">Наименование : </label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.name }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.tab-content -->
|
||||
</div><!-- /.card-body -->
|
||||
<div class="card-footer">
|
||||
<button id="btnok" type="submit" class="btn bg-gradient-primary">Сохранить</button>
|
||||
<a href="/geoproc/point/list/" type="button" class="btn btn-default float-right">Отмена</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.nav-tabs-custom -->
|
||||
<div class="row mb-2">
|
||||
<div class="col-sm-6">
|
||||
<h4>Репер</h4>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="{% url 'geoproc:geoproc_main_with_arg' sector.id %}">Главная</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'geoproc:point_list' sector.id %}">Список
|
||||
реперов</a></li>
|
||||
{% if point %}
|
||||
<li class="breadcrumb-item active">{{ point.name }}</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active">Новый репер</li>
|
||||
{% endif %}
|
||||
</ol>
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
</div><!-- /.container-fluid -->
|
||||
</form>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<section class="content">
|
||||
<form action="{% url 'geoproc:point_save' sector.id %}" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" value="{{ mt }}" name="mt">
|
||||
<input type="hidden" value="{{ point.id }}" name="id">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<!-- /.col -->
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header p-2">
|
||||
</div><!-- /.card-header -->
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label for="id_tabnomer" class="col-sm-2 col-form-label">Наблюдательная станция
|
||||
: </label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.obstation }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="id_tabnomer" class="col-sm-2 col-form-label">Наименование : </label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.name }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.tab-content -->
|
||||
</div><!-- /.card-body -->
|
||||
<div class="card-footer">
|
||||
<button id="btnok" type="submit" class="btn bg-gradient-primary">Сохранить</button>
|
||||
<a href="{% url 'geoproc:point_list' sector.id %}" type="button"
|
||||
class="btn btn-default float-right">Отмена</a>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.nav-tabs-custom -->
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
</div><!-- /.container-fluid -->
|
||||
</form>
|
||||
</section>
|
||||
{% endblock %}
|
||||
{% block script_footer %}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const response = await fetch('{% url "geoproc:get_obstations_by_sector" sector.id %}');
|
||||
const data = await response.json();
|
||||
|
||||
// Получаем ID текущей выбранной станции
|
||||
const selectedObstationId = parseInt('{{ point.obstation.id|default:None }}');
|
||||
|
||||
// Обновляем HTML с новым списком опций
|
||||
$('#id_obstation').html(data);
|
||||
|
||||
// Если есть выбранная станция, устанавливаем её как выбранную в списке
|
||||
if (selectedObstationId) {
|
||||
$('#id_obstation').val(selectedObstationId).change();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock script_footer %}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<ol class="breadcrumb float-sm-right">
|
||||
<li class="breadcrumb-item"><a href="/geoproc/">Главная</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'geoproc:geoproc_main_with_arg' sector.id %}">Главная</a></li>
|
||||
<li class="breadcrumb-item active">Список реперов</li>
|
||||
</ol>
|
||||
</div>
|
||||
@ -34,7 +34,7 @@
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="card-header text-sm">
|
||||
<a href="../add/" type="button" class="btn bg-gradient-primary float-left"
|
||||
<a href="{% url 'geoproc:point_add' sector.id %}" type="button" class="btn bg-gradient-primary float-left"
|
||||
style="margin-right:20px;">Добавить</a>
|
||||
{% block pagination %}
|
||||
{% if is_paginated %}
|
||||
@ -103,7 +103,7 @@ $(document).ready(function() {
|
||||
{% for point in catalog.sorted_points %}
|
||||
{
|
||||
text: "{{ point.name }}",
|
||||
href: "/geoproc/point/edit/?id={{ point.id }}"
|
||||
href: "{% url 'geoproc:point_edit' sector.id %}?id={{ point.id }}"
|
||||
}
|
||||
{% if not forloop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
@ -29,12 +29,13 @@ urlpatterns = [
|
||||
path('sector/<int:pk>/obstation/add/', views_obstation.obstation_add, name='obstation_add'),
|
||||
path('sector/<int:pk>/obstation/edit/', views_obstation.obstation_edit, name='obstation_edit'),
|
||||
path('sector/<int:pk>/obstation/save/', views_obstation.obstation_save, name='obstation_save'),
|
||||
path('sector/<int:pk>/obstations/', views_obstation.get_obstations_by_sector, name='get_obstations_by_sector'),
|
||||
|
||||
# Реперы
|
||||
path('point/list/', views_point.point_list, name='point_list'),
|
||||
path('point/add/', views_point.point_add, name='point_add'),
|
||||
path('point/edit/', views_point.point_edit, name='point_edit'),
|
||||
path('point/save/', views_point.point_save, name='point_save'),
|
||||
path('sector/<int:pk>/point/list/', views_point.point_list, name='point_list'),
|
||||
path('sector/<int:pk>/point/add/', views_point.point_add, name='point_add'),
|
||||
path('sector/<int:pk>/point/edit/', views_point.point_edit, name='point_edit'),
|
||||
path('sector/<int:pk>/point/save/', views_point.point_save, name='point_save'),
|
||||
|
||||
# Мониторинг (точки)
|
||||
path('monitoring/list/', views_monitoring_point.monitoring_list, name='monitoring_list'),
|
||||
|
||||
@ -190,5 +190,5 @@ def main_index(request):
|
||||
def get_points(request):
|
||||
obstation_id = request.GET.get('obstation_id')
|
||||
points = sorted(Point.objects.filter(obstation_id=obstation_id), key=lambda point: natural_sort_key(point.name))
|
||||
html = render_to_string('includes/dropdown.html', {'points': points})
|
||||
html = render_to_string('includes/dropdown.html', {'qs': points})
|
||||
return JsonResponse(html, safe=False)
|
||||
@ -6,9 +6,10 @@ import json
|
||||
|
||||
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.template.loader import render_to_string
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.shortcuts import redirect
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
@ -18,6 +19,7 @@ from django.contrib.auth.models import User
|
||||
from apps.geoproc.models.model_obstation import ObStation
|
||||
from apps.geoproc.forms.form_obstation import ObStationForm
|
||||
from apps.geoproc.models.model_sector import Sector
|
||||
from apps.util.natsort import natural_sort_key
|
||||
|
||||
from sabron.util import logging
|
||||
from apps.util import generalmodule
|
||||
@ -168,3 +170,11 @@ def main_index(request):
|
||||
return render(request,'geoproc_main.html', context)
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
@never_cache
|
||||
def get_obstations_by_sector(request, pk):
|
||||
sector = get_object_or_404(Sector, id=pk)
|
||||
obstations = sorted(ObStation.objects.filter(sector=sector),
|
||||
key=lambda obstation: natural_sort_key(obstation.name))
|
||||
html = render_to_string('includes/dropdown.html', {'qs': obstations})
|
||||
return JsonResponse(html, safe=False)
|
||||
@ -4,10 +4,11 @@ import os
|
||||
import io
|
||||
import json
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.template.loader import render_to_string
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.shortcuts import redirect
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
@ -18,6 +19,7 @@ from apps.general.views import settingsmodule
|
||||
from apps.geoproc.models.model_obstation import ObStation
|
||||
from apps.geoproc.models.model_point import Point
|
||||
from apps.geoproc.forms.form_point import PointForm
|
||||
from apps.geoproc.models.model_sector import Sector
|
||||
from apps.util.natsort import natural_sort_key
|
||||
|
||||
from sabron.util import logging
|
||||
@ -26,11 +28,13 @@ from apps.util import generalmodule
|
||||
|
||||
@login_required(login_url='/')
|
||||
@never_cache
|
||||
def point_edit(request):
|
||||
def point_edit(request, pk):
|
||||
try:
|
||||
sector = get_object_or_404(Sector, id=pk)
|
||||
context = generalmodule.get_context_template()
|
||||
param_post = request.POST.dict()
|
||||
param_get = request.GET.dict()
|
||||
context['sector'] = sector
|
||||
|
||||
if request.method == "GET":
|
||||
point = Point.objects.get(id=param_get['id'])
|
||||
@ -56,8 +60,9 @@ def point_edit(request):
|
||||
|
||||
@login_required(login_url='/')
|
||||
@never_cache
|
||||
def point_save(request):
|
||||
def point_save(request, pk):
|
||||
try:
|
||||
sector = get_object_or_404(Sector, id=pk)
|
||||
param = request.POST.dict()
|
||||
if request.method == "POST":
|
||||
if param['id'] == '':
|
||||
@ -65,36 +70,42 @@ def point_save(request):
|
||||
else:
|
||||
point = Point.objects.get(id=param['id'])
|
||||
form = PointForm(request.POST, instance=point)
|
||||
|
||||
if form.is_valid():
|
||||
point = form.save(commit=False)
|
||||
point.sector = sector
|
||||
point.save()
|
||||
context = generalmodule.get_context_template()
|
||||
context.update({
|
||||
'form': form,
|
||||
'mt': 'edit',
|
||||
'sector': sector
|
||||
})
|
||||
return redirect('/geoproc/point/list/')
|
||||
return redirect('geoproc:point_list', pk=sector.id)
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
|
||||
@login_required(login_url='/')
|
||||
@never_cache
|
||||
def point_add(request):
|
||||
def point_add(request, pk):
|
||||
try:
|
||||
sector = get_object_or_404(Sector, id=pk)
|
||||
param = request.POST.dict()
|
||||
if request.method == "POST":
|
||||
form = PointForm(request.POST)
|
||||
if form.is_valid():
|
||||
client = form.save(commit=False)
|
||||
client.save()
|
||||
return redirect('/geoproc/point/list/')
|
||||
point = form.save(commit=False)
|
||||
point.sector = sector
|
||||
point.save()
|
||||
return redirect('geoproc:point_list')
|
||||
else:
|
||||
form = PointForm()
|
||||
context = generalmodule.get_context_template()
|
||||
context.update({
|
||||
'form': form,
|
||||
'mt': 'add',
|
||||
'sector': sector
|
||||
})
|
||||
return render(request, 'point_edit.html', context)
|
||||
except Exception as err:
|
||||
@ -103,18 +114,21 @@ def point_add(request):
|
||||
|
||||
@login_required(login_url='/')
|
||||
@never_cache
|
||||
def point_list(request):
|
||||
def point_list(request, pk):
|
||||
try:
|
||||
sector = get_object_or_404(Sector, id=pk)
|
||||
param = request.GET.dict()
|
||||
# catalog_list=Point.objects.order_by("obstation").all()
|
||||
catalog_list = ObStation.objects.prefetch_related(
|
||||
'point_set').order_by("name")
|
||||
for catalog in catalog_list:
|
||||
obstation_list = (ObStation.objects
|
||||
.prefetch_related('point_set')
|
||||
.order_by("name")
|
||||
.filter(sector=sector))
|
||||
for catalog in obstation_list:
|
||||
catalog.sorted_points = sorted(catalog.point_set.all(),
|
||||
key=lambda point: natural_sort_key(
|
||||
point.name))
|
||||
catalog_count = catalog_list.count()
|
||||
paginator = Paginator(catalog_list, 50)
|
||||
catalog_count = obstation_list.count()
|
||||
paginator = Paginator(obstation_list, 50)
|
||||
page_number = request.GET.get('page', 1)
|
||||
page = paginator.get_page(page_number)
|
||||
num_pages = page.paginator.num_pages
|
||||
@ -141,6 +155,7 @@ def point_list(request):
|
||||
next_url = ''
|
||||
context = generalmodule.get_context_template()
|
||||
context.update({
|
||||
"sector": sector,
|
||||
'page_object': page,
|
||||
'is_paginated': page.has_other_pages(),
|
||||
'perv_url': perv_url,
|
||||
@ -156,4 +171,3 @@ def point_list(request):
|
||||
return render(request, 'point_list.html', context)
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user