26 lines
1.0 KiB
Python
26 lines
1.0 KiB
Python
from django.conf import settings
|
|
from xml.dom.minidom import parse, parseString
|
|
|
|
|
|
def toc_from_xml(active_chapter,active_section):
|
|
dom=parse(settings.DATA_DIR+'course.xml')
|
|
|
|
course = dom.getElementsByTagName('course')[0]
|
|
name=course.getAttribute("name")
|
|
chapters = course.getElementsByTagName('chapter')
|
|
ch=list()
|
|
for c in chapters:
|
|
sections=list()
|
|
for s in c.getElementsByTagName('section'):
|
|
sections.append({'name':s.getAttribute("name"),
|
|
'time':s.getAttribute("time"),
|
|
'format':s.getAttribute("format"),
|
|
'due':s.getAttribute("due"),
|
|
'active':(c.getAttribute("name")==active_chapter and \
|
|
s.getAttribute("name")==active_section)})
|
|
ch.append({'name':c.getAttribute("name"),
|
|
'sections':sections,
|
|
'active':(c.getAttribute("name")==active_chapter)})
|
|
return ch
|
|
|