Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions xmodule/assetstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import json
from datetime import datetime
from zoneinfo import ZoneInfo

import dateutil.parser
import pytz
from lxml import etree
from opaque_keys.edx.keys import AssetKey, CourseKey

Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, asset_id,
self.thumbnail = thumbnail
self.curr_version = curr_version
self.prev_version = prev_version
now = datetime.now(pytz.utc)
now = datetime.now(ZoneInfo("UTC"))
self.edited_by = edited_by
self.edited_by_email = edited_by_email
self.edited_on = edited_on or now
Expand Down
7 changes: 5 additions & 2 deletions xmodule/capa/capa_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from datetime import datetime
from typing import Optional
from xml.sax.saxutils import unescape
from zoneinfo import ZoneInfo

from django.conf import settings
from lxml import etree
from pytz import UTC

from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib.safe_lxml.xmlparser import XML
Expand Down Expand Up @@ -437,7 +437,10 @@ def get_recentmost_queuetime(self):
if self.correct_map.is_queued(answer_id)
]
queuetimes = [
datetime.strptime(qt_str, xqueue_interface.DATEFORMAT).replace(tzinfo=UTC) for qt_str in queuetime_strs
datetime.strptime(qt_str, xqueue_interface.DATEFORMAT).replace(
tzinfo=ZoneInfo("UTC")
)
for qt_str in queuetime_strs
]

return max(queuetimes)
Expand Down
4 changes: 2 additions & 2 deletions xmodule/capa/responsetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import namedtuple
from datetime import datetime
from sys import float_info
from zoneinfo import ZoneInfo

import html5lib
import numpy
Expand All @@ -33,7 +34,6 @@
from lxml import etree
from lxml.html.soupparser import fromstring as fromstring_bs # uses Beautiful Soup!!! FIXME?
from pyparsing import ParseException
from pytz import UTC
from shapely.geometry import MultiPoint, Point
from six.moves import map, range, zip
from symmath import symmath_check
Expand Down Expand Up @@ -2653,7 +2653,7 @@ def get_score(self, student_answers): # pylint: disable=too-many-locals
# ------------------------------------------------------------

qinterface = self.capa_system.xqueue.interface
qtime = datetime.strftime(datetime.now(UTC), DATEFORMAT)
qtime = datetime.strftime(datetime.now(ZoneInfo("UTC")), DATEFORMAT)

anonymous_student_id = self.capa_system.anonymous_student_id

Expand Down
12 changes: 6 additions & 6 deletions xmodule/capa/tests/test_responsetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import zipfile
from datetime import datetime
from unittest import mock
from zoneinfo import ZoneInfo

import calc
import pyparsing
import pytest
import random2 as random
import requests
from pytz import UTC

from xmodule.capa.correctmap import CorrectMap
from xmodule.capa.responsetypes import (
Expand Down Expand Up @@ -999,7 +999,7 @@ def test_is_queued(self):
# Now we queue the LCP
cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuestate = CodeResponseTest.make_queuestate(i, datetime.now(UTC))
queuestate = CodeResponseTest.make_queuestate(i, datetime.now(ZoneInfo("UTC")))
cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate))
self.problem.correct_map.update(cmap)

Expand All @@ -1015,7 +1015,7 @@ def test_update_score(self): # pylint: disable=too-many-locals
old_cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuekey = 1000 + i
queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(UTC))
queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(ZoneInfo("UTC")))
old_cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate))

# Message format common to external graders
Expand Down Expand Up @@ -1083,14 +1083,14 @@ def test_recentmost_queuetime(self):
cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuekey = 1000 + i
latest_timestamp = datetime.now(UTC)
latest_timestamp = datetime.now(ZoneInfo("UTC"))
queuestate = CodeResponseTest.make_queuestate(queuekey, latest_timestamp)
cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate))
self.problem.correct_map.update(cmap)

# Queue state only tracks up to second
latest_timestamp = datetime.strptime(datetime.strftime(latest_timestamp, DATEFORMAT), DATEFORMAT).replace(
tzinfo=UTC
tzinfo=ZoneInfo("UTC")
)

assert self.problem.get_recentmost_queuetime() == latest_timestamp
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def test_parse_score_msg_of_responder(self):
old_cmap = CorrectMap()
for i, answer_id in enumerate(answer_ids):
queuekey = 1000 + i
queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(UTC))
queuestate = CodeResponseTest.make_queuestate(queuekey, datetime.now(ZoneInfo("UTC")))
old_cmap.update(CorrectMap(answer_id=answer_id, queuestate=queuestate))

for grader_msg in valid_grader_msgs:
Expand Down
8 changes: 4 additions & 4 deletions xmodule/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import struct
import sys
import traceback
from zoneinfo import ZoneInfo

