Commit b744aaa3 by Adam Palay

make sure parsed times are set to UTC

parent af522af2
...@@ -111,9 +111,9 @@ def get_date_for_press(publish_date): ...@@ -111,9 +111,9 @@ def get_date_for_press(publish_date):
# strip off extra months, and just use the first: # strip off extra months, and just use the first:
date = re.sub(multimonth_pattern, ", ", publish_date) date = re.sub(multimonth_pattern, ", ", publish_date)
if re.search(day_pattern, date): if re.search(day_pattern, date):
date = datetime.datetime.strptime(date, "%B %d, %Y") date = datetime.datetime.strptime(date, "%B %d, %Y").replace(tzinfo=UTC)
else: else:
date = datetime.datetime.strptime(date, "%B, %Y") date = datetime.datetime.strptime(date, "%B, %Y").replace(tzinfo=UTC)
return date return date
......
...@@ -32,6 +32,8 @@ import capa.xqueue_interface as xqueue_interface ...@@ -32,6 +32,8 @@ import capa.xqueue_interface as xqueue_interface
import capa.responsetypes as responsetypes import capa.responsetypes as responsetypes
from capa.safe_exec import safe_exec from capa.safe_exec import safe_exec
from pytz import UTC
# dict of tagname, Response Class -- this should come from auto-registering # dict of tagname, Response Class -- this should come from auto-registering
response_tag_dict = dict([(x.response_tag, x) for x in responsetypes.__all__]) response_tag_dict = dict([(x.response_tag, x) for x in responsetypes.__all__])
...@@ -42,13 +44,22 @@ solution_tags = ['solution'] ...@@ -42,13 +44,22 @@ solution_tags = ['solution']
response_properties = ["codeparam", "responseparam", "answer", "openendedparam"] response_properties = ["codeparam", "responseparam", "answer", "openendedparam"]
# special problem tags which should be turned into innocuous HTML # special problem tags which should be turned into innocuous HTML
html_transforms = {'problem': {'tag': 'div'}, html_transforms = {
'text': {'tag': 'span'}, 'problem': {'tag': 'div'},
'math': {'tag': 'span'}, 'text': {'tag': 'span'},
} 'math': {'tag': 'span'},
}
# These should be removed from HTML output, including all subelements # These should be removed from HTML output, including all subelements
html_problem_semantics = ["codeparam", "responseparam", "answer", "script", "hintgroup", "openendedparam", "openendedrubric"] html_problem_semantics = [
"codeparam",
"responseparam",
"answer",
"script",
"hintgroup",
"openendedparam",
"openendedrubric"
]
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -248,7 +259,7 @@ class LoncapaProblem(object): ...@@ -248,7 +259,7 @@ class LoncapaProblem(object):
if self.correct_map.is_queued(answer_id) if self.correct_map.is_queued(answer_id)
] ]
queuetimes = [ queuetimes = [
datetime.strptime(qt_str, xqueue_interface.dateformat) datetime.strptime(qt_str, xqueue_interface.dateformat).replace(tzinfo=UTC)
for qt_str in queuetime_strs for qt_str in queuetime_strs
] ]
...@@ -408,10 +419,16 @@ class LoncapaProblem(object): ...@@ -408,10 +419,16 @@ class LoncapaProblem(object):
# open using ModuleSystem OSFS filestore # open using ModuleSystem OSFS filestore
ifp = self.system.filestore.open(filename) ifp = self.system.filestore.open(filename)
except Exception as err: except Exception as err:
log.warning('Error %s in problem xml include: %s' % ( log.warning(
err, etree.tostring(inc, pretty_print=True))) 'Error %s in problem xml include: %s' % (
log.warning('Cannot find file %s in %s' % ( err, etree.tostring(inc, pretty_print=True)
filename, self.system.filestore)) )
)
log.warning(
'Cannot find file %s in %s' % (
filename, self.system.filestore
)
)
# if debugging, don't fail - just log error # if debugging, don't fail - just log error
# TODO (vshnayder): need real error handling, display to users # TODO (vshnayder): need real error handling, display to users
if not self.system.get('DEBUG'): if not self.system.get('DEBUG'):
...@@ -422,8 +439,11 @@ class LoncapaProblem(object): ...@@ -422,8 +439,11 @@ class LoncapaProblem(object):
# read in and convert to XML # read in and convert to XML
incxml = etree.XML(ifp.read()) incxml = etree.XML(ifp.read())
except Exception as err: except Exception as err:
log.warning('Error %s in problem xml include: %s' % ( log.warning(
err, etree.tostring(inc, pretty_print=True))) 'Error %s in problem xml include: %s' % (
err, etree.tostring(inc, pretty_print=True)
)
)
log.warning('Cannot parse XML in %s' % (filename)) log.warning('Cannot parse XML in %s' % (filename))
# if debugging, don't fail - just log error # if debugging, don't fail - just log error
# TODO (vshnayder): same as above # TODO (vshnayder): same as above
...@@ -583,8 +603,9 @@ class LoncapaProblem(object): ...@@ -583,8 +603,9 @@ class LoncapaProblem(object):
# let each Response render itself # let each Response render itself
if problemtree in self.responders: if problemtree in self.responders:
overall_msg = self.correct_map.get_overall_message() overall_msg = self.correct_map.get_overall_message()
return self.responders[problemtree].render_html(self._extract_html, return self.responders[problemtree].render_html(
response_msg=overall_msg) self._extract_html, response_msg=overall_msg
)
# let each custom renderer render itself: # let each custom renderer render itself:
if problemtree.tag in customrender.registry.registered_tags(): if problemtree.tag in customrender.registry.registered_tags():
...@@ -632,9 +653,10 @@ class LoncapaProblem(object): ...@@ -632,9 +653,10 @@ class LoncapaProblem(object):
answer_id = 1 answer_id = 1
input_tags = inputtypes.registry.registered_tags() input_tags = inputtypes.registry.registered_tags()
inputfields = tree.xpath("|".join(['//' + response.tag + '[@id=$id]//' + x inputfields = tree.xpath(
for x in (input_tags + solution_tags)]), "|".join(['//' + response.tag + '[@id=$id]//' + x for x in (input_tags + solution_tags)]),
id=response_id_str) id=response_id_str
)
# assign one answer_id for each input type or solution type # assign one answer_id for each input type or solution type
for entry in inputfields: for entry in inputfields:
......
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