1.1.9 funcs for raise and highlight routes
This commit is contained in:
@@ -14,4 +14,7 @@ urlpatterns = [
|
|||||||
path('get_routes/', get_my_routes_ajax, name='get_my_routes_ajax'),
|
path('get_routes/', get_my_routes_ajax, name='get_my_routes_ajax'),
|
||||||
path('find_routes/', find_routes_ajax, name='find_routes_ajax'),
|
path('find_routes/', find_routes_ajax, name='find_routes_ajax'),
|
||||||
|
|
||||||
|
path('raise_route/', raise_route_ajax, name='raise_route_ajax'),
|
||||||
|
path('highlight_route/', highlight_route_ajax, name='highlight_route_ajax'),
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -19,6 +19,72 @@ from GeneralApp.funcs import get_and_set_lang
|
|||||||
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
|
from SubscribesApp.funcs import check_option_in_cur_user_subscribe
|
||||||
|
|
||||||
|
|
||||||
|
def highlight_route_ajax(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
data = request.POST
|
||||||
|
if not data and request.body:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
|
||||||
|
if not data or not 'route_id' in data:
|
||||||
|
msg = _('Недостаточно данных')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
try:
|
||||||
|
route = Route.objects.get(owner=request.user, id=data['route_id'])
|
||||||
|
except Route.DoesNotExist:
|
||||||
|
msg = _('Не найден маршрут')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
if not route.get_permission_for_raise():
|
||||||
|
msg = _('Нет доступа к выделению')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
route.highlight_color = '#FF0000'
|
||||||
|
route.save(update_fields=['highlight_color'])
|
||||||
|
|
||||||
|
Dict = {
|
||||||
|
'route': route,
|
||||||
|
}
|
||||||
|
|
||||||
|
html = render_to_string('widgets/routes/w_my_route.html', Dict, request=request)
|
||||||
|
|
||||||
|
res_Dict = {
|
||||||
|
'html': html
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonResponse(res_Dict)
|
||||||
|
|
||||||
|
|
||||||
|
def raise_route_ajax(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
data = request.POST
|
||||||
|
if not data and request.body:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
|
||||||
|
if not data or not 'route_id' in data:
|
||||||
|
msg = _('Недостаточно данных')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
try:
|
||||||
|
route = Route.objects.get(owner=request.user, id=data['route_id'])
|
||||||
|
except Route.DoesNotExist:
|
||||||
|
msg = _('Не найден маршрут')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
if not route.get_permission_for_raise():
|
||||||
|
msg = _('Нет доступных поднятий')
|
||||||
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
|
route.rising_DT = datetime.now()
|
||||||
|
route.save(update_fields=['rising_DT'])
|
||||||
|
|
||||||
|
return JsonResponse({'status': 'ok'})
|
||||||
|
|
||||||
|
|
||||||
def del_route_ajax(request):
|
def del_route_ajax(request):
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
raise Http404
|
raise Http404
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2024-06-03 02:30
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('RoutesApp', '0006_route_rising_dt_route_select_color_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='route',
|
||||||
|
old_name='select_color',
|
||||||
|
new_name='highlight_color',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -67,7 +67,7 @@ class Route(BaseModel):
|
|||||||
verbose_name=_('Дата и время последнего поднятия'),
|
verbose_name=_('Дата и время последнего поднятия'),
|
||||||
blank=True, null=True
|
blank=True, null=True
|
||||||
)
|
)
|
||||||
select_color = ColorField(
|
highlight_color = ColorField(
|
||||||
verbose_name=_('Цвет выделения'),
|
verbose_name=_('Цвет выделения'),
|
||||||
blank=True, null=True
|
blank=True, null=True
|
||||||
)
|
)
|
||||||
@@ -84,6 +84,18 @@ class Route(BaseModel):
|
|||||||
verbose_name_plural = _(u'Маршруты')
|
verbose_name_plural = _(u'Маршруты')
|
||||||
ordering = ('name',)
|
ordering = ('name',)
|
||||||
|
|
||||||
|
def get_permission_for_raise(self):
|
||||||
|
from SubscribesApp.funcs import get_cur_user_subscribe
|
||||||
|
user_subscribe = get_cur_user_subscribe(self.owner)
|
||||||
|
if not user_subscribe:
|
||||||
|
return False
|
||||||
|
data_Dict = user_subscribe.remains_route_adding_options()
|
||||||
|
if data_Dict['remains_route_rising_count'] > 0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def from_country_n_city_str(self):
|
def from_country_n_city_str(self):
|
||||||
res = _('Неизвестно')
|
res = _('Неизвестно')
|
||||||
if self.from_city:
|
if self.from_city:
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Admin_SubscribeOption(Admin_Trans_BaseModel):
|
|||||||
(None, {
|
(None, {
|
||||||
'classes': ['wide'],
|
'classes': ['wide'],
|
||||||
'fields': (
|
'fields': (
|
||||||
'allow_route_rising_count', 'allow_route_select_count'
|
'allow_route_rising_count', 'allow_route_highlight_count'
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@@ -82,7 +82,7 @@ class Admin_SubscribeForUser(Admin_Trans_BaseModel):
|
|||||||
list_display = [
|
list_display = [
|
||||||
'id', 'enable',
|
'id', 'enable',
|
||||||
'name', 'user', 'subscribe',
|
'name', 'user', 'subscribe',
|
||||||
'used_route_rising_count', 'used_route_select_count',
|
'used_route_rising_count', 'used_route_highlight_count',
|
||||||
'last_paid_DT', 'paid_period_from_DT', 'paid_period_to_DT',
|
'last_paid_DT', 'paid_period_from_DT', 'paid_period_to_DT',
|
||||||
'auto_continue', 'receive_finish_subscribe_msg',
|
'auto_continue', 'receive_finish_subscribe_msg',
|
||||||
'order', 'modifiedDT', 'createDT'
|
'order', 'modifiedDT', 'createDT'
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2024-06-03 02:30
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('SubscribesApp', '0004_subscribeforuser_used_route_rising_count_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='subscribeforuser',
|
||||||
|
old_name='used_route_select_count',
|
||||||
|
new_name='used_route_highlight_count',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2024-06-03 02:43
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('SubscribesApp', '0005_rename_used_route_select_count_subscribeforuser_used_route_highlight_count'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='subscribeoption',
|
||||||
|
old_name='allow_route_select_count',
|
||||||
|
new_name='allow_route_highlight_count',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -18,7 +18,7 @@ from datetime import datetime, timedelta
|
|||||||
class SubscribeOption(BaseModel):
|
class SubscribeOption(BaseModel):
|
||||||
|
|
||||||
allow_route_rising_count = models.IntegerField(verbose_name=_('Количество поднятий объявлений') ,default=0)
|
allow_route_rising_count = models.IntegerField(verbose_name=_('Количество поднятий объявлений') ,default=0)
|
||||||
allow_route_select_count = models.IntegerField(verbose_name=_('Количество выделений объявлений'), default=0)
|
allow_route_highlight_count = models.IntegerField(verbose_name=_('Количество выделений объявлений'), default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Опция подписки')
|
verbose_name = _('Опция подписки')
|
||||||
@@ -71,7 +71,7 @@ class SubscribeForUser(BaseModel):
|
|||||||
default=False, verbose_name=_('Получать сообщения о окончании периода'))
|
default=False, verbose_name=_('Получать сообщения о окончании периода'))
|
||||||
|
|
||||||
used_route_rising_count = models.IntegerField(verbose_name=_('Использовано поднятий объявлений'), default=0)
|
used_route_rising_count = models.IntegerField(verbose_name=_('Использовано поднятий объявлений'), default=0)
|
||||||
used_route_select_count = models.IntegerField(verbose_name=_('Использовано выделений объявлений'), default=0)
|
used_route_highlight_count = models.IntegerField(verbose_name=_('Использовано выделений объявлений'), default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Пользовательская подписка')
|
verbose_name = _('Пользовательская подписка')
|
||||||
@@ -94,13 +94,13 @@ class SubscribeForUser(BaseModel):
|
|||||||
enable=True, rel_subscribes_for_option=self.subscribe
|
enable=True, rel_subscribes_for_option=self.subscribe
|
||||||
).aggregate(
|
).aggregate(
|
||||||
total_route_rising_count = Coalesce(Sum('allow_route_rising_count'), 0),
|
total_route_rising_count = Coalesce(Sum('allow_route_rising_count'), 0),
|
||||||
total_route_select_count = Coalesce(Sum('allow_route_select_count'), 0),
|
total_route_highlight_count = Coalesce(Sum('allow_route_highlight_count'), 0),
|
||||||
)
|
)
|
||||||
total_data.update({
|
total_data.update({
|
||||||
'used_route_rising_count': self.used_route_rising_count,
|
'used_route_rising_count': self.used_route_rising_count,
|
||||||
'used_route_select_count': self.used_route_select_count,
|
'used_route_highlight_count': self.used_route_highlight_count,
|
||||||
'remains_route_rising_count': total_data['total_route_rising_count'] - self.used_route_rising_count,
|
'remains_route_rising_count': total_data['total_route_rising_count'] - self.used_route_rising_count,
|
||||||
'remains_route_select_count': total_data['total_route_select_count'] - self.used_route_select_count,
|
'remains_route_highlight_count': total_data['total_route_highlight_count'] - self.used_route_highlight_count,
|
||||||
})
|
})
|
||||||
return total_data
|
return total_data
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
<div>
|
<div>
|
||||||
{% include 'widgets/w_route_info.html' %}
|
{% include 'blocks/routes/b_my_routes_list.html' %}
|
||||||
</div>
|
</div>
|
||||||
102
templates/blocks/routes/b_my_routes_list.html
Normal file
102
templates/blocks/routes/b_my_routes_list.html
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
{% for route in routes %}
|
||||||
|
|
||||||
|
{% include "widgets/routes/w_my_route.html" %}
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
{#<div class="my_route">#}
|
||||||
|
{# <div class="route_info">#}
|
||||||
|
{# <div class="route_info_about">#}
|
||||||
|
{# <span>#}
|
||||||
|
{# Тип:{{ route.get_cargo_type_display }}#}
|
||||||
|
{# </span>#}
|
||||||
|
{##}
|
||||||
|
{# <span>#}
|
||||||
|
{# Вес:{{ route.weight }} кг#}
|
||||||
|
{# </span>#}
|
||||||
|
{##}
|
||||||
|
{# <span>#}
|
||||||
|
{##}
|
||||||
|
{# {{ route.get_type_transport_display }}#}
|
||||||
|
{# </span>#}
|
||||||
|
{##}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# <div class="route_info_point">#}
|
||||||
|
{##}
|
||||||
|
{# <div>#}
|
||||||
|
{# <div>#}
|
||||||
|
{# <span>#}
|
||||||
|
{# {{ route.from_country.name }}/{{ route.from_city.name }}#}
|
||||||
|
{# </span>#}
|
||||||
|
{##}
|
||||||
|
{# <div></div>#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{##}
|
||||||
|
{# <span>#}
|
||||||
|
{# {{ route.to_country.name }}/{{ route.to_city.name }}#}
|
||||||
|
{# </span>#}
|
||||||
|
{# </div>#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# <div class="route_info_date">#}
|
||||||
|
{# Отправка: {{route.departure_DT }}#}
|
||||||
|
{# Прибытие: {{route.arrival_DT }}#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# <div class="route_info_ft_place">#}
|
||||||
|
{# Откуда заберёт:{{ route.from_place }}#}
|
||||||
|
{# Куда доставит:{{ route.to_place }}#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# #}
|
||||||
|
{# <div class="route_contact">#}
|
||||||
|
{##}
|
||||||
|
{# <h2>Контакты перевозчика:</h2>#}
|
||||||
|
{##}
|
||||||
|
{# <div class="route_contact_name">#}
|
||||||
|
{# {{ route.owner.last_name }} {{ route.owner.first_name }}#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# <div class="route_contact_phone_email">#}
|
||||||
|
{# {{ route.phone }}#}
|
||||||
|
{# <br>#}
|
||||||
|
{# {{ route.extra_phone }}#}
|
||||||
|
{# <br>#}
|
||||||
|
{# {{ route.owner.email }}#}
|
||||||
|
{# </div>#}
|
||||||
|
{# <div class="button_edit_route">#}
|
||||||
|
{# <button onclick="editRoute({{ route.id }})"#}
|
||||||
|
{# id="edit_route">#}
|
||||||
|
{# Редактировать#}
|
||||||
|
{# </button>#}
|
||||||
|
{# </div>#}
|
||||||
|
{# <div class="button_remove_route">#}
|
||||||
|
{# <button#}
|
||||||
|
{# onclick="confirmRemove(this)"#}
|
||||||
|
{# id="remove_route">#}
|
||||||
|
{# Удалить#}
|
||||||
|
{# </button>#}
|
||||||
|
{# </div>#}
|
||||||
|
{##}
|
||||||
|
{# </div>#}
|
||||||
|
{# </div>#}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
{% for route in routes %}
|
{% load static %}
|
||||||
|
{% load i18n %}
|
||||||
{% load static %}
|
|
||||||
{% load i18n %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="carrier-card" data-number-of-route="{{ route.id }}">
|
<div class="carrier-card" data-number-of-route="{{ route.id }}">
|
||||||
@@ -144,103 +141,4 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="clear_both"></div>
|
<div class="clear_both"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
|
|
||||||
{#<div class="my_route">#}
|
|
||||||
{# <div class="route_info">#}
|
|
||||||
{# <div class="route_info_about">#}
|
|
||||||
{# <span>#}
|
|
||||||
{# Тип:{{ route.get_cargo_type_display }}#}
|
|
||||||
{# </span>#}
|
|
||||||
{##}
|
|
||||||
{# <span>#}
|
|
||||||
{# Вес:{{ route.weight }} кг#}
|
|
||||||
{# </span>#}
|
|
||||||
{##}
|
|
||||||
{# <span>#}
|
|
||||||
{##}
|
|
||||||
{# {{ route.get_type_transport_display }}#}
|
|
||||||
{# </span>#}
|
|
||||||
{##}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# <div class="route_info_point">#}
|
|
||||||
{##}
|
|
||||||
{# <div>#}
|
|
||||||
{# <div>#}
|
|
||||||
{# <span>#}
|
|
||||||
{# {{ route.from_country.name }}/{{ route.from_city.name }}#}
|
|
||||||
{# </span>#}
|
|
||||||
{##}
|
|
||||||
{# <div></div>#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{##}
|
|
||||||
{# <span>#}
|
|
||||||
{# {{ route.to_country.name }}/{{ route.to_city.name }}#}
|
|
||||||
{# </span>#}
|
|
||||||
{# </div>#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# <div class="route_info_date">#}
|
|
||||||
{# Отправка: {{route.departure_DT }}#}
|
|
||||||
{# Прибытие: {{route.arrival_DT }}#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# <div class="route_info_ft_place">#}
|
|
||||||
{# Откуда заберёт:{{ route.from_place }}#}
|
|
||||||
{# Куда доставит:{{ route.to_place }}#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# #}
|
|
||||||
{# <div class="route_contact">#}
|
|
||||||
{##}
|
|
||||||
{# <h2>Контакты перевозчика:</h2>#}
|
|
||||||
{##}
|
|
||||||
{# <div class="route_contact_name">#}
|
|
||||||
{# {{ route.owner.last_name }} {{ route.owner.first_name }}#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# <div class="route_contact_phone_email">#}
|
|
||||||
{# {{ route.phone }}#}
|
|
||||||
{# <br>#}
|
|
||||||
{# {{ route.extra_phone }}#}
|
|
||||||
{# <br>#}
|
|
||||||
{# {{ route.owner.email }}#}
|
|
||||||
{# </div>#}
|
|
||||||
{# <div class="button_edit_route">#}
|
|
||||||
{# <button onclick="editRoute({{ route.id }})"#}
|
|
||||||
{# id="edit_route">#}
|
|
||||||
{# Редактировать#}
|
|
||||||
{# </button>#}
|
|
||||||
{# </div>#}
|
|
||||||
{# <div class="button_remove_route">#}
|
|
||||||
{# <button#}
|
|
||||||
{# onclick="confirmRemove(this)"#}
|
|
||||||
{# id="remove_route">#}
|
|
||||||
{# Удалить#}
|
|
||||||
{# </button>#}
|
|
||||||
{# </div>#}
|
|
||||||
{##}
|
|
||||||
{# </div>#}
|
|
||||||
{# </div>#}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user