import nh3
from django.conf import settings
Expand All @@ -23,7 +24,6 @@
from django.utils.encoding import smart_str
from django.utils.functional import cached_property
from lxml import etree
from pytz import utc
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.exceptions import NotFoundError, ProcessingError
Expand Down Expand Up @@ -931,7 +931,7 @@ def set_last_submission_time(self):
"""
Set the module's last submission time (when the problem was submitted)
"""
self.last_submission_time = datetime.datetime.now(utc)
self.last_submission_time = datetime.datetime.now(ZoneInfo("UTC"))

def get_progress(self):
"""
Expand Down Expand Up @@ -1448,7 +1448,7 @@ def is_past_due(self):
"""
Is it now past this problem's due date, including grace period?
"""
return self.close_date is not None and datetime.datetime.now(utc) > self.close_date
return self.close_date is not None and datetime.datetime.now(ZoneInfo("UTC")) > self.close_date

def closed(self):
"""
Expand Down Expand Up @@ -1774,7 +1774,7 @@ def submit_problem( # pylint: disable=too-many-statements,too-many-branches,too
event_info["answers"] = answers_without_files

# Can override current time
current_time = datetime.datetime.now(utc)
current_time = datetime.datetime.now(ZoneInfo("UTC"))
if override_time is not False:
current_time = override_time

Expand Down
10 changes: 5 additions & 5 deletions xmodule/course_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import logging
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import dateutil.parser
import requests
Expand All @@ -15,7 +16,6 @@
from lazy import lazy
from lxml import etree
from path import Path as path
from pytz import utc
from xblock.fields import Boolean, Date, Dict, Float, Integer, List, Scope, String
from openedx.core.djangoapps.video_pipeline.models import VideoUploadsEnabledByDefault
from openedx.core.djangoapps.video_config.sharing import (
Expand Down Expand Up @@ -163,7 +163,7 @@ def table_of_contents(self):
# see if we already fetched this
if toc_url in _cached_toc:
(table_of_contents, timestamp) = _cached_toc[toc_url]
age = datetime.now(utc) - timestamp
age = datetime.now(ZoneInfo("UTC")) - timestamp
# expire every 10 minutes
if age.seconds < 600:
return table_of_contents
Expand Down Expand Up @@ -1485,7 +1485,7 @@ def forum_posts_allowed(self):

blackouts = self.get_discussion_blackout_datetimes()
posting_restrictions = self.discussions_settings.get('posting_restrictions', 'disabled')
now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))

if posting_restrictions == 'enabled':
return False
Expand Down Expand Up @@ -1601,7 +1601,7 @@ def can_toggle_course_pacing(self):
"""
if not self.start:
return False
return datetime.now(utc) <= self.start
return datetime.now(ZoneInfo("UTC")) <= self.start


class CourseSummary:
Expand Down Expand Up @@ -1674,5 +1674,5 @@ def has_ended(self):
course_id=str(self.id), end_date=self.end, err=e
)
)
modified_end = self.end.replace(tzinfo=utc)
modified_end = self.end.replace(tzinfo=ZoneInfo("UTC"))
return course_metadata_utils.has_course_ended(modified_end)
23 changes: 12 additions & 11 deletions xmodule/course_metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
"""


import dateutil.parser

from base64 import b32encode
from datetime import datetime, timedelta
from math import exp
from zoneinfo import ZoneInfo

import dateutil.parser
from pytz import utc

DEFAULT_START_DATE = datetime(2030, 1, 1, tzinfo=utc)
DEFAULT_START_DATE = datetime(2030, 1, 1, tzinfo=ZoneInfo("UTC"))

"""
Default grading policy for a course run.
Expand Down Expand Up @@ -95,7 +96,7 @@ def has_course_started(start_date):
start_date (datetime): The start datetime of the course in question.
"""
# TODO: This will throw if start_date is None... consider changing this behavior?
return datetime.now(utc) > start_date
return datetime.now(ZoneInfo("UTC")) > start_date


def has_course_ended(end_date):
Expand All @@ -107,7 +108,7 @@ def has_course_ended(end_date):
Arguments:
end_date (datetime): The end datetime of the course in question.
"""
return datetime.now(utc) > end_date if end_date is not None else False
return datetime.now(ZoneInfo("UTC")) > end_date if end_date is not None else False


def is_enrollment_open(enrollment_start_date, enrollment_end_date):
Expand All @@ -118,9 +119,9 @@ def is_enrollment_open(enrollment_start_date, enrollment_end_date):
enrollment_start_date (datetime): The enrollment start datetime of the course.
enrollment_end_date (datetime): The enrollment end datetime of the course.
"""
now = datetime.now(utc)
enrollment_start_date = enrollment_start_date or datetime.min.replace(tzinfo=utc)
enrollment_end_date = enrollment_end_date or datetime.max.replace(tzinfo=utc)
now = datetime.now(ZoneInfo("UTC"))
enrollment_start_date = enrollment_start_date or datetime.min.replace(tzinfo=ZoneInfo("UTC"))
enrollment_end_date = enrollment_end_date or datetime.max.replace(tzinfo=ZoneInfo("UTC"))
return enrollment_start_date < now < enrollment_end_date


