LIL-299. Add AuthorRequest view

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent e68b383d57
commit d5f65f5b95
  1. 2
      apps/user/templates/user/profile-settings.html
  2. 46
      apps/user/views.py
  3. 7
      project/templates/lilcity/index.html
  4. 12
      project/urls.py

@ -79,7 +79,7 @@
{% if form.email.errors %} {% if form.email.errors %}
<div class="field__error">Укажите корректно свои данные</div> <div class="field__error">Укажите корректно свои данные</div>
{% endif %} {% endif %}
</div> </div>
<div class="form__fieldset"> <div class="form__fieldset">
<div class="form__field field{% if form.city.errors %} error{% endif %}"> <div class="form__field field{% if form.city.errors %} error{% endif %}">
<div class="field__label">ГОРОД</div> <div class="field__label">ГОРОД</div>

@ -26,7 +26,8 @@ from apps.notification.utils import send_email
from apps.school.models import SchoolSchedule from apps.school.models import SchoolSchedule
from apps.payment.models import AuthorBalance, CoursePayment, SchoolPayment from apps.payment.models import AuthorBalance, CoursePayment, SchoolPayment
from .forms import UserEditForm, WithdrawalForm from .forms import AuthorRequesForm, UserEditForm, WithdrawalForm
from .models import AuthorRequest
User = get_user_model() User = get_user_model()
@ -182,3 +183,46 @@ class UserEditView(UpdateView):
def get_success_url(self): def get_success_url(self):
return reverse('user-edit-profile', args=[self.object.id]) return reverse('user-edit-profile', args=[self.object.id])
class AuthorRequestView(FormView):
template_name = 'user/become-author.html'
form_class = AuthorRequesForm
success_url = reverse_lazy('author-request-success')
def post(self, request, pk=None):
form = self.get_form()
if form.is_valid():
if request.user.is_authenticated:
email = request.user.email
if request.user.role in [User.AUTHOR_ROLE, User.ADMIN_ROLE]:
messages.info('Вы уже являетесь автором')
return self.form_invalid(form)
else:
email = form.cleaned_data['email']
if AuthorRequest.objects.filter(email=email).exists():
messages.error('Вы уже отправили заявку на преподавателя')
return self.form_invalid(form)
AuthorRequest.objects.create(
first_name=form.cleaned_daLILta['first_name'],
last_name=form.cleaned_data['last_name'],
email=email,
about=form.cleaned_data['about'],
facebook=form.cleaned_data['facebook'],
)
return self.form_valid(form)
else:
return self.form_invalid(form)
def get_context_data(self):
if self.request.user.is_authenticated:
self.initial = {
'first_name': self.request.user.first_name,
'last_name': self.request.user.last_name,
'email': self.request.user.email,
'about': self.request.user.about,
'facebook': self.request.user.facebook,
}
return super().get_context_data()

@ -188,8 +188,11 @@
</div> </div>
<div class="footer__col"> <div class="footer__col">
<div class="footer__title">Программы</div> <div class="footer__title">Программы</div>
<nav class="footer__nav"><a class="footer__link" href="#">Онлайн-школа</a><a class="footer__link" href="#">Онлайн-курсы</a><a <nav class="footer__nav">
class="footer__link" href="#">Стать автором</a></nav> <a class="footer__link" href="#">Онлайн-школа</a>
<a class="footer__link" href="#">Онлайн-курсы</a>
<a class="footer__link" href="{% url 'author_request' %}">Стать автором</a>
</nav>
</div> </div>
<div class="footer__col"> <div class="footer__col">
<div class="footer__title">Контакты</div> <div class="footer__title">Контакты</div>

@ -25,7 +25,8 @@ from apps.course.views import (
CourseOnModerationView, CourseOnModerationView,
) )
from apps.user.views import ( from apps.user.views import (
UserView, UserEditView, NotificationEditView, AuthorRequestView, UserView,
UserEditView, NotificationEditView,
PaymentHistoryView, resend_email_verify, PaymentHistoryView, resend_email_verify,
) )
from apps.payment.views import CourseBuyView, PaymentwallCallbackView, SchoolBuyView from apps.payment.views import CourseBuyView, PaymentwallCallbackView, SchoolBuyView
@ -35,6 +36,7 @@ from .views import IndexView
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('auth/', include(('apps.auth.urls', 'lilcity'))), path('auth/', include(('apps.auth.urls', 'lilcity'))),
path('author-request/', AuthorRequestView.as_view(), name='author_request'),
path('author-request/success/', TemplateView.as_view(template_name='user/become-author-success.html'), name='author-request-success'), path('author-request/success/', TemplateView.as_view(template_name='user/become-author-success.html'), name='author-request-success'),
path('courses/', CoursesView.as_view(), name='courses'), path('courses/', CoursesView.as_view(), name='courses'),
path('course/create', CourseEditView.as_view(), name='course_create'), path('course/create', CourseEditView.as_view(), name='course_create'),
@ -59,12 +61,12 @@ urlpatterns = [
path('user/<int:pk>/notifications', NotificationEditView.as_view(), name='user-edit-notifications'), path('user/<int:pk>/notifications', NotificationEditView.as_view(), name='user-edit-notifications'),
path('user/<int:pk>/payments', PaymentHistoryView.as_view(), name='user-edit-payments'), path('user/<int:pk>/payments', PaymentHistoryView.as_view(), name='user-edit-payments'),
path('user/resend-email-verify', resend_email_verify, name='resend-email-verify'), path('user/resend-email-verify', resend_email_verify, name='resend-email-verify'),
path('privacy', TemplateView.as_view(template_name="templates/lilcity/privacy_policy.html"), name='privacy'), path('privacy', TemplateView.as_view(template_name='templates/lilcity/privacy_policy.html'), name='privacy'),
path('terms', TemplateView.as_view(template_name="templates/lilcity/terms.html"), name='terms'), path('terms', TemplateView.as_view(template_name='templates/lilcity/terms.html'), name='terms'),
path('refund-policy', TemplateView.as_view(template_name="templates/lilcity/refund_policy.html"), name='refund_policy'), path('refund-policy', TemplateView.as_view(template_name='templates/lilcity/refund_policy.html'), name='refund_policy'),
path('', IndexView.as_view(), name='index'), path('', IndexView.as_view(), name='index'),
path('api/v1/', include(('api.v1.urls', 'api_v1'))), path('api/v1/', include(('api.v1.urls', 'api_v1'))),
path('test', TemplateView.as_view(template_name="templates/lilcity/test.html"), name='test'), path('test', TemplateView.as_view(template_name='templates/lilcity/test.html'), name='test'),
] ]

Loading…
Cancel
Save