Here is another idea ...
It might be useful to use certain streams that can be identified to update the course. You can add custom attributes to current resources, if necessary, to help identify them (see this post.).
For example, you can do something like this:
... report.append(some_content) report.append(PageBreak()) report[-1].new_course = True
And configure some variables:
course_list = [...] course_iter = iter(course_list) current_course = next(course_iter)
You can then check each stream after rendering it, to see if it has this attribute and updates the current course if it does.
def afterFlowable(flowable): global current_course if hasattr(flowable, 'new_course'): current_course = next(course_iter) doc.afterFlowable = afterFlowable
HeaderOverview will be able to use the current_course variable to get the correct course, since both HeaderOverview and afterFlowable called at different points during the final build.
source share