|
|
|
|
@ -10,6 +10,7 @@ from django.conf import settings |
|
|
|
|
from django.contrib.auth import login |
|
|
|
|
from django.core.exceptions import ValidationError |
|
|
|
|
from django.shortcuts import render, reverse, redirect |
|
|
|
|
from django.views import View |
|
|
|
|
from django.views.generic import DetailView, UpdateView, TemplateView, FormView |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
|
@ -25,10 +26,9 @@ from apps.course.models import Course |
|
|
|
|
from apps.notification.utils import send_email |
|
|
|
|
from apps.school.models import SchoolSchedule |
|
|
|
|
from apps.payment.models import AuthorBalance, CoursePayment, SchoolPayment |
|
|
|
|
from apps.user.models import SubscriptionCategory |
|
|
|
|
from apps.user.models import AuthorRequest, EmailSubscription, SubscriptionCategory |
|
|
|
|
|
|
|
|
|
from .forms import AuthorRequesForm, UserEditForm, WithdrawalForm |
|
|
|
|
from .models import AuthorRequest |
|
|
|
|
|
|
|
|
|
User = get_user_model() |
|
|
|
|
|
|
|
|
|
@ -87,6 +87,27 @@ class UserView(DetailView): |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SubscribeView(View): |
|
|
|
|
|
|
|
|
|
def post(self, request, pk=None, **kwargs): |
|
|
|
|
if request.user.is_authenticated: |
|
|
|
|
messages.info(request, 'Вы уже подписаны на рассылки.') |
|
|
|
|
return redirect(request.get_full_path()) |
|
|
|
|
email = request.POST.get('email', None) |
|
|
|
|
if email: |
|
|
|
|
email_subscription = EmailSubscription.objects.create( |
|
|
|
|
email=email, |
|
|
|
|
) |
|
|
|
|
email_subscription.categories.set( |
|
|
|
|
SubscriptionCategory.objects.filter(auto_add=True) |
|
|
|
|
) |
|
|
|
|
messages.info(request, 'Вы подписаны на новости.') |
|
|
|
|
return redirect(request.get_full_path()) |
|
|
|
|
else: |
|
|
|
|
messages.error(request, 'Введите адрес электронной почты.') |
|
|
|
|
return redirect(request.get_full_path()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch') |
|
|
|
|
class NotificationEditView(TemplateView): |
|
|
|
|
template_name = 'user/notification-settings.html' |
|
|
|
|
|