Пример #1
0
 def get_chapters(self):
     chapters = []
     for key in self.chapters:
         chapter = Chapter.get(key)
         chapter.questions = list_questions(chapter)
         chapters.append(chapter)
     return chapters
Пример #2
0
 def has_chapter(self, chapter):
     """
     Check if the course has a prticular chapter
     """
     if isinstance(chapter, Chapter):
         chapter_key = chapter.key()
     else:
         chapter_key = chapter
         chapter = Chapter.get(chapter_key)
         
     if chapter_key in self.chapters:
         return True
     
     root = root_key()
     parent_chapter_key = chapter.parent_key()
     while parent_chapter_key != root and parent_chapter_key != None: 
         if parent_chapter_key in self.chapters:
             return True
         chap = Chapter.get(parent_chapter_key)
         parent_chapter_key = chap.parent_key()
         
     return False  
Пример #3
0
 def count_questions(self):
     n = 0
     for key in self.chapters:
         chapter = Chapter.get(key)
         n += count_questions(chapter)
     self.num_questions = n