Dynamically find the start and end pages of a textbook instead of hardcoding to 6.002 values

This commit is contained in:
David Ormsbee
2012-09-19 17:12:08 -04:00
parent 10a838cb01
commit f9a49ece6f
3 changed files with 17 additions and 4 deletions

View File

@@ -21,7 +21,15 @@ class CourseDescriptor(SequenceDescriptor):
self.title = title
self.book_url = book_url
self.table_of_contents = self._get_toc_from_s3()
self.start_page = int(self.table_of_contents[0].attrib['page'])
# The last page should be the last element in the table of contents,
# but it may be nested. So recurse all the way down the last element
last_el = self.table_of_contents[-1]
while last_el.getchildren():
last_el = last_el[-1]
self.end_page = int(last_el.attrib['page'])
@property
def table_of_contents(self):