Merge branch 'feature/auto-open-live-lesson-25-04-19' into 'master'

сделать автоматическую публикацию урока в 17-00

See merge request lilschool/site!293
remotes/origin/feature/birthday-postcard-25-04-19
Danil 7 years ago
commit c043d3b956
  1. 28
      apps/school/models.py
  2. 2
      apps/school/templates/blocks/schedule_item.html

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

@ -16,7 +16,7 @@
<div class="timing__time">{{ school_schedule.start_at }} (МСК)</div>
<div class="timing__buy">
{% 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 %}

Loading…
Cancel
Save