From 3b0e1f6524139e6544d0e2fa32b7a038ff6ddbb9 Mon Sep 17 00:00:00 2001 From: SDE Date: Mon, 17 Feb 2025 18:22:23 +0300 Subject: [PATCH] 2.1.39 fix users_notify_by_result_search_matches --- GeneralApp/views.py | 2 +- RoutesApp/admin.py | 4 +- RoutesApp/search_matches.py | 90 +++++++++++++++++++++++-------------- 3 files changed, 59 insertions(+), 37 deletions(-) diff --git a/GeneralApp/views.py b/GeneralApp/views.py index d9fc75f..f288fc1 100644 --- a/GeneralApp/views.py +++ b/GeneralApp/views.py @@ -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 diff --git a/RoutesApp/admin.py b/RoutesApp/admin.py index 3a45d44..ce3c30c 100644 --- a/RoutesApp/admin.py +++ b/RoutesApp/admin.py @@ -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) diff --git a/RoutesApp/search_matches.py b/RoutesApp/search_matches.py index e693eff..a45d73c 100644 --- a/RoutesApp/search_matches.py +++ b/RoutesApp/search_matches.py @@ -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'
\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'
\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'
\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()}' + print(msg) - data_Dict = None - try: - data_Dict = get_Dict_for_send_msgs(params, found_routes[0].owner_type) - except Exception as e: - msg = f'
\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'
\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'
\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'
\n! search_matches Error = {str(e)}'