diff --git a/apps/school/urls.py b/apps/school/urls.py
index 47361f96..59973c6d 100644
--- a/apps/school/urls.py
+++ b/apps/school/urls.py
@@ -3,12 +3,11 @@ from django.urls import path, include
from .views import (
LiveLessonsView, LiveLessonEditView,
LiveLessonsDetailView, SchoolView,
- SchoolSchedulesPrintView, SummerSchoolView,
+ SchoolSchedulesPrintView,
)
urlpatterns = [
path('', SchoolView.as_view(), name='school'),
- path('summer', SummerSchoolView.as_view(), name='summer-school'),
path('schedules/print', SchoolSchedulesPrintView.as_view(), name='school_schedules-print'),
path('lessons/', LiveLessonsView.as_view(), name='lessons'),
path('lessons/create', LiveLessonEditView.as_view(), name='lessons-create'),
diff --git a/apps/school/views.py b/apps/school/views.py
index 3f269067..e09801c2 100644
--- a/apps/school/views.py
+++ b/apps/school/views.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, date
from paymentwall import Pingback
from django.contrib.auth import get_user_model
@@ -34,19 +34,22 @@ class LiveLessonsView(ListView):
template_name = 'school/livelessons_list.html'
def get_queryset(self):
+ september2018 = date(2018, 9, 1)
+ date_start = (now() - timedelta(days=7)).date()
+ if date_start < september2018:
+ date_start = september2018
date_range = Q(
date__range=[
- (now() - timedelta(days=7)).date(),
- (now() + timedelta(days=10)).date(),
+ date_start,
+ date_start + timedelta(days=17),
]
)
queryset = LiveLesson.objects.filter(date_range)
if queryset.count() < 17:
- start_date = now() - timedelta(days=7)
for i in range(18):
try:
LiveLesson.objects.create(
- date=(start_date + timedelta(days=i)).date(),
+ date=date_start + timedelta(days=i),
)
except IntegrityError:
pass
@@ -61,6 +64,7 @@ class LiveLessonsDetailView(DetailView):
def get(self, request, pk=None):
response = super().get(request, pk=pk)
+ # ??? где проверка?
#try:
# school_payment = SchoolPayment.objects.get(
# user=request.user,
@@ -107,75 +111,8 @@ class LiveLessonEditView(TemplateView):
class SchoolView(TemplateView):
- template_name = 'school/school.html'
-
- def get_context_data(self):
- context = super().get_context_data()
- is_previous = 'is_previous' in self.request.GET
- date_now = now().date()
- now_time = now()
- try:
- school_schedule = SchoolSchedule.objects.get(weekday=now_time.isoweekday())
- except SchoolSchedule.DoesNotExist:
- online = False
- else:
- end_at = datetime.combine(now_time.today(), school_schedule.start_at)
- online = (
- school_schedule.start_at <= now_time.time() and
- (end_at + timedelta(hours=1)).time() >= now_time.time() and
- school_schedule.current_live_lesson()
- )
- if self.request.user.is_authenticated:
- school_payment = 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__lte=date_now,
- date_end__gte=date_now
- )
- school_payment_exists = school_payment.exists()
- school_schedules_purchased = school_payment.annotate(
- joined_weekdays=Func(F('weekdays'), function='unnest',)
- ).values_list('joined_weekdays', flat=True).distinct()
- else:
- school_payment_exists = False
- school_schedules_purchased = []
- if school_payment_exists and is_previous:
- live_lessons = LiveLesson.objects.filter(
- date__gte=school_payment.last().date_start,
- date__range=[(now_time - timedelta(days=8)).date(), (now_time - timedelta(days=1)).date()],
- deactivated_at__isnull=True,
- )
- live_lessons_exists = live_lessons.exists()
- else:
- live_lessons = None
- live_lessons_exists = False
- context.update({
- 'online': online,
- 'live_lessons': live_lessons,
- 'live_lessons_exists': live_lessons_exists,
- 'is_previous': is_previous,
- 'course_items': Course.objects.filter(status=Course.PUBLISHED)[:6],
- 'is_purchased': school_payment_exists,
- 'min_school_price': SchoolSchedule.objects.aggregate(Min('month_price'))['month_price__min'],
- 'school_schedules': SchoolSchedule.objects.all(),
- 'school_schedules_purchased': school_schedules_purchased,
- 'subscription_ends': school_payment.filter(add_days=False).first().date_end if school_payment_exists else None,
- })
- return context
-
-class SummerSchoolView(TemplateView):
template_name = 'school/summer_school.html'
- def get(self, request, *args, **kwargs):
- context = self.get_context_data(**kwargs)
- if not context.get('is_purchased'):
- return redirect('/')
- return self.render_to_response(context)
-
def get_context_data(self):
context = super().get_context_data()
is_previous = 'is_previous' in self.request.GET
@@ -193,10 +130,14 @@ class SummerSchoolView(TemplateView):
online = (
school_schedule.start_at <= now_time.time() and
(end_at + timedelta(hours=1)).time() >= now_time.time() and
- school_schedule.current_live_lesson()
+ school_schedule.current_live_lesson
)
school_schedules = SchoolSchedule.objects.all()
+ try:
+ school_schedules = sorted(school_schedules, key=lambda ss: ss.current_live_lesson and ss.current_live_lesson.date)
+ except Exception:
+ pass
school_schedules_dict = {ss.weekday: ss for ss in school_schedules}
school_schedules_dict[0] = school_schedules_dict.get(7)
all_schedules_purchased = []
@@ -250,7 +191,7 @@ class SummerSchoolView(TemplateView):
school_schedules_purchased = []
if all_schedules_purchased and is_previous:
live_lessons = LiveLesson.objects.filter(
- date__range=[month_start, yesterday],
+ date__range=[yesterday - timedelta(days=7), yesterday],
deactivated_at__isnull=True,
date__week_day__in=all_schedules_purchased,
).order_by('-date')
diff --git a/apps/user/templates/user/profile.html b/apps/user/templates/user/profile.html
index fd279635..e8a81d33 100644
--- a/apps/user/templates/user/profile.html
+++ b/apps/user/templates/user/profile.html
@@ -64,7 +64,7 @@
- {# #}
+
@@ -75,7 +75,6 @@
{% endif %}
- {% comment %}
{% if is_purchased_future %}
@@ -89,7 +88,7 @@
{% else %}
-
Вы не подписаны на лагерь!
+
Вы не подписаны на онлайн-школу!