From 2416587c19b33261b7074767848ca6f8cc1f5c8b Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Mon, 20 Feb 2012 16:47:53 -0500 Subject: [PATCH] Minor cleanup --HG-- branch : pmitros-section --- courseware/content_parser.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/courseware/content_parser.py b/courseware/content_parser.py index 7e2ef9ca8e..536436629d 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -146,7 +146,19 @@ def user_groups(user): # TODO: Rewrite in Django return [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])] +def course_xml_process(tree): + ''' Do basic pre-processing of an XML tree. Assign IDs to all + items without. Propagate due dates, grace periods, etc. to child + items. + ''' + id_tag(tree) + propogate_downward_tag(tree, "due") + propogate_downward_tag(tree, "graded") + propogate_downward_tag(tree, "graceperiod") + def course_file(user): + ''' Given a user, return course.xml + ''' # TODO: Cache. filename = UserProfile.objects.get(user=user).courseware @@ -155,14 +167,12 @@ def course_file(user): options = {'dev_content':settings.DEV_CONTENT, 'groups' : groups} - tree = etree.XML(render_to_string(filename, options, namespace = 'course')) - id_tag(tree) - propogate_downward_tag(tree, "due") - propogate_downward_tag(tree, "graded") - propogate_downward_tag(tree, "graceperiod") + tree = course_xml_process(etree.XML(render_to_string(filename, options, namespace = 'course'))) return tree def section_file(user, section): + ''' Given a user and the name of a section, return that section + ''' filename = section+".xml" if filename not in os.listdir(settings.DATA_DIR + '/sections/'): @@ -172,11 +182,7 @@ def section_file(user, section): options = {'dev_content':settings.DEV_CONTENT, 'groups' : user_groups(user)} - tree = etree.XML(render_to_string(filename, options, namespace = 'sections')) - id_tag(tree) - propogate_downward_tag(tree, "due") - propogate_downward_tag(tree, "graded") - propogate_downward_tag(tree, "graceperiod") + tree = course_xml_process(etree.XML(render_to_string(filename, options, namespace = 'sections'))) return tree