You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.8 KiB
48 lines
1.8 KiB
from django.conf import settings
|
|
from django.core.paginator import Paginator
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
# Create your views here.
|
|
from django.views.generic import ListView
|
|
|
|
from cart.models import BUYING_STATUS_IN_CART, BUYING_STATUS_BOUGHT, Buying
|
|
from core.views import ProtectedView
|
|
|
|
|
|
class IndexView(ProtectedView):
|
|
template_name = 'cabinet/index.html'
|
|
title = _('Личный кабинет')
|
|
|
|
def get_ref_link(self,user):
|
|
return "{path}?ref={ref_link}".format(**{
|
|
'path': user.referral.url,
|
|
'ref_link': user.referral.code
|
|
})
|
|
|
|
def get_bought_item_list(self,user):
|
|
bought_item_queryset = user.buying_set.filter(status=BUYING_STATUS_BOUGHT).order_by('-create_at').all()
|
|
paginator = Paginator(
|
|
object_list=bought_item_queryset,
|
|
per_page=5
|
|
)
|
|
the_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
|
|
context['company'] = self.request.user.company
|
|
context['profile'] = self.request.user.profile
|
|
return context
|
|
|