0.12.3 subscribe mailing
This commit is contained in:
@@ -17,6 +17,7 @@ import json
|
||||
from django.core.files import File
|
||||
import base64
|
||||
from django.core.validators import validate_email
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
# @login_required(login_url='/profile/login/')
|
||||
@@ -31,6 +32,48 @@ from django.core.validators import validate_email
|
||||
# return JsonResponse({'html': html}, status=200)
|
||||
|
||||
|
||||
def mailing_subscribe_ajax(request):
|
||||
if request.method != 'POST':
|
||||
raise Http404
|
||||
|
||||
try:
|
||||
|
||||
email = request.POST['email']
|
||||
user = None
|
||||
if request.user and request.user.is_authenticated():
|
||||
user = request.user
|
||||
user.user_profile.mailing_on = True
|
||||
user.user_profile.save(update_fields=['mailing_on'])
|
||||
|
||||
return JsonResponse({
|
||||
'status': 'sended',
|
||||
'del_form': True,
|
||||
'html': _('Подписка на рассылку для адреса ') + user.email + _(' одобрена')
|
||||
})
|
||||
|
||||
if not user:
|
||||
try:
|
||||
user = User.objects.get(email=email)
|
||||
except User.DoesNotExist:
|
||||
user = None
|
||||
|
||||
if user:
|
||||
redirect_url = f"{reverse('login_profile')}?mailing_for_email={email}"
|
||||
else:
|
||||
redirect_url = f"{reverse('registration_page')}?mailing_for_email={email}"
|
||||
|
||||
return JsonResponse({
|
||||
'status': 'sended',
|
||||
'redirect_url': redirect_url
|
||||
})
|
||||
|
||||
|
||||
except Exception as e:
|
||||
return JsonResponse({
|
||||
'status': 'error',
|
||||
'html': str(e)
|
||||
}, status=400)
|
||||
|
||||
|
||||
def send_message_ajax(request):
|
||||
if request.method != 'POST':
|
||||
|
||||
Reference in New Issue
Block a user