diff --git a/apps/user/templates/user/author_profile.html b/apps/user/templates/user/author_profile.html new file mode 100644 index 00000000..da09c579 --- /dev/null +++ b/apps/user/templates/user/author_profile.html @@ -0,0 +1,87 @@ +{% extends "templates/lilcity/index.html" %} {% load static %} {% load thumbnail %} {% block content %} +
+
+
+
+ {% thumbnail user.photo "120x120" crop="center" as im %} + + {% empty %} + + {% endthumbnail %} +
+
+
{{ user.get_full_name }}
+ +
+
+ {% if user.about %} + {{ user.about }} + {% endif %} +
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ {% if published.exists %} + {% include "course/course_items.html" with course_items=published %} + {% else %} +
+
+
Нет опубликованных курсов!
+
+
+ {% endif %} +
+
+
+
+
+
+
+{% endblock content %} diff --git a/apps/user/templates/user/notification-settings.html b/apps/user/templates/user/notification-settings.html index f2688060..40c679e5 100644 --- a/apps/user/templates/user/notification-settings.html +++ b/apps/user/templates/user/notification-settings.html @@ -2,7 +2,7 @@
diff --git a/apps/user/templates/user/payment-history.html b/apps/user/templates/user/payment-history.html index 5643dfa5..c27a3faa 100644 --- a/apps/user/templates/user/payment-history.html +++ b/apps/user/templates/user/payment-history.html @@ -2,7 +2,7 @@
diff --git a/apps/user/templates/user/profile-settings.html b/apps/user/templates/user/profile-settings.html index f590c7f9..5502c21d 100644 --- a/apps/user/templates/user/profile-settings.html +++ b/apps/user/templates/user/profile-settings.html @@ -2,7 +2,7 @@
diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html index e1deb25b..fd279635 100644 --- a/apps/user/templates/user/profile.html +++ b/apps/user/templates/user/profile.html @@ -2,9 +2,7 @@
- {% if not guest %} - Редактировать - {% endif %} + Редактировать
{% thumbnail user.photo "120x120" crop="center" as im %} @@ -56,7 +54,7 @@ {% endif %}
@@ -66,18 +64,17 @@
- {% if owner %} {# #} - - {% endif %} - + {% endif %}
- {% if owner %} {% comment %}
{% if is_purchased_future %} @@ -128,8 +125,8 @@
- {% endif %} -
+ {% if is_author %} +
{% if published.exists %} @@ -147,6 +144,7 @@
+ {% endif %}
diff --git a/apps/user/views.py b/apps/user/views.py index 500d8404..da1245ae 100644 --- a/apps/user/views.py +++ b/apps/user/views.py @@ -41,25 +41,23 @@ def resend_email_verify(request): url = request.scheme + '://' + request.get_host() + str(reverse_lazy('lilcity:verification-email', args=[token, request.user.id])) send_email('Вы успешно прошли регистрацию', request.user.email, "notification/email/verification_email.html", url=url) messages.info(request, 'Письмо подтверждения отправлено.') - return redirect('user-edit-profile', request.user.id) + return redirect('user-edit-profile') -class UserView(DetailView): +@method_decorator(login_required, name='dispatch') +class ProfileView(TemplateView): model = User template_name = 'user/profile.html' + def get(self, request, *args, **kwargs): + self.object = self.request.user + context = self.get_context_data(object=self.object) + return self.render_to_response(context) + def get_context_data(self, object): context = super().get_context_data() - if not self.request.user.is_anonymous: - context['simple_user'] = self.request.user.role == User.USER_ROLE - context['guest'] = self.request.user.id != self.object.id and self.request.user.role <= User.USER_ROLE - else: - context['simple_user'] = True - context['guest'] = True - context['owner'] = self.request.user.id == self.object.id - - if context['guest'] and self.object.role <= User.USER_ROLE: - raise Http404() + context['user'] = self.request.user + context['is_author'] = self.request.user.role == User.AUTHOR_ROLE context['published'] = Course.objects.filter( author=self.object, @@ -110,6 +108,18 @@ class UserView(DetailView): return context +class UserView(DetailView): + model = User + template_name = 'user/author_profile.html' + + def get_context_data(self, object): + context = super().get_context_data() + context['published'] = Course.objects.filter( + author=self.object, + ) + return context + + class SubscribeView(View): def post(self, request, pk=None, **kwargs): @@ -190,16 +200,16 @@ class PaymentHistoryView(FormView): @method_decorator(login_required, name='dispatch') -class UserEditView(UpdateView): +class ProfileEditView(UpdateView): model = User template_name = 'user/profile-settings.html' form_class = UserEditForm - @method_decorator(login_required) + def get_object(self, queryset=None): + return self.request.user + def dispatch(self, request, *args, **kwargs): self.object = self.get_object() - if request.user != self.object: - raise Http404() return super().dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): @@ -245,7 +255,7 @@ class UserEditView(UpdateView): return super().post(request, *args, **kwargs) def get_success_url(self): - return reverse('user-edit-profile', args=[self.object.id]) + return reverse('user-edit-profile') class AuthorRequestView(FormView): diff --git a/project/templates/blocks/user_menu.html b/project/templates/blocks/user_menu.html index 13f4fbdf..95e2b7d3 100644 --- a/project/templates/blocks/user_menu.html +++ b/project/templates/blocks/user_menu.html @@ -1,7 +1,7 @@ {% load static %} {% load thumbnail %} {% if request.user.is_authenticated %}