From 3b6ad62f9fe5d037bbbbb97b80b28449a721dd46 Mon Sep 17 00:00:00 2001 From: gzbender Date: Thu, 25 Apr 2019 04:19:31 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B0=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D1=81=D0=BA=D1=83=D1=8E=20=D0=BF=D1=83=D0=B1=D0=BB=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8E=20=D1=83=D1=80=D0=BE=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=2017-00?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/school/models.py | 28 ++++++++++++++----- .../templates/blocks/schedule_item.html | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/school/models.py b/apps/school/models.py index c6eb5ba8..771f01bb 100644 --- a/apps/school/models.py +++ b/apps/school/models.py @@ -153,13 +153,27 @@ class LiveLesson(BaseModel, DeactivatedMixin): def stream_index(self): return self.stream.split('/')[-1] - def is_online(self): + @cached_property + def school_schedule(self): weekday = self.date.isoweekday() if self.date else None try: - school_schedule = SchoolSchedule.objects.get(weekday=weekday) + return SchoolSchedule.objects.get(weekday=weekday) except SchoolSchedule.DoesNotExist: - return False - else: - start_at = school_schedule.start_at - end_at = datetime.combine(now().today(), start_at) + timedelta(hours=1) - return start_at <= now().time() and end_at.time() >= now().time() + return None + + @property + def is_online(self): + # если урок открыт, он сегодняшний и прошло не больше часа с момента старта - значит онлайн + if self.is_opened and self.school_schedule: + today = now().date() + end_at = datetime.combine(today, self.school_schedule.start_at) + timedelta(hours=1) + return self.date == today and end_at.time() >= now().time() + return False + + @property + def is_opened(self): + # если есть заголовок и дата меньше сегодняшней (прошлый урок) или сегодняшняя и время показа урока уже пришло + # тогда урок считается открытым к просмотру + today = now().date() + return self.title and (self.date < today or (self.date == today and self.school_schedule + and self.school_schedule.start_at <= now().time())) diff --git a/apps/school/templates/blocks/schedule_item.html b/apps/school/templates/blocks/schedule_item.html index c8342620..1c37334e 100644 --- a/apps/school/templates/blocks/schedule_item.html +++ b/apps/school/templates/blocks/schedule_item.html @@ -16,7 +16,7 @@
{{ school_schedule.start_at }} (МСК)
{% if is_purchased and school_schedule.weekday in school_schedules_purchased or is_previous %} - {% if live_lesson and live_lesson.title %} + {% if live_lesson.is_opened %} {% include './open_lesson.html' %} {% endif %} {% else %}