diff --git a/cabinet/views.py b/cabinet/views.py index 3707da1..a19f098 100644 --- a/cabinet/views.py +++ b/cabinet/views.py @@ -1,14 +1,41 @@ -from django.shortcuts import render +from django.conf import settings +from django.core.paginator import Paginator from django.utils.translation import ugettext_lazy as _ # Create your views here. +from cart.models import BUYING_STATUS_IN_CART from core.views import ProtectedView +def get_mobile_phone_number(user): + return user.profile.phone + + class IndexView(ProtectedView): template_name = 'cabinet/index.html' title = _('Личный кабинет') + def get_ref_link(self,user): + return user.referral.url if user.referral else "" + + def get_bought_item_list(self,user): + paginator = Paginator(object_list=user.buying_set.filter(status=BUYING_STATUS_IN_CART).order_by('create_at').all(), per_page=settings.DEFAULT_PAGE_AMMOUNT) + the_page = self.kwargs.get('page',1) + return paginator.page(the_page) + + def get_full_name(self,user): + return '{last_name}{first_name}{patronymic}'.format(**{ + 'last_name': user.profile.last_name or "", + 'first_name': user.profile.first_name or "", + 'patronymic': user.profile.patronymic or "" + }) + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['title'] = self.title + context['ref_link'] = self.get_ref_link(self.request.user) + context['bought_item_list'] = self.get_bought_item_list(self.request.user) + context['full_name'] = self.get_full_name(self.request.user) + context['email'] = self.request.user.email + context['phone_number'] = self.request.user.profile.phone + return context diff --git a/templates/cabinet/index.html b/templates/cabinet/index.html index 4e5a2ae..187f947 100644 --- a/templates/cabinet/index.html +++ b/templates/cabinet/index.html @@ -6,24 +6,25 @@
{{ title }}
-
-
-
- Ваши бонусы: 1326 -
- - -
-
+{#
#} +{#
#} +{#
#} +{# Ваши бонусы: 1326#} +{#
#} +{# #} +{# #} +{#
#} +{#
#}
-
Ваша ссылка: rusprog.ru/igor115 +
+ Ваша ссылка: {{ res_link }}
@@ -34,14 +35,17 @@
Имя
Баллы
-
-
Nikolas
-
120
-
-
-
Nikolas
-
120
-
+ {% for ref_user in referral_user_list %} +
+
{{ ref_user.name }}
+{#
120
#} +
+ {% empty %} +
+
Nikolas
+
120
+
+ {% endfor %}
@@ -58,34 +62,23 @@ Кол-во Сумма - - 12.06.17 - 142251366 - Windows 7 BOX... - 1 - 7570₽ - - - 12.06.17 - 142251366 - Windows 7 BOX... - 1 - 7570₽ - - - 12.06.17 - 142251366 - Windows 7 BOX... - 1 - 7570₽ - - - 12.06.17 - 142251366 - Windows 7 BOX... - 1 - 7570₽ - + {% for bought_item in bought_item_list %} + + {{ bought_item.bought_at }} + {{ bought_item.id }} + {{ bought_item.product.name }} + {{ bought_item.amount }} + {{ bought_item.total_price }}7570₽ + + {% empty %} + + 12.06.17 + 142251366 + Windows 7 BOX... + 1 + 7570₽ + + {% endfor %}
Вся история покупок
@@ -93,19 +86,19 @@
ФИО:
-
Мезенцев Игорь Евгеньевич
+
{{ full_name|default:"-" }}
Дата рождения:
-
24.08.1995
+
{{ birthday|default:"-" }}
Номер телефона:
-
8 (913) 464-14-43
+
{{ phone_number|default:"-" }}
Эл.почта:
-
igormezencev55@yandex.ru
+
{{ email }}