Commit a1f181e7 by Don Mitchell

Make the variable and method names clearer

parent 085a590b
...@@ -672,10 +672,10 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): ...@@ -672,10 +672,10 @@ class CourseDescriptor(CourseFields, SequenceDescriptor):
@property @property
def forum_posts_allowed(self): def forum_posts_allowed(self):
datestandin = Date() date_proxy = Date()
try: try:
blackout_periods = [(datestandin.from_json(start), blackout_periods = [(date_proxy.from_json(start),
datestandin.from_json(end)) date_proxy.from_json(end))
for start, end for start, end
in self.discussion_blackouts] in self.discussion_blackouts]
now = datetime.now(UTC()) now = datetime.now(UTC())
......
...@@ -17,8 +17,9 @@ class Date(ModelType): ...@@ -17,8 +17,9 @@ class Date(ModelType):
''' '''
# See note below about not defaulting these # See note below about not defaulting these
CURRENT_YEAR = datetime.datetime.now(UTC).year CURRENT_YEAR = datetime.datetime.now(UTC).year
DEFAULT_DATE0 = datetime.datetime(CURRENT_YEAR, 1, 1, tzinfo=UTC) PREVENT_DEFAULT_DAY_MON_SEED1 = datetime.datetime(CURRENT_YEAR, 1, 1, tzinfo=UTC)
DEFAULT_DATE1 = datetime.datetime(CURRENT_YEAR, 2, 2, tzinfo=UTC) PREVENT_DEFAULT_DAY_MON_SEED2 = datetime.datetime(CURRENT_YEAR, 2, 2, tzinfo=UTC)
def _parse_date_wo_default_month_day(self, field): def _parse_date_wo_default_month_day(self, field):
""" """
Parse the field as an iso string but prevent dateutils from defaulting the day or month while Parse the field as an iso string but prevent dateutils from defaulting the day or month while
...@@ -27,8 +28,8 @@ class Date(ModelType): ...@@ -27,8 +28,8 @@ class Date(ModelType):
# It's not trivial to replace dateutil b/c parsing timezones as Z, +03:30, -400 is hard in python # It's not trivial to replace dateutil b/c parsing timezones as Z, +03:30, -400 is hard in python
# however, we don't want dateutil to default the month or day (but some tests at least expect # however, we don't want dateutil to default the month or day (but some tests at least expect
# us to default year); so, we'll see if dateutil uses the defaults for these the hard way # us to default year); so, we'll see if dateutil uses the defaults for these the hard way
result = dateutil.parser.parse(field, default=self.DEFAULT_DATE0) result = dateutil.parser.parse(field, default=self.PREVENT_DEFAULT_DAY_MON_SEED1)
result_other = dateutil.parser.parse(field, default=self.DEFAULT_DATE1) result_other = dateutil.parser.parse(field, default=self.PREVENT_DEFAULT_DAY_MON_SEED1)
if result != result_other: if result != result_other:
log.warning("Field {0} is missing month or day".format(self._name, field)) log.warning("Field {0} is missing month or day".format(self._name, field))
return None return None
......
...@@ -56,7 +56,10 @@ class DateTest(unittest.TestCase): ...@@ -56,7 +56,10 @@ class DateTest(unittest.TestCase):
DateTest.date.from_json("December 4 16:30")) DateTest.date.from_json("December 4 16:30"))
self.assertIsNone(DateTest.date.from_json("12 12:00")) self.assertIsNone(DateTest.date.from_json("12 12:00"))
def test_odd_from_json(self): def test_non_std_from_json(self):
"""
Test the non-standard args being passed to from_json
"""
now = datetime.datetime.now(UTC()) now = datetime.datetime.now(UTC())
delta = now - datetime.datetime.fromtimestamp(0, UTC()) delta = now - datetime.datetime.fromtimestamp(0, UTC())
self.assertEqual(DateTest.date.from_json(delta.total_seconds() * 1000), self.assertEqual(DateTest.date.from_json(delta.total_seconds() * 1000),
......
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