Expand All @@ -133,7 +134,7 @@ def course_starts_within(start_date, look_ahead_days):
start_date (datetime): The start datetime of the course in question.
look_ahead_days (int): number of days to see in future for course start date.
"""
return datetime.now(utc) + timedelta(days=look_ahead_days) > start_date
return datetime.now(ZoneInfo("UTC")) + timedelta(days=look_ahead_days) > start_date


def course_start_date_is_default(start, advertised_start):
Expand Down Expand Up @@ -179,10 +180,10 @@ def sorting_dates(start, advertised_start, announcement):
try:
start = dateutil.parser.parse(advertised_start)
if start.tzinfo is None:
start = start.replace(tzinfo=utc)
start = start.replace(tzinfo=ZoneInfo("UTC"))
except (TypeError, ValueError, AttributeError):
start = start # lint-amnesty, pylint: disable=self-assigning-variable

now = datetime.now(utc)
now = datetime.now(ZoneInfo("UTC"))

return announcement, start, now
4 changes: 2 additions & 2 deletions xmodule/lti_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
from unittest import mock
from urllib import parse
from xml.sax.saxutils import escape
from zoneinfo import ZoneInfo

import nh3
import oauthlib.oauth1
from django.conf import settings
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import List, Scope, String, XBlock
Expand Down Expand Up @@ -989,7 +989,7 @@ def is_past_due(self):
close_date = due_date + self.graceperiod # pylint: disable=no-member
else:
close_date = due_date
return close_date is not None and datetime.datetime.now(UTC) > close_date
return close_date is not None and datetime.datetime.now(ZoneInfo("UTC")) > close_date


LTIBlock = (
Expand Down
8 changes: 4 additions & 4 deletions xmodule/modulestore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from collections import defaultdict
from contextlib import contextmanager
from operator import itemgetter
from django.db import transaction
from zoneinfo import ZoneInfo

from django.db import transaction
from opaque_keys.edx.keys import AssetKey, CourseKey
from opaque_keys.edx.locations import Location # For import backwards compatibility
from pytz import UTC
from sortedcontainers import SortedKeyList
from xblock.core import XBlock
from xblock.plugin import default_select
Expand Down Expand Up @@ -719,7 +719,7 @@ def _save_assets_by_type(self, course_key, asset_metadata_list, course_assets, u
))
continue
if not import_only:
asset_md.update({'edited_by': user_id, 'edited_on': datetime.datetime.now(UTC)})
asset_md.update({'edited_by': user_id, 'edited_on': datetime.datetime.now(ZoneInfo("UTC"))})
asset_type = asset_md.asset_id.asset_type
all_assets = assets_by_type[asset_type]
all_assets.insert_or_update(asset_md)
Expand Down Expand Up @@ -862,7 +862,7 @@ def _block_matches(self, block, qualifiers):
For substring matching:
pass a regex object.
For arbitrary function comparison such as date time comparison:
pass the function as in start=lambda x: x < datetime.datetime(2014, 1, 1, 0, tzinfo=pytz.UTC)
pass the function as in start=lambda x: x < datetime.datetime(2014, 1, 1, 0, tzinfo=ZoneInfo("UTC"))

Args:
block (dict, XBlock, or BlockData): either the BlockData (transformed from the db) -or-
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/mongo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
from datetime import datetime
from importlib import import_module
from uuid import uuid4
from zoneinfo import ZoneInfo

import pymongo
from bson.son import SON
from fs.osfs import OSFS
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator, LibraryLocator
from path import Path as path
from pytz import UTC
from xblock.exceptions import InvalidScopeError
from xblock.fields import Reference, ReferenceList, ReferenceValueDict, Scope, ScopeIds
from xblock.runtime import KvsFieldData
Expand Down Expand Up @@ -252,7 +252,7 @@ def load_item(self, location, for_parent=None): # lint-amnesty, pylint: disable
if raw_metadata.get('published_date'):
block._edit_info['published_date'] = datetime(
*raw_metadata.get('published_date')[0:6]
).replace(tzinfo=UTC)
).replace(tzinfo=ZoneInfo("UTC"))
block._edit_info['published_by'] = raw_metadata.get('published_by')

for wrapper in self.modulestore.xblock_field_data_wrappers:
Expand Down
Loading
Loading