Refactoring into module, part 1

This commit is contained in:
Piotr Mitros
2011-12-07 17:49:48 -05:00
parent cc1de22e26
commit 9e18b2611f
7 changed files with 111 additions and 84 deletions

View File

@@ -0,0 +1,25 @@
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