1.6.12 fix next package for my_routes

This commit is contained in:
SDE
2024-08-13 14:41:11 +03:00
parent a99ffcc9d2
commit 42c2843cab
8 changed files with 72 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ from .models import *
from django.contrib import admin
class Admin_Route(Admin_Trans_BaseModel):
readonly_fields = ['highlight_end_DT', 'rising_DT']
list_display = [
'id', 'owner_type', 'receive_msg_by_email', 'type_transport', 'cargo_type',
'departure_DT', 'from_city', 'from_place',

View File

@@ -118,10 +118,10 @@ def get_city_by_type_transport_and_address_point(type_transport, address_point):
from ReferenceDataApp.models import Airport, City
try:
# if type_transport == 'avia':
# return Airport.objects.get(id=address_point).city
# else:
return City.objects.get(id=address_point)
if type_transport == 'avia':
return Airport.objects.get(id=address_point).city
else:
return City.objects.get(id=address_point)
except Exception as e:
msg = f'get_city_by_type_transport_and_address_point Error = {str(e)}, type_transport = {type_transport}, address_point = {address_point}'
print(msg)

View File

@@ -10,7 +10,7 @@ from django.template import loader, RequestContext
from django.contrib.auth.decorators import login_required
from BaseModels.mailSender import techSendMail
from django.utils.translation import gettext as _
from datetime import datetime
from datetime import datetime, timedelta
from django.template.loader import render_to_string
from django.urls import reverse
from .forms import *
@@ -41,14 +41,20 @@ def highlight_route_ajax(request):
msg = _('Нет доступа к выделению')
return JsonResponse({'errors': msg})
route.highlight_color = '#FF0000'
route.save(update_fields=['highlight_color'])
from SubscribesApp.funcs import get_cur_user_subscribe
user_subscribe = get_cur_user_subscribe(request.user)
user_subscribe.used_route_highlight_count += 1
user_subscribe.save(update_fields=['used_route_highlight_count'])
route.highlight_color = '#FF0000'
highlight_hours = user_subscribe.get_highlight_hours()
route.highlight_end_DT = datetime.now() + timedelta(hours=highlight_hours)
route.save(update_fields=['highlight_color', 'highlight_end_DT'])
Dict = {
'route': route,
}

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.2.2 on 2024-08-13 13:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('RoutesApp', '0007_rename_select_color_route_highlight_color'),
]
operations = [
migrations.AddField(
model_name='route',
name='highlight_end_DT',
field=models.DateTimeField(blank=True, null=True, verbose_name='Дата и время окончания выделения'),
),
]

View File

@@ -71,6 +71,10 @@ class Route(BaseModel):
verbose_name=_('Цвет выделения'),
blank=True, null=True
)
highlight_end_DT = models.DateTimeField(
verbose_name=_('Дата и время окончания выделения'),
blank=True, null=True
)
def __str__(self):
if self.name:

View File

@@ -45,7 +45,8 @@ class Admin_SubscribeOption(Admin_Trans_BaseModel):
(None, {
'classes': ['wide'],
'fields': (
'allow_route_rising_count', 'allow_route_highlight_count'
('allow_route_rising_count',),
('allow_route_highlight_count', 'route_highlight_hours'),
)
}),
)
@@ -53,6 +54,8 @@ class Admin_SubscribeOption(Admin_Trans_BaseModel):
list_display = [
'id', 'enable',
'name',
'allow_route_rising_count',
'allow_route_highlight_count', 'route_highlight_hours',
'order', 'modifiedDT', 'createDT'
]
list_editable = ['enable']

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.2.2 on 2024-08-13 13:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('SubscribesApp', '0006_rename_allow_route_select_count_subscribeoption_allow_route_highlight_count'),
]
operations = [
migrations.AddField(
model_name='subscribeoption',
name='route_highlight_hours',
field=models.IntegerField(default=24, verbose_name='Количество часов выделения цветом объявлений'),
),
]

View File

@@ -17,8 +17,12 @@ from datetime import datetime, timedelta
class SubscribeOption(BaseModel):
allow_route_rising_count = models.IntegerField(verbose_name=_('Количество поднятий объявлений') ,default=0)
allow_route_highlight_count = models.IntegerField(verbose_name=_('Количество выделений объявлений'), default=0)
allow_route_rising_count = models.IntegerField(
verbose_name=_('Количество поднятий объявлений') ,default=0)
allow_route_highlight_count = models.IntegerField(
verbose_name=_('Количество выделений объявлений'), default=0)
route_highlight_hours = models.IntegerField(
verbose_name=_('Количество часов выделения цветом объявлений'), default=24)
class Meta:
verbose_name = _('Опция подписки')
@@ -88,6 +92,14 @@ class SubscribeForUser(BaseModel):
res += f' {str(self.id)}'
return res
def get_highlight_hours(self):
options = self.subscribe.options.filter(
allow_route_highlight_count__gt=0,
)
if options:
return options[0].route_highlight_hours
return 0
def remains_route_adding_options(self):
total_data = SubscribeOption.objects.filter(