0.8.7
processing send messages by mail
This commit is contained in:
@@ -28,6 +28,6 @@ urlpatterns = [
|
||||
path('change_profile_confirm/', change_profile_confirm_ajax, name='change_profile_confirm_ajax'),
|
||||
path('change_avatar_confirm/', change_avatar_confirm_ajax, name='change_avatar_confirm_ajax'),
|
||||
|
||||
path('request_offer/', request_offer_ajax, name='request_offer_ajax')
|
||||
path('send_message/', send_message_ajax, name='send_message_ajax')
|
||||
|
||||
]
|
||||
@@ -31,53 +31,90 @@ import base64
|
||||
|
||||
|
||||
|
||||
def request_offer_ajax(request):
|
||||
def send_message_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
data = request.POST
|
||||
if not data and request.body:
|
||||
data = request.body
|
||||
try:
|
||||
|
||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
|
||||
data = request.POST
|
||||
if not data and request.body:
|
||||
data = request.body
|
||||
|
||||
request_type = None
|
||||
subject = _('Получен запрос')
|
||||
if 'form_name' in data:
|
||||
if data['form_name'] == 'msg_from_advertisement':
|
||||
subject = _('Получен запрос на рекламу')
|
||||
request_type = _('запрос на рекламу')
|
||||
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options
|
||||
sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
|
||||
|
||||
request_type = None
|
||||
subject = _('Получен запрос')
|
||||
if 'form_name' in data:
|
||||
if data['form_name'] == 'msg_from_advertisement':
|
||||
subject = _('Получен запрос на рекламу')
|
||||
request_type = _('запрос на рекламу')
|
||||
if data['form_name'] == 'msg_from_partners':
|
||||
subject = _('Получен запрос на подключение к партнерской сети')
|
||||
request_type = _('запрос на партнерство')
|
||||
if data['form_name'] == 'msg_from_customer_service':
|
||||
subject = _('Получен запрос в службу техподдержки')
|
||||
request_type = _('запрос в техподдержку')
|
||||
if data['form_name'] == 'msg_from_contacts':
|
||||
subject = _('Получен запрос со страницы контактов')
|
||||
request_type = _('запрос со страницы контактов')
|
||||
if data['form_name'] == 'msg_from_about_service':
|
||||
subject = _('Получен запрос со страницы О сервисе')
|
||||
request_type = _('запрос со страницы о сервисе')
|
||||
if data['form_name'] == 'footer':
|
||||
subject = _('Получен запрос на рассылку')
|
||||
request_type = _('запрос на рассылку')
|
||||
|
||||
if request_type:
|
||||
request_type_str = f'<b>{_("Тип запроса")}:</b> {request_type}<br>'
|
||||
else:
|
||||
request_type_str = ''
|
||||
name_str = ''
|
||||
phone_str = ''
|
||||
email_str = ''
|
||||
msg_str = ''
|
||||
if request_type:
|
||||
request_type_str = f'<b>{_("Тип запроса")}:</b> {request_type}<br>'
|
||||
if 'name' in data:
|
||||
name_str = f'<b>{_("Имя")}:</b> {data["name"]}<br>'
|
||||
if 'phone' in data:
|
||||
phone_str = f'<b>{_("Телефон")}:</b> {data["phone"]}<br>'
|
||||
if 'email' in data:
|
||||
email_str = f'<b>{_("email")}:</b> {data["email"]}<br>'
|
||||
if 'text_msg' in data:
|
||||
msg_str = (f'<b>{_("Сообщение")}:</b><br>'
|
||||
f'<div style="margin-left: 40px; line-height: 20px;">{data["text_msg"]}</div><br>')
|
||||
|
||||
Dict = {
|
||||
'logo': f'{request.scheme}://{sets["domain"]}/static/img/svg/LogoMobile.svg',
|
||||
'project_name': sets['project_name'],
|
||||
'message_title': subject,
|
||||
'message_text': f'<p><b>{_("ДАННЫЕ ЗАПРОСА")}</b></p>'
|
||||
f'<p style="padding-left: 20px; line-height: 30px;">'
|
||||
f'{request_type_str}'
|
||||
f'<b>{_("Имя")}:</b> {data["name"]}<br>'
|
||||
f'<b>{_("Телефон")}:</b> {data["phone"]}'
|
||||
f'</p>'
|
||||
}
|
||||
|
||||
html = render_to_string('mail/m_request_offer.html', Dict, request)
|
||||
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
||||
mail_sets = get_mail_send_options()
|
||||
to = [mail_sets['sender_email'], 'web@syncsystems.net']
|
||||
res = admin_send_mail_by_SMTPlib(
|
||||
mail_sets,
|
||||
subject=subject,
|
||||
from_email=mail_sets['sender_email'], to=to,
|
||||
html_content=html
|
||||
)
|
||||
Dict = {
|
||||
'logo': f'{request.scheme}://{sets["domain"]}/static/img/svg/LogoMobile.svg',
|
||||
'project_name': sets['project_name'],
|
||||
'message_title': subject,
|
||||
'message_text': f'<p><b>{_("ДАННЫЕ ЗАПРОСА")}</b></p>'
|
||||
f'<p style="padding-left: 20px; line-height: 30px;">'
|
||||
f'{request_type_str}'
|
||||
f'{name_str}'
|
||||
f'{phone_str}'
|
||||
f'{email_str}'
|
||||
f'{msg_str}'
|
||||
f'</p>'
|
||||
}
|
||||
|
||||
return JsonResponse({'status': 'sended'})
|
||||
html = render_to_string('mail/m_request_offer.html', Dict, request)
|
||||
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
||||
mail_sets = get_mail_send_options()
|
||||
to = [mail_sets['sender_email'], 'web@syncsystems.net']
|
||||
res = admin_send_mail_by_SMTPlib(
|
||||
mail_sets,
|
||||
subject=subject,
|
||||
from_email=mail_sets['sender_email'], to=to,
|
||||
html_content=html
|
||||
)
|
||||
|
||||
return JsonResponse({'status': 'sended'})
|
||||
except Exception as e:
|
||||
return JsonResponse({
|
||||
'status': 'error',
|
||||
'error': str(e)
|
||||
})
|
||||
|
||||
|
||||
@login_required(login_url='/profile/login/')
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
|
||||
<div style="font-family:Calibri,Candara,Segoe,'Segoe UI',Optima,Arial,sans-serif; padding:10px; background-color: #F8F8F8;">
|
||||
<div style="line-height:1.0em;width: 660px">
|
||||
<div style="font-family:Calibri,Candara,Segoe,'Segoe UI',Optima,Arial,sans-serif;
|
||||
padding:10px; background-color: #F8F8F8;"
|
||||
>
|
||||
<div style="line-height:1.0em; width: 660px">
|
||||
<div style="padding:5px; text-align: center;">
|
||||
<img src="{{ logo }}" alt="{{ project_name }}" style="margin:0;padding:0;">
|
||||
</div>
|
||||
<p style="font-weight:700;font-size:25px;text-align:center;padding:0;line-height:1em; text-transform: uppercase; color: #ff613a;">
|
||||
<p style="font-weight:700; font-size:25px; text-align:center;
|
||||
padding:0; line-height:1em; text-transform: uppercase; color: #ff613a;
|
||||
margin: auto; max-width: 90%;
|
||||
">
|
||||
{{ message_title|safe }}
|
||||
</p>
|
||||
<div style="line-height:1.0em;font-size:18px;margin-top: 5px; margin-left: 30px; box-shadow: -1px 4px 10px 0 rgba(198, 199, 203, 0.20), 0 -1px 10px 0 rgba(198, 199, 203, 0.20); padding: 30px; border-radius: 10px; background-color: #FFF;">
|
||||
<div style="line-height:1.0em; font-size:18px; margin: 5px 30px;
|
||||
box-shadow: -1px 4px 10px 0 rgba(198, 199, 203, 0.20), 0 -1px 10px 0 rgba(198, 199, 203, 0.20);
|
||||
padding: 30px; border-radius: 10px; background-color: #FFF;"
|
||||
>
|
||||
{# <p style="line-height:1.0em;font-size:18px;margin-top: 5px; margin-left: 80px">#}
|
||||
{{ message_text|safe }}
|
||||
{{ message_text|safe|linebreaksbr }}
|
||||
{# </p>#}
|
||||
</div>
|
||||
{% for button in message_buttons %}
|
||||
|
||||
Reference in New Issue
Block a user