2.1.39 fix users_notify_by_result_search_matches
This commit is contained in:
@@ -74,7 +74,7 @@ def test_code(request):
|
||||
|
||||
from RoutesApp.search_matches import search_matches
|
||||
from RoutesApp.models import Route
|
||||
search_matches(Route.objects.filter(id=16))
|
||||
search_matches(Route.objects.filter(id=17158))
|
||||
|
||||
# from RoutesApp.funcs import get_city_by_type_transport_and_address_point
|
||||
# from RoutesApp.models import Route
|
||||
|
||||
@@ -30,6 +30,6 @@ class Admin_Route(Admin_Trans_BaseModel):
|
||||
search_fields = [
|
||||
'owner__first_name', 'owner__last_name', 'from_city__name', 'to_city__name', 'owner__email'
|
||||
]
|
||||
raw_id_fields = ['from_city', 'to_city']
|
||||
raw_id_fields = ['from_city', 'to_city', 'owner']
|
||||
|
||||
admin.site.register(Route,Admin_Route)
|
||||
admin.site.register(Route, Admin_Route)
|
||||
|
||||
@@ -47,7 +47,7 @@ def send_push_message_for_found_matches_routes(route, data_Dict):
|
||||
|
||||
|
||||
|
||||
def send_mail_found_matches_routes(route, data_Dict):
|
||||
def send_mail_found_matches_routes(route, matched_route, data_Dict):
|
||||
print(f'send_mail_found_matches_routes to route id = {route.id}')
|
||||
|
||||
Dict = {
|
||||
@@ -67,7 +67,9 @@ def send_mail_found_matches_routes(route, data_Dict):
|
||||
from_email=mail_sets['sender_email'], to=to,
|
||||
html_content=html
|
||||
)
|
||||
to = ['web@syncsystems.net']
|
||||
|
||||
subject = f'route matches {route.id} <> {matched_route.id} send to {route.owner.email}'
|
||||
to = ['web@syncsystems.net', 'sa@a3-global.com']
|
||||
res = admin_send_mail_by_SMTPlib(
|
||||
mail_sets,
|
||||
subject=subject,
|
||||
@@ -78,6 +80,56 @@ def send_mail_found_matches_routes(route, data_Dict):
|
||||
return res
|
||||
|
||||
|
||||
def user_notify_by_result_search_matches(route_for_send, founded_route, params):
|
||||
log = ''
|
||||
|
||||
data_Dict = None
|
||||
try:
|
||||
data_Dict = get_Dict_for_send_msgs(params, founded_route.owner_type)
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error get_Dict_for_send_msgs = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
|
||||
if data_Dict and check_option_in_cur_user_subscribe(
|
||||
route_for_send.owner, 'push уведомления'
|
||||
):
|
||||
try:
|
||||
msg = send_push_message_for_found_matches_routes(route_for_send, data_Dict)
|
||||
if msg:
|
||||
log += msg
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error send_push_message_for_found_matches_routes = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
|
||||
if data_Dict and check_option_in_cur_user_subscribe(
|
||||
route_for_send.owner,
|
||||
'уведомление на e-mail о появлении перевозчика по заданным критериям'
|
||||
):
|
||||
try:
|
||||
msg = send_mail_found_matches_routes(route_for_send, founded_route, data_Dict)
|
||||
if msg:
|
||||
log += msg
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error send_mail_found_matches_routes = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
|
||||
return log
|
||||
|
||||
|
||||
|
||||
def users_notify_by_result_search_matches(source_route, found_routes, params):
|
||||
log = ''
|
||||
log += user_notify_by_result_search_matches(source_route, found_routes[0], params)
|
||||
|
||||
for route in found_routes:
|
||||
log += user_notify_by_result_search_matches(route, source_route, params)
|
||||
|
||||
return log
|
||||
|
||||
|
||||
def search_matches(for_routes=None):
|
||||
print('search_matches')
|
||||
|
||||
@@ -147,39 +199,9 @@ def search_matches(for_routes=None):
|
||||
|
||||
if found_routes:
|
||||
msg = f'found routes for send messages = {found_routes.count()}'
|
||||
|
||||
data_Dict = None
|
||||
try:
|
||||
data_Dict = get_Dict_for_send_msgs(params, found_routes[0].owner_type)
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error get_Dict_for_send_msgs = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
|
||||
if data_Dict and check_option_in_cur_user_subscribe(
|
||||
route.owner, 'push уведомления'
|
||||
):
|
||||
try:
|
||||
msg = send_push_message_for_found_matches_routes(route, data_Dict)
|
||||
if msg:
|
||||
log += msg
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error send_push_message_for_found_matches_routes = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
|
||||
if data_Dict and check_option_in_cur_user_subscribe(
|
||||
route.owner,
|
||||
'уведомление на e-mail о появлении перевозчика по заданным критериям'
|
||||
):
|
||||
try:
|
||||
msg = send_mail_found_matches_routes(route, data_Dict)
|
||||
if msg:
|
||||
log += msg
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error send_mail_found_matches_routes = {str(e)}'
|
||||
print(msg)
|
||||
log += msg
|
||||
log += users_notify_by_result_search_matches(route, found_routes, params)
|
||||
|
||||
except Exception as e:
|
||||
msg = f'<br>\n! search_matches Error = {str(e)}'
|
||||
|
||||
Reference in New Issue
Block a user