Commit fae69d2e authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add release_date timezone to lesson

parent 7159c6ea
This diff is collapsed.
......@@ -27,6 +27,7 @@ from .classroom.models import Classroom, Event
from .scheduling.models import ScheduledTask
import re
import pytz
class CourseCategory(models.Model):
......@@ -903,6 +904,7 @@ class Lesson(PositionedModel):
('draft', _('Draft')),
('published', _('Published')),
)
TIMEZONE_CHOICES = zip(pytz.all_timezones, pytz.all_timezones)
course = models.ForeignKey(
Course,
......@@ -950,6 +952,7 @@ class Lesson(PositionedModel):
blank=True,
default=None,
)
release_date_timezone = models.CharField(max_length=255, default='UTC', blank=True, choices=TIMEZONE_CHOICES)
scheduled_task = GenericRelation(ScheduledTask, related_query_name='lesson')
collection_name = 'course'
......
......@@ -38,6 +38,11 @@ def pre_lesson_created_or_updated(sender, instance: Lesson, **kwargs):
previous_lesson = Lesson.objects.get(id=instance.id)
previous_release_date = previous_lesson.release_date
if instance.release_date and instance.release_date_timezone:
import pytz
tz = pytz.timezone(instance.release_date_timezone)
instance.release_date = instance.release_date.replace(tzinfo=tz)
new_release_date = instance.release_date
if new_release_date:
......
......@@ -343,6 +343,6 @@ class TimezonesView(views.APIView):
def get(self, request, *args, **kwargs):
import pytz
import json
timezones = json.dumps({"timezones": pytz.common_timezones})
timezones = json.dumps({"timezones": pytz.all_timezones})
return HttpResponse(timezones, content_type ="application/json")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment