diff --git a/RoutesApp/js_urls.py b/RoutesApp/js_urls.py index 3b1707a..b0da061 100644 --- a/RoutesApp/js_urls.py +++ b/RoutesApp/js_urls.py @@ -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'), + ] \ No newline at end of file diff --git a/RoutesApp/js_views.py b/RoutesApp/js_views.py index a5b9a09..bc80d27 100644 --- a/RoutesApp/js_views.py +++ b/RoutesApp/js_views.py @@ -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 diff --git a/RoutesApp/migrations/0007_rename_select_color_route_highlight_color.py b/RoutesApp/migrations/0007_rename_select_color_route_highlight_color.py new file mode 100644 index 0000000..50a11ef --- /dev/null +++ b/RoutesApp/migrations/0007_rename_select_color_route_highlight_color.py @@ -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', + ), + ] diff --git a/RoutesApp/models.py b/RoutesApp/models.py index b389a04..4c105cf 100644 --- a/RoutesApp/models.py +++ b/RoutesApp/models.py @@ -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: diff --git a/SubscribesApp/admin.py b/SubscribesApp/admin.py index 55057cf..5414d28 100644 --- a/SubscribesApp/admin.py +++ b/SubscribesApp/admin.py @@ -45,7 +45,7 @@ class Admin_SubscribeOption(Admin_Trans_BaseModel): (None, { 'classes': ['wide'], '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 = [ 'id', 'enable', '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', 'auto_continue', 'receive_finish_subscribe_msg', 'order', 'modifiedDT', 'createDT' diff --git a/SubscribesApp/migrations/0005_rename_used_route_select_count_subscribeforuser_used_route_highlight_count.py b/SubscribesApp/migrations/0005_rename_used_route_select_count_subscribeforuser_used_route_highlight_count.py new file mode 100644 index 0000000..90fcf43 --- /dev/null +++ b/SubscribesApp/migrations/0005_rename_used_route_select_count_subscribeforuser_used_route_highlight_count.py @@ -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', + ), + ] diff --git a/SubscribesApp/migrations/0006_rename_allow_route_select_count_subscribeoption_allow_route_highlight_count.py b/SubscribesApp/migrations/0006_rename_allow_route_select_count_subscribeoption_allow_route_highlight_count.py new file mode 100644 index 0000000..b953d28 --- /dev/null +++ b/SubscribesApp/migrations/0006_rename_allow_route_select_count_subscribeoption_allow_route_highlight_count.py @@ -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', + ), + ] diff --git a/SubscribesApp/models.py b/SubscribesApp/models.py index de4a43b..89b599d 100644 --- a/SubscribesApp/models.py +++ b/SubscribesApp/models.py @@ -18,7 +18,7 @@ from datetime import datetime, timedelta class SubscribeOption(BaseModel): 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: verbose_name = _('Опция подписки') @@ -71,7 +71,7 @@ class SubscribeForUser(BaseModel): default=False, verbose_name=_('Получать сообщения о окончании периода')) 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: verbose_name = _('Пользовательская подписка') @@ -94,13 +94,13 @@ class SubscribeForUser(BaseModel): enable=True, rel_subscribes_for_option=self.subscribe ).aggregate( 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({ '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_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 diff --git a/templates/blocks/profile/b_my_routes.html b/templates/blocks/profile/b_my_routes.html index 7a08422..459d9cf 100644 --- a/templates/blocks/profile/b_my_routes.html +++ b/templates/blocks/profile/b_my_routes.html @@ -1,3 +1,3 @@