0.1.8
fix create route form
This commit is contained in:
@@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError
|
||||
from .models import *
|
||||
|
||||
|
||||
class CreateRouteForm(forms.ModelForm):
|
||||
class RouteForm(forms.ModelForm):
|
||||
from_address_point_txt = forms.CharField(required=True)
|
||||
to_address_point_txt = forms.CharField(required=True)
|
||||
class Meta:
|
||||
@@ -18,7 +18,7 @@ class CreateRouteForm(forms.ModelForm):
|
||||
|
||||
def clean(self):
|
||||
# print('check')
|
||||
cleaned_data = super(CreateRouteForm, self).clean()
|
||||
cleaned_data = super(RouteForm, self).clean()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ def edit_route_ajax(request):
|
||||
msg = f'Недостаточно данных'
|
||||
return JsonResponse({'errors': msg})
|
||||
|
||||
route = Route.objects.get(data['route_id'])
|
||||
route = Route.objects.get(id=data['route_id'])
|
||||
|
||||
form = CreateRouteForm(route)
|
||||
form = CreateRouteForm(instance=route)
|
||||
|
||||
Dict = {
|
||||
'form': form
|
||||
@@ -41,9 +41,11 @@ def edit_route_ajax(request):
|
||||
|
||||
except Exception as e:
|
||||
# form.errors.append({'__all__': f'Ошибка: {str(e)}'})
|
||||
print(str(e))
|
||||
msg = f'Ошибка edit_route = {str(e)}'
|
||||
print(msg)
|
||||
return JsonResponse({'errors': msg})
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_new_route2.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
@@ -52,7 +54,7 @@ def new_route_view_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
form = CreateRouteForm()
|
||||
form = RouteForm()
|
||||
Dict = {
|
||||
'form': form
|
||||
}
|
||||
@@ -60,11 +62,20 @@ def new_route_view_ajax(request):
|
||||
|
||||
errors_off = True
|
||||
|
||||
data = request.POST
|
||||
data = request.POST.dict()
|
||||
if not data and request.body:
|
||||
data = json.loads(request.body)
|
||||
# show_errors = False
|
||||
|
||||
if 'from_address_point' in data:
|
||||
del data['from_address_point']
|
||||
if 'from_address_point_txt' in data:
|
||||
del data['from_address_point_txt']
|
||||
|
||||
if 'to_address_point' in data:
|
||||
del data['to_address_point']
|
||||
if 'to_address_point_txt' in data:
|
||||
del data['to_address_point_txt']
|
||||
|
||||
if 'type_transport' in data:
|
||||
if data['type_transport'] == 'avia':
|
||||
@@ -96,6 +107,11 @@ def new_route_view_ajax(request):
|
||||
('letter', _('Письмо\Документ'))
|
||||
)
|
||||
|
||||
form = RouteForm(data)
|
||||
if not form.is_valid():
|
||||
pass
|
||||
form = RouteForm(initial=form.cleaned_data)
|
||||
|
||||
form.fields['from_place'].choices = transfer_location_choices
|
||||
form.fields['to_place'].choices = transfer_location_choices
|
||||
form.fields['cargo_type'].choices = cargo_type_choices
|
||||
@@ -104,10 +120,10 @@ def new_route_view_ajax(request):
|
||||
form.base_fields['to_place'].choices = transfer_location_choices
|
||||
form.base_fields['cargo_type'].choices = cargo_type_choices
|
||||
|
||||
form = CreateRouteForm(data)
|
||||
# form = CreateRouteForm(initial=data)
|
||||
|
||||
if not form.is_valid():
|
||||
pass
|
||||
# if not form.is_valid():
|
||||
# pass
|
||||
|
||||
Dict = {
|
||||
'form': form,
|
||||
@@ -119,7 +135,7 @@ def new_route_view_ajax(request):
|
||||
# form.errors.append({'__all__': f'Ошибка: {str(e)}'})
|
||||
print(str(e))
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_new_route2.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
@@ -163,10 +179,14 @@ def create_route_ajax(request):
|
||||
|
||||
data = request.POST
|
||||
|
||||
form = CreateRouteForm(data)
|
||||
# obj = Route(data)
|
||||
# form = RouteForm(data=data, instance=obj)
|
||||
|
||||
form = RouteForm(data)
|
||||
if not form.is_valid():
|
||||
form.initial = form.cleaned_data
|
||||
Dict = {'form': form}
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_new_route2.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=400)
|
||||
|
||||
obj = form.save(commit=False)
|
||||
@@ -178,7 +198,7 @@ def create_route_ajax(request):
|
||||
if 'errors' in routes_Dict:
|
||||
form.errors.update(routes_Dict['errors'])
|
||||
Dict = {'form': form}
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_new_route2.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=400)
|
||||
|
||||
html = render_to_string('blocks/profile/b_my_routes.html', routes_Dict, request=request)
|
||||
@@ -197,5 +217,5 @@ def create_route_ajax(request):
|
||||
}
|
||||
}
|
||||
Dict = {'form': errors_Dict}
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
html = render_to_string('blocks/profile/b_new_route2.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=400)
|
||||
287
templates/blocks/profile/b_new_route2.html
Normal file
287
templates/blocks/profile/b_new_route2.html
Normal file
@@ -0,0 +1,287 @@
|
||||
{% load static %}
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/ion.rangeSlider.min.css' %}">
|
||||
|
||||
|
||||
<form class = "new_route" name="new_route" method="post">
|
||||
{% csrf_token %}
|
||||
<div>
|
||||
<label for="id_type_transport">{{ form.fields.type_transport.label }}</label>
|
||||
</div>
|
||||
<div>
|
||||
|
||||
<select
|
||||
onchange="OnSelectionChange(this)"
|
||||
name="type_transport"
|
||||
id="id_type_transport">
|
||||
{% for item in form.fields.type_transport.choices %}
|
||||
<option
|
||||
value="{{ item.0 }}"
|
||||
{% if form.initial.type_transport == item.0 %}
|
||||
selected="selected"
|
||||
{% endif %}>
|
||||
{{ item.1 }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if not errors_off and form.errors and form.errors.type_transport %}
|
||||
<span>{{ form.errors.type_transport }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if form.initial and form.initial.type_transport and form.initial.type_transport != '' %}
|
||||
<hr>
|
||||
<div class="departure_arrival">
|
||||
<div>
|
||||
<label for="id_departure_DT">{{ form.fields.departure_DT.label }}</label>
|
||||
|
||||
<input
|
||||
type="datetime-local"
|
||||
name="departure_DT"
|
||||
{% if form.fields.departure_DT.required %} required{% endif %}
|
||||
id="id_departure_DT"
|
||||
{% if form.initial.departure_DT %}value="{{ form.initial.departure_DT.date|date:"Y-m-d" }}T{{ form.initial.departure_DT.time|date:"H:i" }}"{% endif %}
|
||||
/>
|
||||
|
||||
{% if not errors_off and form.errors and form.errors.departure_DT %}
|
||||
<span>{{ form.errors.departure_DT }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
<label for="id_arrival_DT">{{ form.fields.arrival_DT.label }}</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
name="arrival_DT"
|
||||
{% if form.fields.arrival_DT.required %} required{% endif %}
|
||||
id="id_arrival_DT"
|
||||
{% if form.initial.arrival_DT %}value="{{ form.initial.arrival_DT.date|date:"Y-m-d" }}T{{ form.initial.arrival_DT.time|date:"H:i" }}"{% endif %}
|
||||
/>
|
||||
{% if not errors_off and form.errors and form.errors.arrival_DT %}
|
||||
<span>{{ form.errors.arrival_DT }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="from_to_country">
|
||||
<div class="from_country_container">
|
||||
<label for="id_from_address_point">{{ form.fields.from_address_point.label }}</label>
|
||||
<input type="number" name="from_address_point" id="id_from_address_point" hidden />
|
||||
<input
|
||||
oninput="searchTown(this)"
|
||||
onclick="searchTown(this)"
|
||||
onblur="setTimeout(()=>onblurInputField(event, this), 100)"
|
||||
type="text"
|
||||
list="from_address_point"
|
||||
name="from_address_point_txt"
|
||||
{% if form.fields.from_address_point.required %} required{% endif %}
|
||||
id="id_from_address_point_txt"
|
||||
{% if form.initial.from_address_point_txt %}value="{{ form.initial.from_address_point_txt }}"{% endif %}
|
||||
/>
|
||||
<datalist id="from_address_point">
|
||||
|
||||
</datalist>
|
||||
|
||||
<div class="input_list" name="from_address_point_txt_list">
|
||||
</div>
|
||||
{% if not errors_off and form.errors and form.errors.from_address_point %}
|
||||
<span>{{ form.errors.from_address_point}}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
<label for="id_to_address_point">{{ form.fields.to_address_point.label }}</label>
|
||||
<input type="number" name="to_address_point" id="id_to_address_point" hidden />
|
||||
<input
|
||||
oninput="searchTown(this)"
|
||||
onclick="searchTown(this)"
|
||||
onblur="setTimeout(()=>onblurInputField(event, this), 100)"
|
||||
type="text"
|
||||
name="to_address_point_txt"
|
||||
{% if form.fields.to_address_point.required %} required{% endif %}
|
||||
id="id_to_address_point_txt"
|
||||
{% if form.initial.to_address_point_txt %}value="{{ form.initial.to_address_point_txt}}"{% endif %}
|
||||
|
||||
/>
|
||||
<div class="input_list" name="to_address_point_txt_list">
|
||||
|
||||
</div>
|
||||
{% if not errors_off and form.errors and form.errors.to_address_point %}
|
||||
<span>{{ form.errors.to_address_point }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{# <div>#}
|
||||
{# <label for="id_from_city">{{ form.fields.from_city.label }}</label>#}
|
||||
{# <input type="text" name="from_city"{% if form.fields.from_city.required %} required{% endif %} id="id_from_city">#}
|
||||
{# </div>#}
|
||||
{# <div>#}
|
||||
{# <label for="id_to_city">{{ form.fields.to_city.label }}</label>#}
|
||||
{# <input type="text" name="to_city"{% if form.fields.to_city.required %} required{% endif %} id="id_to_city">#}
|
||||
{# </div>#}
|
||||
<div class="from_to_place">
|
||||
<div>
|
||||
<label for="id_from_place">{{ form.fields.from_place.label }}</label>
|
||||
<select
|
||||
name="from_place"
|
||||
{# onchange="hideErrorMsg(this)"#}
|
||||
id="id_from_place"
|
||||
{% if form.fields.from_place.required %} required{% endif %}>
|
||||
{% for item in form.fields.from_place.choices %}
|
||||
<option
|
||||
value="{{ item.0 }}"{% if form.initial.from_place == item.0 %}
|
||||
selected="selected"{% endif %}>{{ item.1 }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if not errors_off and form.errors and form.errors.from_place %}
|
||||
<span>{{ form.errors.from_place }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
<label for="id_to_place">{{ form.fields.to_place.label }}</label>
|
||||
<select
|
||||
name="to_place"
|
||||
id="id_to_place"
|
||||
{% if form.fields.to_place.required %} required{% endif %}>
|
||||
{% for item in form.fields.to_place.choices %}
|
||||
<option
|
||||
value="{{ item.0 }}"{% if form.initial.to_place == item.0 %}
|
||||
selected="selected"{% endif %}>{{ item.1 }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% if not errors_off and form.errors and form.errors.to_place %}
|
||||
<span>{{ form.errors.to_place }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div>
|
||||
<label for="id_cargo_type">{{ form.fields.cargo_type.label }}</label>
|
||||
</div>
|
||||
{#<div>#}
|
||||
{# <select#}
|
||||
{# multiple#}
|
||||
{# size="5"#}
|
||||
{# name="cargo_type"#}
|
||||
{# id="id_cargo_type"#}
|
||||
{# {% if form.fields.cargo_type.required %} required{% endif %}>#}
|
||||
{# {% for item in form.fields.cargo_type.choices %}#}
|
||||
{# <option#}
|
||||
{# value="{{ item.0 }}"{% if form.fields.cargo_type == item.0 %}#}
|
||||
{# selected="selected"{% endif %}>{{ item.1 }}#}
|
||||
{# </option>#}
|
||||
{# {% endfor %}#}
|
||||
{##}
|
||||
{# </select>#}
|
||||
|
||||
{# </div>#}
|
||||
|
||||
<div class="checkbox_cargo_type">
|
||||
{% for item in form.fields.cargo_type.choices %}
|
||||
<input
|
||||
type="checkbox"
|
||||
name="cargo_type"
|
||||
id="id_cargo_type"
|
||||
{% if form.fields.cargo_type.required %} required{% endif %}
|
||||
value="{{ item.0 }}"
|
||||
{% if form.fields.cargo_type == item.0 %}
|
||||
{% endif %}/>{{ item.1 }}
|
||||
{% endfor %}
|
||||
|
||||
{# <lable for="">#}
|
||||
{##}
|
||||
{# </lable>#}
|
||||
{% if not errors_off and form.errors and form.errors.cargo_type %}
|
||||
<span>{{ form.errors.cargo_type }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="range-slider">
|
||||
<label for="id_weight">{{ form.fields.weight.label }}</label>
|
||||
<input
|
||||
type="text"
|
||||
id="id_weight"
|
||||
{% if form.fields.weight.required %} required{% endif %}
|
||||
name="weight"
|
||||
value=""
|
||||
{% if form.initial.weight %}value="{{ form.initial.weight}}"{% endif %}
|
||||
/>
|
||||
{% if not errors_off and form.errors and form.errors.weight %}
|
||||
<span>{{ form.errors.weight }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
{# <div class="prise-slider-div">#}
|
||||
{# <span class="filter-span">Цена</span>#}
|
||||
{# <div id="slider-range"></div>#}
|
||||
{# <div class="input-control-price">#}
|
||||
{# <div class="slider-range-div-input">#}
|
||||
{# <span class="span-price-placeholder">от</span>#}
|
||||
{# <input min="0" max="1000" type="number" onchange="set_range(this)" class="form-control" name="price" id="control-price-1">#}
|
||||
{# </div>#}
|
||||
{##}
|
||||
{# <div class="slider-range-div-input">#}
|
||||
{# <span class="span-price-placeholder">до</span>#}
|
||||
{# <input min="0" max="1000" type="number" onchange="set_range(this)" class="form-control" name="price" id="control-price-2">#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="phone">
|
||||
<div>
|
||||
<label for="id_phone">{{ form.fields.phone.label }}</label>
|
||||
<input
|
||||
type="text"
|
||||
name="phone"
|
||||
placeholder="{{ form.fields.phone.label }}"
|
||||
{% if form.fields.phone.required %} required{% endif %}
|
||||
id="id_phone"
|
||||
{% if form.initial.phone %}value="{{ form.initial.phone}}"{% endif %}
|
||||
|
||||
/>
|
||||
{% if not errors_off and form.errors and form.errors.phone %}
|
||||
<span>{{ form.errors.phone }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<label for="id_extra_phone">{{ form.fields.extra_phone.label }}</label>
|
||||
<input
|
||||
type="text"
|
||||
name="extra_phone"
|
||||
id="id_extra_phone"
|
||||
placeholder="{{ form.fields.extra_phone.label }}"
|
||||
{% if form.initial.extra_phone %}value="{{ form.initial.extra_phone}}"{% endif %}
|
||||
/>
|
||||
{% if not errors_off and form.errors and form.errors.extra_phone %}
|
||||
<span>{{ form.errors.extra_phone }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div>
|
||||
<label for="id_receive_msg_by_email">{{ form.fields.receive_msg_by_email.label }}</label>
|
||||
<input type="checkbox" name="receive_msg_by_email" id="id_receive_msg_by_email">
|
||||
{% if not errors_off and form.errors and form.errors.receive_msg_by_email %}
|
||||
<span>{{ form.errors.receive_msg_by_email }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="button_register">
|
||||
<button id="registration" onclick="sendRoute(this)"> Разместить объявления </button>
|
||||
</div>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
</form>
|
||||
Reference in New Issue
Block a user