refactor: convert from_xml to parse_xml in CourseBlock
This commit is contained in:
committed by
Piotr Surowiec
parent
da2e89db83
commit
1bfd3842c7
@@ -6,7 +6,6 @@ Django module container for classes and operations related to the "Course Module
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
|
||||
import dateutil.parser
|
||||
import requests
|
||||
@@ -1128,18 +1127,11 @@ class CourseBlock(
|
||||
return policy_str
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, xml_data, system, id_generator):
|
||||
instance = super().from_xml(xml_data, system, id_generator)
|
||||
|
||||
# bleh, have to parse the XML here to just pull out the url_name attribute
|
||||
# I don't think it's stored anywhere in the instance.
|
||||
if isinstance(xml_data, str):
|
||||
xml_data = xml_data.encode('ascii', 'ignore')
|
||||
course_file = BytesIO(xml_data)
|
||||
xml_obj = etree.parse(course_file, parser=edx_xml_parser).getroot()
|
||||
def parse_xml(cls, node, runtime, keys, id_generator):
|
||||
instance = super().parse_xml(node, runtime, keys, id_generator)
|
||||
|
||||
policy_dir = None
|
||||
url_name = xml_obj.get('url_name', xml_obj.get('slug'))
|
||||
url_name = node.get('url_name')
|
||||
if url_name:
|
||||
policy_dir = 'policies/' + url_name
|
||||
|
||||
@@ -1149,9 +1141,9 @@ class CourseBlock(
|
||||
paths = [policy_dir + '/grading_policy.json'] + paths
|
||||
|
||||
try:
|
||||
policy = json.loads(cls.read_grading_policy(paths, system))
|
||||
policy = json.loads(cls.read_grading_policy(paths, runtime))
|
||||
except ValueError:
|
||||
system.error_tracker("Unable to decode grading policy as json")
|
||||
runtime.error_tracker("Unable to decode grading policy as json")
|
||||
policy = {}
|
||||
|
||||
# now set the current instance. set_grading_policy() will apply some inheritance rules
|
||||
|
||||
Reference in New Issue
Block a user