0.7.19
profile static pages
This commit is contained in:
@@ -1,4 +1,88 @@
|
||||
from .models import *
|
||||
from .forms import *
|
||||
from django.utils.translation import gettext as _
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
def get_profile_new_route_page_html(request, data):
|
||||
|
||||
form = RouteForm()
|
||||
Dict = {
|
||||
'form': form
|
||||
}
|
||||
try:
|
||||
|
||||
errors_off = True
|
||||
|
||||
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':
|
||||
transfer_location_choices = (
|
||||
('airport', _('В аэропорту')),
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('passenger', _('Пассажир')),
|
||||
('cargo', _('Груз')),
|
||||
('parcel', _('Бандероль')),
|
||||
('package', _('Посылка')),
|
||||
('letter', _('Письмо\Документ'))
|
||||
)
|
||||
|
||||
|
||||
else:
|
||||
transfer_location_choices = (
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('cargo', _('Груз')),
|
||||
('parcel', _('Бандероль')),
|
||||
('package', _('Посылка')),
|
||||
('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
|
||||
|
||||
form.base_fields['from_place'].choices = transfer_location_choices
|
||||
form.base_fields['to_place'].choices = transfer_location_choices
|
||||
form.base_fields['cargo_type'].choices = cargo_type_choices
|
||||
|
||||
# form = CreateRouteForm(initial=data)
|
||||
|
||||
# if not form.is_valid():
|
||||
# pass
|
||||
|
||||
Dict = {
|
||||
'form': form,
|
||||
'errors_off': errors_off
|
||||
}
|
||||
|
||||
# print(form)
|
||||
except Exception as e:
|
||||
# form.errors.append({'__all__': f'Ошибка: {str(e)}'})
|
||||
print(str(e))
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
return html
|
||||
|
||||
|
||||
def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
||||
@@ -14,6 +98,18 @@ def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
||||
print(msg)
|
||||
return None
|
||||
|
||||
|
||||
def get_profile_my_routes_page_content_html(request):
|
||||
routes_Dict = get_routes_Dict(request.user)
|
||||
if 'errors' in routes_Dict:
|
||||
msg = f'get_my_routes_page_content_html errors = {str(routes_Dict)}'
|
||||
print(msg)
|
||||
return msg
|
||||
|
||||
html = render_to_string('blocks/profile/b_my_routes.html', routes_Dict, request=request)
|
||||
return html
|
||||
|
||||
|
||||
def get_routes_Dict(user=None, data=None):
|
||||
from ReferenceDataApp.models import Airport, Country, City
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ urlpatterns = [
|
||||
|
||||
path('edit_route/', edit_route_ajax, name='edit_route_ajax'),
|
||||
|
||||
path('get_routes/', get_routes_ajax, name='get_routes_ajax'),
|
||||
path('get_routes/', get_my_routes_ajax, name='get_my_routes_ajax'),
|
||||
path('find_routes/', find_routes_ajax, name='find_routes_ajax'),
|
||||
|
||||
]
|
||||
@@ -61,10 +61,10 @@ def new_route_view_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
form = RouteForm()
|
||||
Dict = {
|
||||
'form': form
|
||||
}
|
||||
# form = RouteForm()
|
||||
# Dict = {
|
||||
# 'form': form
|
||||
# }
|
||||
try:
|
||||
|
||||
errors_off = True
|
||||
@@ -74,75 +74,17 @@ def new_route_view_ajax(request):
|
||||
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':
|
||||
transfer_location_choices = (
|
||||
('airport', _('В аэропорту')),
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('passenger', _('Пассажир')),
|
||||
('cargo', _('Груз')),
|
||||
('parcel', _('Бандероль')),
|
||||
('package', _('Посылка')),
|
||||
('letter', _('Письмо\Документ'))
|
||||
)
|
||||
html = get_profile_new_route_page_html(request, data)
|
||||
|
||||
|
||||
else:
|
||||
transfer_location_choices = (
|
||||
('city', _('По городу')),
|
||||
('other', _('По договоренности'))
|
||||
)
|
||||
|
||||
cargo_type_choices = (
|
||||
('cargo', _('Груз')),
|
||||
('parcel', _('Бандероль')),
|
||||
('package', _('Посылка')),
|
||||
('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
|
||||
|
||||
form.base_fields['from_place'].choices = transfer_location_choices
|
||||
form.base_fields['to_place'].choices = transfer_location_choices
|
||||
form.base_fields['cargo_type'].choices = cargo_type_choices
|
||||
|
||||
# form = CreateRouteForm(initial=data)
|
||||
|
||||
# if not form.is_valid():
|
||||
# pass
|
||||
|
||||
Dict = {
|
||||
'form': form,
|
||||
'errors_off': errors_off
|
||||
}
|
||||
|
||||
# print(form)
|
||||
except Exception as e:
|
||||
# form.errors.append({'__all__': f'Ошибка: {str(e)}'})
|
||||
print(str(e))
|
||||
msg = f'new_route_view_ajax Error = {str(e)}'
|
||||
print(msg)
|
||||
html = msg
|
||||
|
||||
html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
|
||||
# html = render_to_string('blocks/profile/b_new_route.html', Dict, request=request)
|
||||
return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
@@ -186,7 +128,7 @@ def find_routes_ajax(request):
|
||||
return JsonResponse(errors_Dict, status=400)
|
||||
|
||||
|
||||
def get_routes_ajax(request):
|
||||
def get_my_routes_ajax(request):
|
||||
|
||||
|
||||
if request.method != 'POST':
|
||||
|
||||
Reference in New Issue
Block a user