0.12.3 subscribe mailing
This commit is contained in:
@@ -28,6 +28,8 @@ urlpatterns = [
|
|||||||
path('change_profile_confirm/', change_profile_confirm_ajax, name='change_profile_confirm_ajax'),
|
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('change_avatar_confirm/', change_avatar_confirm_ajax, name='change_avatar_confirm_ajax'),
|
||||||
|
|
||||||
path('send_message/', send_message_ajax, name='send_message_ajax')
|
path('send_message/', send_message_ajax, name='send_message_ajax'),
|
||||||
|
|
||||||
|
path('mailing_subscribe/', mailing_subscribe_ajax, name='mailing_subscribe_ajax')
|
||||||
|
|
||||||
]
|
]
|
||||||
@@ -17,6 +17,7 @@ import json
|
|||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
import base64
|
import base64
|
||||||
from django.core.validators import validate_email
|
from django.core.validators import validate_email
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
# @login_required(login_url='/profile/login/')
|
# @login_required(login_url='/profile/login/')
|
||||||
@@ -31,6 +32,48 @@ from django.core.validators import validate_email
|
|||||||
# return JsonResponse({'html': html}, status=200)
|
# 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):
|
def send_message_ajax(request):
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
|
|||||||
18
AuthApp/migrations/0005_userprofile_mailing_on.py
Normal file
18
AuthApp/migrations/0005_userprofile_mailing_on.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2024-02-01 17:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('AuthApp', '0004_alter_userprofile_account_type'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='userprofile',
|
||||||
|
name='mailing_on',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='Рассылка'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -51,6 +51,8 @@ class UserProfile(BaseModel):
|
|||||||
on_delete=models.SET_NULL
|
on_delete=models.SET_NULL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mailing_on = models.BooleanField(default=False, verbose_name=_('Рассылка'))
|
||||||
|
|
||||||
def save_user_alerts_to_session(self, request):
|
def save_user_alerts_to_session(self, request):
|
||||||
for_save_to_session = self.get_node_by_name('for_save_to_session')
|
for_save_to_session = self.get_node_by_name('for_save_to_session')
|
||||||
if for_save_to_session:
|
if for_save_to_session:
|
||||||
|
|||||||
Reference in New Issue
Block a user