Merge branch 'master' of https://gitlab.com/lilcity/backend into feature/LIL-657

remotes/origin/hotfix/LIL-661
gzbender 7 years ago
commit 8ec6d91cc3
  1. 1
      apps/school/models.py
  2. 4
      apps/school/templates/blocks/schedule_item.html
  3. 48
      apps/school/views.py
  4. 57
      apps/user/templates/user/profile.html
  5. 32
      apps/user/views.py
  6. 2
      web/src/sass/_common.sass

@ -14,6 +14,7 @@ from apps.payment import models as payment_models
class SchoolSchedule(models.Model):
WEEKDAY_SHORT_NAMES = ('пн', 'вт', 'ср', 'чт', 'пт', 'сб', 'вс')
WEEKDAY_CHOICES = (
(1, 'понедельник'),
(2, 'вторник'),

@ -4,7 +4,7 @@
<div class="timing__info">
<div class="timing__day{% if school_schedule.is_online %} active{% endif %}">
{{ school_schedule }}
{% if request.user_agent.is_mobile and school_schedule.trial_lesson %}
{% if not is_purchased and request.user_agent.is_mobile and school_schedule.trial_lesson %}
<a class="timing__trial-lesson js-video-modal" href="#" data-video-url="{{ school_schedule.trial_lesson }}">Пробный урок</a>
{% endif %}
</div>
@ -20,7 +20,7 @@
{% else %}
{% include './day_pay_btn.html' %}
{% endif %}
{% if not request.user_agent.is_mobile and school_schedule.trial_lesson %}
{% if not is_purchased and not request.user_agent.is_mobile and school_schedule.trial_lesson %}
<a class="timing__trial-lesson js-video-modal" href="#" data-video-url="{{ school_schedule.trial_lesson }}">Пробный урок</a>
{% endif %}
</div>

@ -140,21 +140,9 @@ class SchoolView(TemplateView):
pass
school_schedules_dict = {ss.weekday: ss for ss in school_schedules}
school_schedules_dict[0] = school_schedules_dict.get(7)
all_schedules_purchased = []
live_lessons = None
live_lessons_exists = False
if self.request.user.is_authenticated:
all_schedules_purchased = SchoolPayment.objects.filter(
user=self.request.user,
status__in=[
Pingback.PINGBACK_TYPE_REGULAR,
Pingback.PINGBACK_TYPE_GOODWILL,
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
],
date_start__range=[month_start, date_now],
).annotate(
joined_weekdays=Func(F('weekdays'), function='unnest',)
).distinct().values_list('joined_weekdays', flat=True)
all_schedules_purchased = list(map(lambda x: 1 if x == 7 else x+1, all_schedules_purchased))
school_payment = SchoolPayment.objects.filter(
user=self.request.user,
status__in=[
@ -173,18 +161,32 @@ class SchoolView(TemplateView):
else:
school_payment_exists = False
school_schedules_purchased = []
if all_schedules_purchased and is_previous:
live_lessons = LiveLesson.objects.filter(
date__range=[yesterday - timedelta(days=7), yesterday],
deactivated_at__isnull=True,
date__week_day__in=all_schedules_purchased,
).order_by('-date')
if is_previous:
prev_range = [yesterday - timedelta(days=7), yesterday]
live_lessons = []
# берем все подписки, которые были в периоде
for sp in SchoolPayment.objects.filter(
date_start__lte=prev_range[1],
date_end__gte=prev_range[0],
user=self.request.user,
status__in=[
Pingback.PINGBACK_TYPE_REGULAR,
Pingback.PINGBACK_TYPE_GOODWILL,
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,
],
):
# берем все уроки в оплаченном промежутке
date_range = [max(sp.date_start, prev_range[0]), min(sp.date_end, prev_range[1])]
live_lessons += LiveLesson.objects.filter(
date__range=date_range,
deactivated_at__isnull=True,
date__week_day__in=list(map(lambda x: 1 if x == 7 else x+1, sp.weekdays)),
).values_list('id', flat=True)
live_lessons = LiveLesson.objects.filter(id__in=set(live_lessons)).order_by('-date')
for ll in live_lessons:
ll.school_schedule = school_schedules_dict.get(ll.date.isoweekday())
live_lessons_exists = live_lessons.exists()
else:
live_lessons = None
live_lessons_exists = False
live_lessons = live_lessons or None
context.update({
'online': online,
'live_lessons': live_lessons,

@ -64,10 +64,7 @@
<div class="section__center center">
<div class="tabs js-tabs">
<div class="tabs__nav">
<button class="tabs__btn js-tabs-btn active">ОНЛАЙН-ШКОЛА</button>
<button class="tabs__btn js-tabs-btn">ПРИОБРЕТЕННЫЕ
<span class="mobile-hide">КУРСЫ</span>
</button>
<button class="tabs__btn js-tabs-btn active">МОИ ПОКУПКИ</button>
{% if is_author %}
<button class="tabs__btn js-tabs-btn">ОПУБЛИКОВАННЫЕ
<span class="mobile-hide">КУРСЫ</span>
@ -76,45 +73,33 @@
</div>
<div class="tabs__container">
<div class="tabs__item js-tabs-item" style="display: block;">
{% if is_purchased_future %}
<div class="center center_xs">
<div class="done">
<div class="done__title title">Ваша подписка начинается {{school_purchased_future.date_start}}</div>
</div>
</div>
{% else %}
{% if is_purchased %}
{% include "blocks/schedule_purchased.html" %}
{% else %}
<div class="center center_xs">
<div class="done">
<div class="done__title title">Вы не подписаны на онлайн-школу!</div>
<div class="done__foot">
<a
{% if not user.is_authenticated %}
data-popup=".js-popup-auth"
{% else %}
data-popup=".js-popup-buy"
{% endif %}
href="#"
class="done__btn btn btn_md btn_stroke"
>Купить подписку</a>
</div>
</div>
</div>
{% endif %}
{% endif %}
</div>
<div class="tabs__item js-tabs-item">
<div class="courses courses_scroll">
<div class="courses__list">
{% if is_school_purchased %}
<div class="courses__item">
<a class="courses__preview" href="{% url 'school:school' %}">
<img class="courses__pic" src="{% static 'img/og_main.jpg' %}"
style="height: 201px; width: 300px; object-fit: cover;" />
</a>
<div class="courses__details">
<a class="courses__theme theme">{{ school_purchased_weekdays }}</a>
<div class="courses__price">{{ school_purchased_price|floatformat:"-2" }}₽</div>
</div>
<a class="courses__title">Онлайн-школа&nbsp;{{ school_purchased_dates.0|date:"j b" }}&nbsp;-&nbsp;{{ school_purchased_dates.1|date:"j b" }}</a>
<a class="btn" href="{% url 'school:school' %}">Перейти в онлайн-школу</a>
</div>
{% endif %}
{% if paid.exists %}
{% include "course/course_items.html" with course_items=paid %}
{% else %}
{% endif %}
{% if not is_school_purchased and not paid.exists %}
<div class="center center_xs">
<div class="done">
<div class="done__title title">Нет приобретённых курсов!</div>
<div class="done__title">Вы пока ничего не приобрели...</div>
<div class="done__foot">
<a class="done__btn btn btn_md btn_stroke" href="{% url 'school:school' %}"
style="margin-bottom: 20px;">Записаться в школу</a>
<a class="done__btn btn btn_md btn_stroke" href="{% url 'courses' %}">Купить курсы</a>
</div>
</div>

@ -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

@ -1710,6 +1710,8 @@ a.grey-link
color: $cl
+t
line-height: 1.33
&__theme
text-transform: uppercase
&__user
margin-top: 20px
&_two &__item

Loading…
Cancel
Save