|
|
|
|
@ -16,7 +16,7 @@ from django.contrib.auth import get_user_model |
|
|
|
|
from django.contrib.auth.decorators import login_required, permission_required |
|
|
|
|
from django.contrib.auth.hashers import check_password, make_password |
|
|
|
|
from django.http import Http404 |
|
|
|
|
from django.db.models import F, Func |
|
|
|
|
from django.db.models import F, Func, Sum, Min, Max |
|
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
from django.utils.decorators import method_decorator |
|
|
|
|
from django.utils.timezone import now |
|
|
|
|
@ -55,11 +55,11 @@ class ProfileView(TemplateView): |
|
|
|
|
def get_context_data(self, object): |
|
|
|
|
context = super().get_context_data() |
|
|
|
|
context['user'] = self.request.user |
|
|
|
|
context['is_author'] = self.request.user.role == User.AUTHOR_ROLE |
|
|
|
|
|
|
|
|
|
context['published'] = Course.objects.filter( |
|
|
|
|
author=self.object, |
|
|
|
|
) |
|
|
|
|
context['is_author'] = context['published'] or self.request.user.role == User.AUTHOR_ROLE |
|
|
|
|
context['paid'] = Course.objects.filter( |
|
|
|
|
payments__in=CoursePayment.objects.filter( |
|
|
|
|
user=self.object, |
|
|
|
|
@ -80,22 +80,18 @@ class ProfileView(TemplateView): |
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
], |
|
|
|
|
) |
|
|
|
|
school_schedules_purchased = school_payment.annotate( |
|
|
|
|
joined_weekdays=Func(F('weekdays'), function='unnest',) |
|
|
|
|
).values_list('joined_weekdays', flat=True).distinct() |
|
|
|
|
context['school_schedules_purchased'] = school_schedules_purchased |
|
|
|
|
context['school_payment'] = school_payment |
|
|
|
|
context['is_purchased'] = school_payment.exists() |
|
|
|
|
context['profile'] = True |
|
|
|
|
if school_payment.exists() and school_payment.last().date_end: |
|
|
|
|
context['subscription_ends'] = school_payment.last().date_end |
|
|
|
|
context['school_schedules'] = SchoolSchedule.objects.filter( |
|
|
|
|
weekday__in=school_schedules_purchased if school_payment.exists() else [], |
|
|
|
|
).all() |
|
|
|
|
context['all_school_schedules'] = SchoolSchedule.objects.all() |
|
|
|
|
context['is_school_purchased'] = school_payment.exists() |
|
|
|
|
if context['is_school_purchased']: |
|
|
|
|
school_schedules_purchased = school_payment.annotate( |
|
|
|
|
joined_weekdays=Func(F('weekdays'), function='unnest',) |
|
|
|
|
).values_list('joined_weekdays', flat=True).distinct() |
|
|
|
|
aggregated = school_payment.aggregate(Sum('amount'), Min('date_start'), Max('date_end'),) |
|
|
|
|
context['school_purchased_weekdays'] = '-'.join(map(lambda wd: SchoolSchedule.WEEKDAY_SHORT_NAMES[wd-1], |
|
|
|
|
set(sorted(school_schedules_purchased)))) |
|
|
|
|
context['school_purchased_price'] = aggregated.get('amount__sum') or 0 |
|
|
|
|
context['school_purchased_dates'] = [aggregated.get('date_start__min'), aggregated.get('date_end__max')] |
|
|
|
|
|
|
|
|
|
context['is_purchased_future'] = False |
|
|
|
|
context['school_purchased_future'] = False |
|
|
|
|
context['profile'] = True |
|
|
|
|
|
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
@ -107,7 +103,7 @@ class UserView(DetailView): |
|
|
|
|
def get_context_data(self, object): |
|
|
|
|
context = super().get_context_data() |
|
|
|
|
context['published'] = Course.objects.filter( |
|
|
|
|
author=self.object, |
|
|
|
|
author=self.object, status=Course.PUBLISHED, |
|
|
|
|
) |
|
|
|
|
return context |
|
|
|
|
|
|
|
|
|
|