Commit 8539b926 by Piotr Mitros

Profile page uses lxml

parent 591f9023
......@@ -83,17 +83,17 @@ def module_xml(coursefile, module, id_tag, module_id):
#return result_set[0].serialize()
def toc_from_xml(coursefile, active_chapter, active_section):
dom2 = etree.parse(coursefile)
dom = etree.parse(coursefile)
name = dom2.xpath('//course/@name')[0]
name = dom.xpath('//course/@name')[0]
chapters = dom2.xpath('//course[@name=$name]/chapter', name=name)
chapters = dom.xpath('//course[@name=$name]/chapter', name=name)
ch=list()
for c in chapters:
if c.get('name') == 'hidden':
continue
sections=list()
for s in dom2.xpath('//course[@name=$name]/chapter[@name=$chname]/section', name=name, chname=c.get('name')):
for s in dom.xpath('//course[@name=$name]/chapter[@name=$chname]/section', name=name, chname=c.get('name')):
sections.append({'name':s.get("name") or "",
'time':s.get("time") or "",
'format':s.get("format") or "",
......
......@@ -31,6 +31,8 @@ import uuid
from module_render import *
from lxml import etree
template_imports={'urllib':urllib}
def profile(request):
......@@ -39,20 +41,23 @@ def profile(request):
if not request.user.is_authenticated():
return redirect('/')
dom=parse(content_parser.course_file(request.user))
dom=etree.parse(content_parser.course_file(request.user))
hw=[]
course = dom.getElementsByTagName('course')[0]
chapters = course.getElementsByTagName('chapter')
course = dom.xpath('//course/@name')[0]
chapters = dom.xpath('//course[@name=$course]/chapter', course=course)
responses=StudentModule.objects.filter(student=request.user)
for c in chapters:
for s in c.getElementsByTagName('section'):
problems=s.getElementsByTagName('problem')
chname=c.get('name')
for s in dom.xpath('//course[@name=$course]/chapter[@name=$chname]/section',
course=course, chname=chname):
problems=dom.xpath('//course[@name=$course]/chapter[@name=$chname]/section[@name=$section]//problem',
course=course, chname=chname, section=s.get('name'))
scores=[]
if len(problems)>0:
for p in problems:
id = p.getAttribute('filename')
id = p.get('filename')
correct = 0
for response in responses:
if response.module_id == id:
......@@ -60,11 +65,11 @@ def profile(request):
correct=response.grade
else:
correct=0
total=capa_module.LoncapaModule(p.toxml(), "id").max_score() # TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
total=capa_module.LoncapaModule(etree.tostring(p), "id").max_score() # TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
scores.append((int(correct),total))
score={'course':course.getAttribute('name'),
'section':s.getAttribute("name"),
'chapter':c.getAttribute("name"),
score={'course':course,
'section':s.get("name"),
'chapter':c.get("name"),
'scores':scores,
}
hw.append(score)
......
settings_new_askbot.py
\ No newline at end of file
settings_old_askbot.py
\ No newline at end of file
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