From a1f181e7bba387220a1033093548fb159039cc5f Mon Sep 17 00:00:00 2001 From: Don Mitchell Date: Tue, 18 Jun 2013 11:45:16 -0400 Subject: [PATCH] Make the variable and method names clearer --- common/lib/xmodule/xmodule/course_module.py | 6 +++--- common/lib/xmodule/xmodule/fields.py | 9 +++++---- common/lib/xmodule/xmodule/tests/test_fields.py | 5 ++++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 5dff0e1a20..945c3a3cfa 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -672,10 +672,10 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): @property def forum_posts_allowed(self): - datestandin = Date() + date_proxy = Date() try: - blackout_periods = [(datestandin.from_json(start), - datestandin.from_json(end)) + blackout_periods = [(date_proxy.from_json(start), + date_proxy.from_json(end)) for start, end in self.discussion_blackouts] now = datetime.now(UTC()) diff --git a/common/lib/xmodule/xmodule/fields.py b/common/lib/xmodule/xmodule/fields.py index a36934a24d..e75bbd8047 100644 --- a/common/lib/xmodule/xmodule/fields.py +++ b/common/lib/xmodule/xmodule/fields.py @@ -17,8 +17,9 @@ class Date(ModelType): ''' # See note below about not defaulting these CURRENT_YEAR = datetime.datetime.now(UTC).year - DEFAULT_DATE0 = datetime.datetime(CURRENT_YEAR, 1, 1, tzinfo=UTC) - DEFAULT_DATE1 = datetime.datetime(CURRENT_YEAR, 2, 2, tzinfo=UTC) + PREVENT_DEFAULT_DAY_MON_SEED1 = datetime.datetime(CURRENT_YEAR, 1, 1, tzinfo=UTC) + PREVENT_DEFAULT_DAY_MON_SEED2 = datetime.datetime(CURRENT_YEAR, 2, 2, tzinfo=UTC) + 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 @@ -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 # 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 - result = dateutil.parser.parse(field, default=self.DEFAULT_DATE0) - result_other = dateutil.parser.parse(field, default=self.DEFAULT_DATE1) + result = dateutil.parser.parse(field, default=self.PREVENT_DEFAULT_DAY_MON_SEED1) + result_other = dateutil.parser.parse(field, default=self.PREVENT_DEFAULT_DAY_MON_SEED1) if result != result_other: log.warning("Field {0} is missing month or day".format(self._name, field)) return None diff --git a/common/lib/xmodule/xmodule/tests/test_fields.py b/common/lib/xmodule/xmodule/tests/test_fields.py index facf60147e..f0eb082dcf 100644 --- a/common/lib/xmodule/xmodule/tests/test_fields.py +++ b/common/lib/xmodule/xmodule/tests/test_fields.py @@ -56,7 +56,10 @@ class DateTest(unittest.TestCase): DateTest.date.from_json("December 4 16:30")) 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()) delta = now - datetime.datetime.fromtimestamp(0, UTC()) self.assertEqual(DateTest.date.from_json(delta.total_seconds() * 1000),