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('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
|
||||
|
||||
|
||||
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):
|
||||
if request.method != 'POST':
|
||||
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=_('Дата и время последнего поднятия'),
|
||||
blank=True, null=True
|
||||
)
|
||||
select_color = ColorField(
|
||||
highlight_color = ColorField(
|
||||
verbose_name=_('Цвет выделения'),
|
||||
blank=True, null=True
|
||||
)
|
||||
@@ -84,6 +84,18 @@ class Route(BaseModel):
|
||||
verbose_name_plural = _(u'Маршруты')
|
||||
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):
|
||||
res = _('Неизвестно')
|
||||
if self.from_city:
|
||||
|
||||
Reference in New Issue
Block a user