Merge pull request 'dev' (#11) from dev into main
Reviewed-on: sysadminix/tripwithbonus#11
This commit is contained in:
@@ -22,8 +22,8 @@ def test_code(request):
|
|||||||
|
|
||||||
res = None
|
res = None
|
||||||
|
|
||||||
from ReferenceDataApp.funcs import parse_data
|
# from ReferenceDataApp.funcs import parse_data
|
||||||
parse_data()
|
# parse_data()
|
||||||
|
|
||||||
# from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
# from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
||||||
# send_mail_for_user_subscribes_that_is_going_to_finish()
|
# send_mail_for_user_subscribes_that_is_going_to_finish()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from .models import *
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
class Admin_Route(Admin_Trans_BaseModel):
|
class Admin_Route(Admin_Trans_BaseModel):
|
||||||
|
readonly_fields = ['highlight_end_DT', 'rising_DT']
|
||||||
list_display = [
|
list_display = [
|
||||||
'id', 'owner_type', 'receive_msg_by_email', 'type_transport', 'cargo_type',
|
'id', 'owner_type', 'receive_msg_by_email', 'type_transport', 'cargo_type',
|
||||||
'departure_DT', 'from_city', 'from_place',
|
'departure_DT', 'from_city', 'from_place',
|
||||||
|
|||||||
@@ -109,9 +109,9 @@ def get_profile_new_route_page_html(request, data):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def get_country_n_city_str_by_type_transport_and_address_point(type_transport, address_point):
|
# def get_country_n_city_str_by_type_transport_and_address_point(type_transport, address_point):
|
||||||
city = get_city_by_type_transport_and_address_point(type_transport, address_point)
|
# city = get_city_by_type_transport_and_address_point(type_transport, address_point)
|
||||||
return city.get_country_n_city_str()
|
# return city.get_country_n_city_str()
|
||||||
|
|
||||||
|
|
||||||
def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
||||||
@@ -127,6 +127,16 @@ def get_city_by_type_transport_and_address_point(type_transport, address_point):
|
|||||||
print(msg)
|
print(msg)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_city_by_address_point(address_point):
|
||||||
|
from ReferenceDataApp.models import Airport, City
|
||||||
|
|
||||||
|
try:
|
||||||
|
return City.objects.get(id=address_point)
|
||||||
|
except Exception as e:
|
||||||
|
msg = f'get_city_by_address_point Error = {str(e)}, address_point = {address_point}'
|
||||||
|
print(msg)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_profile_my_routes_page_content_html(request):
|
def get_profile_my_routes_page_content_html(request):
|
||||||
routes_Dict = get_routes_Dict(request.user)
|
routes_Dict = get_routes_Dict(request.user)
|
||||||
@@ -209,16 +219,19 @@ def get_routes_Dict(user=None, data=None):
|
|||||||
):
|
):
|
||||||
kwargs.update({key: val})
|
kwargs.update({key: val})
|
||||||
|
|
||||||
if key == 'from_address_point':
|
if key == 'from_address_point': # в from_address_point всегда город
|
||||||
city = get_city_by_type_transport_and_address_point(type_transport, val)
|
# city = get_city_by_type_transport_and_address_point(type_transport, val)
|
||||||
|
city = get_city_by_address_point(val)
|
||||||
kwargs.update({f'from_city': city})
|
kwargs.update({f'from_city': city})
|
||||||
|
|
||||||
|
|
||||||
res_Dict.update({
|
res_Dict.update({
|
||||||
'from_address_point_txt': city.get_country_n_city_str()
|
'from_address_point_txt': city.get_country_n_city_str()
|
||||||
})
|
})
|
||||||
|
|
||||||
if key == 'to_address_point':
|
if key == 'to_address_point': # в to_address_point всегда город
|
||||||
city = get_city_by_type_transport_and_address_point(type_transport, val)
|
# city = get_city_by_type_transport_and_address_point(type_transport, val)
|
||||||
|
city = get_city_by_address_point(val)
|
||||||
kwargs.update({f'to_city': city})
|
kwargs.update({f'to_city': city})
|
||||||
res_Dict.update({
|
res_Dict.update({
|
||||||
'to_address_point_txt': city.get_country_n_city_str()
|
'to_address_point_txt': city.get_country_n_city_str()
|
||||||
@@ -236,14 +249,14 @@ def get_routes_Dict(user=None, data=None):
|
|||||||
# ).order_by(
|
# ).order_by(
|
||||||
# '-rising_DT', '-departure_DT', '-arrival_DT', '-modifiedDT'
|
# '-rising_DT', '-departure_DT', '-arrival_DT', '-modifiedDT'
|
||||||
# )
|
# )
|
||||||
routes = Route.objects.exclude(
|
# routes = Route.objects.exclude(
|
||||||
rising_DT=None
|
# rising_DT=None
|
||||||
).filter(
|
# ).filter(
|
||||||
departure_DT__lt=datetime.now()
|
# departure_DT__lt=datetime.now()
|
||||||
)
|
# )
|
||||||
routes.update(
|
# routes.update(
|
||||||
rising_DT=None
|
# rising_DT=None
|
||||||
)
|
# )
|
||||||
|
|
||||||
routes = Route.objects.filter(
|
routes = Route.objects.filter(
|
||||||
**kwargs
|
**kwargs
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from django.template import loader, RequestContext
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from BaseModels.mailSender import techSendMail
|
from BaseModels.mailSender import techSendMail
|
||||||
from django.utils.translation import gettext as _
|
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.template.loader import render_to_string
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .forms import *
|
from .forms import *
|
||||||
@@ -41,14 +41,20 @@ def highlight_route_ajax(request):
|
|||||||
msg = _('Нет доступа к выделению')
|
msg = _('Нет доступа к выделению')
|
||||||
return JsonResponse({'errors': msg})
|
return JsonResponse({'errors': msg})
|
||||||
|
|
||||||
route.highlight_color = '#FF0000'
|
|
||||||
route.save(update_fields=['highlight_color'])
|
|
||||||
|
|
||||||
from SubscribesApp.funcs import get_cur_user_subscribe
|
from SubscribesApp.funcs import get_cur_user_subscribe
|
||||||
user_subscribe = get_cur_user_subscribe(request.user)
|
user_subscribe = get_cur_user_subscribe(request.user)
|
||||||
user_subscribe.used_route_highlight_count += 1
|
user_subscribe.used_route_highlight_count += 1
|
||||||
user_subscribe.save(update_fields=['used_route_highlight_count'])
|
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 = {
|
Dict = {
|
||||||
'route': route,
|
'route': route,
|
||||||
}
|
}
|
||||||
@@ -293,8 +299,12 @@ def get_my_routes_ajax(request):
|
|||||||
|
|
||||||
lang = get_and_set_lang(request)
|
lang = get_and_set_lang(request)
|
||||||
|
|
||||||
|
data = request.POST.dict()
|
||||||
|
if not data and request.body:
|
||||||
|
data = json.loads(request.body)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
routes_Dict = get_routes_Dict(request.user)
|
routes_Dict = get_routes_Dict(request.user, data)
|
||||||
if 'errors' in routes_Dict:
|
if 'errors' in routes_Dict:
|
||||||
return JsonResponse(routes_Dict, status=400)
|
return JsonResponse(routes_Dict, status=400)
|
||||||
|
|
||||||
|
|||||||
18
RoutesApp/migrations/0008_route_highlight_end_dt.py
Normal file
18
RoutesApp/migrations/0008_route_highlight_end_dt.py
Normal 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='Дата и время окончания выделения'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -71,6 +71,10 @@ class Route(BaseModel):
|
|||||||
verbose_name=_('Цвет выделения'),
|
verbose_name=_('Цвет выделения'),
|
||||||
blank=True, null=True
|
blank=True, null=True
|
||||||
)
|
)
|
||||||
|
highlight_end_DT = models.DateTimeField(
|
||||||
|
verbose_name=_('Дата и время окончания выделения'),
|
||||||
|
blank=True, null=True
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.name:
|
if self.name:
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ class Admin_SubscribeOption(Admin_Trans_BaseModel):
|
|||||||
(None, {
|
(None, {
|
||||||
'classes': ['wide'],
|
'classes': ['wide'],
|
||||||
'fields': (
|
'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 = [
|
list_display = [
|
||||||
'id', 'enable',
|
'id', 'enable',
|
||||||
'name',
|
'name',
|
||||||
|
'allow_route_rising_count',
|
||||||
|
'allow_route_highlight_count', 'route_highlight_hours',
|
||||||
'order', 'modifiedDT', 'createDT'
|
'order', 'modifiedDT', 'createDT'
|
||||||
]
|
]
|
||||||
list_editable = ['enable']
|
list_editable = ['enable']
|
||||||
|
|||||||
@@ -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='Количество часов выделения цветом объявлений'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -17,8 +17,12 @@ 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(
|
||||||
allow_route_highlight_count = models.IntegerField(verbose_name=_('Количество выделений объявлений'), default=0)
|
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:
|
class Meta:
|
||||||
verbose_name = _('Опция подписки')
|
verbose_name = _('Опция подписки')
|
||||||
@@ -88,6 +92,14 @@ class SubscribeForUser(BaseModel):
|
|||||||
res += f' {str(self.id)}'
|
res += f' {str(self.id)}'
|
||||||
return res
|
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):
|
def remains_route_adding_options(self):
|
||||||
total_data = SubscribeOption.objects.filter(
|
total_data = SubscribeOption.objects.filter(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ function load_routes (el,news=null,incrase,owner_type) {
|
|||||||
if (!news){
|
if (!news){
|
||||||
local_page_iterator = page_iterator
|
local_page_iterator = page_iterator
|
||||||
}
|
}
|
||||||
|
let check_url = (window.location.href.indexOf("my_routes") > -1)
|
||||||
let number_last_route = el.id
|
let number_last_route = el.id
|
||||||
// let incrase = 2
|
// let incrase = 2
|
||||||
// if (!news){
|
// if (!news){
|
||||||
@@ -20,13 +21,20 @@ function load_routes (el,news=null,incrase,owner_type) {
|
|||||||
}
|
}
|
||||||
let get_url = ""
|
let get_url = ""
|
||||||
let url_ajax = "get_articles_block/"
|
let url_ajax = "get_articles_block/"
|
||||||
if (!news){
|
if (!news && !check_url ){
|
||||||
let list = forloop_func_form(data_d,"get",get_url)
|
let list = forloop_func_form(data_d,"get",get_url)
|
||||||
data_d = list[0]
|
data_d = list[0]
|
||||||
get_url = list[1]
|
get_url = list[1]
|
||||||
url_ajax = "routes/find_routes/"
|
url_ajax = "routes/find_routes/"
|
||||||
|
|
||||||
|
} else if (check_url) {
|
||||||
|
let list = forloop_func_form(data_d,"get",get_url)
|
||||||
|
data_d = list[0]
|
||||||
|
get_url = list[1]
|
||||||
|
url_ajax = "routes/get_routes/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let loader = document.querySelector(".loader_f_loading_routes")
|
let loader = document.querySelector(".loader_f_loading_routes")
|
||||||
loader.classList.toggle("show")
|
loader.classList.toggle("show")
|
||||||
el.classList.toggle("hide")
|
el.classList.toggle("hide")
|
||||||
@@ -185,6 +193,8 @@ function load_routes (el,news=null,incrase,owner_type) {
|
|||||||
}
|
}
|
||||||
insert_place.innerHTML = data.html
|
insert_place.innerHTML = data.html
|
||||||
document.querySelector(".loader_f_loading_routes.show").classList.remove("show")
|
document.querySelector(".loader_f_loading_routes.show").classList.remove("show")
|
||||||
|
|
||||||
|
|
||||||
if (data.last_block === true){
|
if (data.last_block === true){
|
||||||
el.classList.add("hide")
|
el.classList.add("hide")
|
||||||
} else if (data.last_block === false){
|
} else if (data.last_block === false){
|
||||||
|
|||||||
Reference in New Issue
Block a user