0.11.20 push w link
This commit is contained in:
@@ -415,7 +415,7 @@ def registration_ajax(request):
|
|||||||
user = User.objects.create_user(username=form.data['email'], email=form.data['email'], password=form.data['password'])
|
user = User.objects.create_user(username=form.data['email'], email=form.data['email'], password=form.data['password'])
|
||||||
# user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass'])
|
# user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass'])
|
||||||
if user:
|
if user:
|
||||||
auth.login(request, user)
|
auth.login(request, user, backend='django.contrib.auth.backends.ModelBackend')
|
||||||
|
|
||||||
user.last_name = form.data['lastname']
|
user.last_name = form.data['lastname']
|
||||||
user.first_name = form.data['firstname']
|
user.first_name = form.data['firstname']
|
||||||
|
|||||||
@@ -266,19 +266,22 @@ def techSendMail(sets, html_content, title=None, add_emails=None):
|
|||||||
# return msg
|
# return msg
|
||||||
|
|
||||||
print('techSendMail')
|
print('techSendMail')
|
||||||
|
project_name = ''
|
||||||
|
if 'project_name' in sets:
|
||||||
|
project_name = sets['project_name']
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# subject = u'truEnergy Data техническое оповещение'
|
# subject = u'truEnergy Data техническое оповещение'
|
||||||
from_email = 'support@truenergy.by'
|
from_email = sets['sender_email']
|
||||||
to = ['web@syncsystems.net']
|
to = ['web@syncsystems.net']
|
||||||
if add_emails:
|
if add_emails:
|
||||||
to.extend(add_emails)
|
to.extend(add_emails)
|
||||||
text_content = 'Technical message from truEnergy.'
|
text_content = f'Technical message from {project_name}'
|
||||||
|
|
||||||
if title:
|
if title:
|
||||||
subject = title
|
subject = title
|
||||||
else:
|
else:
|
||||||
subject = u'truEnergy Data техническое оповещение'
|
subject = f'{project_name} - техническое оповещение'
|
||||||
|
|
||||||
res = admin_send_mail_by_SMTPlib(sets, subject, from_email, to, html_content)
|
res = admin_send_mail_by_SMTPlib(sets, subject, from_email, to, html_content)
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,16 @@ def get_options_by_opt_types(opt_types, only_vals=False):
|
|||||||
res = {}
|
res = {}
|
||||||
opts = opts.values('opt_type', 'value', 'prefix')
|
opts = opts.values('opt_type', 'value', 'prefix')
|
||||||
for item in opts:
|
for item in opts:
|
||||||
|
if item['opt_type'] == 'domain':
|
||||||
|
|
||||||
|
try:
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
|
current_site = Site.objects.get_current()
|
||||||
|
res.update({item['opt_type']: current_site.domain})
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
if item['prefix']:
|
if item['prefix']:
|
||||||
res.update({item['opt_type']: f"{item['prefix']}{item['value']}"})
|
res.update({item['opt_type']: f"{item['prefix']}{item['value']}"})
|
||||||
else:
|
else:
|
||||||
@@ -29,6 +39,6 @@ def get_first_option_value_by_opt_type(opt_type):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def get_mail_send_options():
|
def get_mail_send_options():
|
||||||
opt_types = ['mail_server_url', 'mail_server_smtp_port', 'sender_mail_login', 'sender_mail_password', 'sender_email']
|
opt_types = ['mail_server_url', 'mail_server_smtp_port', 'sender_mail_login', 'sender_mail_password', 'sender_email', 'project_name']
|
||||||
|
|
||||||
return get_options_by_opt_types(opt_types, only_vals=True)
|
return get_options_by_opt_types(opt_types, only_vals=True)
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ def test_code(request):
|
|||||||
from RoutesApp.models import Route
|
from RoutesApp.models import Route
|
||||||
from ReferenceDataApp.models import Airport, City
|
from ReferenceDataApp.models import Airport, City
|
||||||
|
|
||||||
import allauth
|
# import allauth
|
||||||
from allauth.socialaccount.models import SocialApp
|
# from allauth.socialaccount.models import SocialApp
|
||||||
apps = SocialApp.objects.all()
|
# apps = SocialApp.objects.all()
|
||||||
apps.delete()
|
# apps.delete()
|
||||||
|
|
||||||
# from RoutesApp.search_matches import search_matches
|
from RoutesApp.search_matches import search_matches
|
||||||
# search_matches()
|
search_matches()
|
||||||
|
|
||||||
# try:
|
# try:
|
||||||
# # body = request.body
|
# # body = request.body
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from webpush import send_user_notification
|
|||||||
import json
|
import json
|
||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
|
||||||
def get_key_Dict():
|
def get_key_Dict():
|
||||||
@@ -16,7 +17,7 @@ def get_key_Dict():
|
|||||||
}
|
}
|
||||||
return Dict
|
return Dict
|
||||||
|
|
||||||
def send_push(user, title, text, img=None):
|
def send_push(user, title, text, url=None, button_name=None, img=None):
|
||||||
try:
|
try:
|
||||||
# body = request.body
|
# body = request.body
|
||||||
# data = json.loads(body)
|
# data = json.loads(body)
|
||||||
@@ -28,8 +29,17 @@ def send_push(user, title, text, img=None):
|
|||||||
# user = get_object_or_404(User, pk=user_id)
|
# user = get_object_or_404(User, pk=user_id)
|
||||||
Dict = {
|
Dict = {
|
||||||
'head': title,
|
'head': title,
|
||||||
'body': text
|
'body': text,
|
||||||
}
|
}
|
||||||
|
if url:
|
||||||
|
Dict['url'] = url
|
||||||
|
if button_name:
|
||||||
|
Dict['button_name'] = button_name
|
||||||
|
else:
|
||||||
|
Dict['button_name'] = _('Перейти'),
|
||||||
|
|
||||||
|
if img:
|
||||||
|
Dict['img'] = img
|
||||||
|
|
||||||
# payload = {'head': data['head'], 'body': data['body']}
|
# payload = {'head': data['head'], 'body': data['body']}
|
||||||
send_user_notification(user=user, payload=Dict, ttl=1000)
|
send_user_notification(user=user, payload=Dict, ttl=1000)
|
||||||
|
|||||||
@@ -150,6 +150,16 @@ def get_routes_Dict(user=None, data=None):
|
|||||||
res_Dict = {}
|
res_Dict = {}
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
|
|
||||||
|
type_transport = None
|
||||||
|
if 'type_transport' in data and data['type_transport']:
|
||||||
|
items_list = data['type_transport'].split(',')
|
||||||
|
kwargs.update({f'type_transport__in': items_list})
|
||||||
|
|
||||||
|
if len(items_list) == 1:
|
||||||
|
type_transport = items_list[0]
|
||||||
|
|
||||||
|
|
||||||
for key, val in data.items():
|
for key, val in data.items():
|
||||||
if val:
|
if val:
|
||||||
if key == 'weight':
|
if key == 'weight':
|
||||||
@@ -162,9 +172,9 @@ def get_routes_Dict(user=None, data=None):
|
|||||||
else:
|
else:
|
||||||
kwargs.update({f'{key}__lte': int(weight_list[0])})
|
kwargs.update({f'{key}__lte': int(weight_list[0])})
|
||||||
|
|
||||||
if key == 'type_transport':
|
# if key == 'type_transport':
|
||||||
items_list = val.split(',')
|
# items_list = val.split(',')
|
||||||
kwargs.update({f'{key}__in': items_list})
|
# kwargs.update({f'{key}__in': items_list})
|
||||||
|
|
||||||
|
|
||||||
if key in (
|
if key in (
|
||||||
@@ -184,19 +194,18 @@ 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':
|
||||||
kwargs.update({f'from_city__id': val})
|
city = get_city_by_type_transport_and_address_point(type_transport, val)
|
||||||
|
kwargs.update({f'from_city': city})
|
||||||
|
|
||||||
res_Dict.update({
|
res_Dict.update({
|
||||||
'from_address_point_txt': get_country_n_city_str_by_type_transport_and_address_point(
|
'from_address_point_txt': city.get_country_n_city_str()
|
||||||
'road', val
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if key == 'to_address_point':
|
if key == 'to_address_point':
|
||||||
kwargs.update({f'to_city__id': val})
|
city = get_city_by_type_transport_and_address_point(type_transport, val)
|
||||||
|
kwargs.update({f'to_city': city})
|
||||||
res_Dict.update({
|
res_Dict.update({
|
||||||
'to_address_point_txt': get_country_n_city_str_by_type_transport_and_address_point(
|
'to_address_point_txt': city.get_country_n_city_str()
|
||||||
'road', val
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if key == 'from_el':
|
if key == 'from_el':
|
||||||
|
|||||||
@@ -5,22 +5,49 @@ from django.template.loader import render_to_string
|
|||||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||||
from BaseModels.mailSender import admin_send_mail_by_SMTPlib, techSendMail
|
from BaseModels.mailSender import admin_send_mail_by_SMTPlib, techSendMail
|
||||||
|
|
||||||
def send_mail_found_matches_routes(route, kwargs, search_owner_type):
|
|
||||||
|
|
||||||
|
def get_Dict_for_send_msgs(kwargs, search_owner_type):
|
||||||
|
|
||||||
Dict = {
|
Dict = {
|
||||||
'route': route,
|
|
||||||
'search_owner_type': search_owner_type
|
'search_owner_type': search_owner_type
|
||||||
}
|
}
|
||||||
sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
|
sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
|
||||||
Dict.update(sets)
|
Dict.update(sets)
|
||||||
|
|
||||||
|
|
||||||
Dict.update({'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg', })
|
Dict.update({'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg', })
|
||||||
|
|
||||||
find_routes_page_url = f'{sets["domain"]}/routes/route_search_results/?'
|
find_routes_page_url = f'{sets["domain"]}/routes/route_search_results/?'
|
||||||
kwargs_list = [f'{key}={value}' for key, value in kwargs.items()]
|
kwargs_list = [f'{key}={value}' for key, value in kwargs.items()]
|
||||||
kwargs_list.append(f'owner_type={search_owner_type}')
|
kwargs_list.append(f'owner_type={search_owner_type}')
|
||||||
find_routes_page_url += f'{"&".join(kwargs_list)}'
|
find_routes_page_url += f'{"&".join(kwargs_list)}'
|
||||||
|
|
||||||
Dict.update({'find_routes_page_url': find_routes_page_url})
|
Dict.update({'find_routes_page_url': find_routes_page_url})
|
||||||
|
|
||||||
|
return Dict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def send_push_message_for_found_matches_routes(route, data_Dict):
|
||||||
|
if not route.owner.is_authenticated:
|
||||||
|
return None
|
||||||
|
|
||||||
|
from PushMessages.views import send_push
|
||||||
|
title = 'Мы нашли исполнителя по Вашему объявлению!'
|
||||||
|
text = 'Для просмотра результата нажмите на кнопку ниже'
|
||||||
|
send_push(route.owner, title, text, url=data_Dict['find_routes_page_url'], button_name=_('Перейти к найденному'))
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def send_mail_found_matches_routes(route, data_Dict):
|
||||||
|
|
||||||
|
Dict = {
|
||||||
|
'route': route,
|
||||||
|
}
|
||||||
|
Dict.update(data_Dict)
|
||||||
|
|
||||||
html = render_to_string('mail/m_found_matched_routes.html', Dict)
|
html = render_to_string('mail/m_found_matched_routes.html', Dict)
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +114,11 @@ def search_matches(for_routes=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if found_routes:
|
if found_routes:
|
||||||
msg = send_mail_found_matches_routes(route, params, found_routes[0].owner_type)
|
data_Dict = get_Dict_for_send_msgs(params, found_routes[0].owner_type)
|
||||||
|
msg = send_push_message_for_found_matches_routes(route, data_Dict)
|
||||||
|
if msg:
|
||||||
|
log += msg
|
||||||
|
msg = send_mail_found_matches_routes(route, data_Dict)
|
||||||
if msg:
|
if msg:
|
||||||
log += msg
|
log += msg
|
||||||
|
|
||||||
@@ -96,6 +127,6 @@ def search_matches(for_routes=None):
|
|||||||
log += msg
|
log += msg
|
||||||
|
|
||||||
mail_sets = get_mail_send_options()
|
mail_sets = get_mail_send_options()
|
||||||
techSendMail(mail_sets, log, msg)
|
techSendMail(mail_sets, log, title='search_matches fail')
|
||||||
|
|
||||||
return log
|
return log
|
||||||
|
|||||||
@@ -7,12 +7,32 @@ self.addEventListener('push', function (event) {
|
|||||||
const data = JSON.parse(eventInfo);
|
const data = JSON.parse(eventInfo);
|
||||||
const head = data.head || 'New Notification 🕺🕺';
|
const head = data.head || 'New Notification 🕺🕺';
|
||||||
const body = data.body || 'This is default content. Your notification didn\'t have one 🙄🙄';
|
const body = data.body || 'This is default content. Your notification didn\'t have one 🙄🙄';
|
||||||
|
const icon = data.img || 'static/img/svg/Logo.svg';
|
||||||
|
|
||||||
|
let notificationOptions = {
|
||||||
|
body: body,
|
||||||
|
icon: icon,
|
||||||
|
};
|
||||||
|
if ('url' in data){
|
||||||
|
notificationOptions['data'] = { url: data.url };
|
||||||
|
notificationOptions['actions'] = [{action: "open_url", title: data.button_name}]
|
||||||
|
}
|
||||||
|
|
||||||
// Keep the service worker alive until the notification is created.
|
// Keep the service worker alive until the notification is created.
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
self.registration.showNotification(head, {
|
self.registration.showNotification(head, notificationOptions)
|
||||||
body: body,
|
|
||||||
icon: 'static/img/svg/Logo.svg'
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.addEventListener('notificationclick', function(event) {
|
||||||
|
|
||||||
|
switch(event.action){
|
||||||
|
case 'open_url':
|
||||||
|
clients.openWindow(event.notification.data.url);
|
||||||
|
break;
|
||||||
|
case 'any_other_action':
|
||||||
|
clients.openWindow("https://www.example.com");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
, false);
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
{#var user_id = {{ user.id }}#}
|
{#var user_id = {{ user.id }}#}
|
||||||
ws_url = `wss://{% get_ws_address %}/ws/socket-server/?user_id={{ user.id }}`;
|
ws_url = `ws://{% get_ws_address %}/ws/socket-server/?user_id={{ user.id }}`;
|
||||||
var chatSocket;
|
var chatSocket;
|
||||||
init_ws()
|
init_ws()
|
||||||
const beep = new Audio('/static/sounds/beep_2.mp3')
|
const beep = new Audio('/static/sounds/beep_2.mp3')
|
||||||
|
|||||||
Reference in New Issue
Block a user