diff --git a/apps/user/views.py b/apps/user/views.py
index 500d8404..6530c309 100644
--- a/apps/user/views.py
+++ b/apps/user/views.py
@@ -56,56 +56,62 @@ class UserView(DetailView):
else:
context['simple_user'] = True
context['guest'] = True
- context['owner'] = self.request.user.id == self.object.id
+ owner = self.request.user.id == self.object.id
if context['guest'] and self.object.role <= User.USER_ROLE:
raise Http404()
- context['published'] = Course.objects.filter(
+ published = Course.objects.filter(
author=self.object,
)
- context['paid'] = Course.objects.filter(
- payments__in=CoursePayment.objects.filter(
+ if not owner:
+ published = published.filter(status=Course.PUBLISHED)
+ else:
+ context['paid'] = Course.objects.filter(
+ payments__in=CoursePayment.objects.filter(
+ user=self.object,
+ status__in=[
+ Pingback.PINGBACK_TYPE_REGULAR,
+ Pingback.PINGBACK_TYPE_GOODWILL,
+ Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
+ ],
+ ),
+ ).distinct()
+ school_payment = SchoolPayment.objects.filter(
user=self.object,
+ date_start__lte=now(),
+ date_end__gt=now(),
status__in=[
Pingback.PINGBACK_TYPE_REGULAR,
Pingback.PINGBACK_TYPE_GOODWILL,
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
],
- ),
- ).distinct()
- school_payment = SchoolPayment.objects.filter(
- user=self.object,
- date_start__lte=now(),
- date_end__gt=now(),
- status__in=[
- Pingback.PINGBACK_TYPE_REGULAR,
- Pingback.PINGBACK_TYPE_GOODWILL,
- 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()
-
- school_payment_future = SchoolPayment.objects.filter(
- user=self.object,
- date_start__gte=now(),
- date_end__gte=now()
- )
+ )
+ 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()
+
+ school_payment_future = SchoolPayment.objects.filter(
+ user=self.object,
+ date_start__gte=now(),
+ date_end__gte=now()
+ )
+
+ context['is_purchased_future'] = school_payment_future.exists()
+ context['school_purchased_future'] = school_payment_future.last()
- context['is_purchased_future'] = school_payment_future.exists()
- context['school_purchased_future'] = school_payment_future.last()
+ context['owner'] = owner
+ context['published'] = published
return context