示例#1
0
    def prepare_next_chapter(self):
        """Save the previous chapter in database and prepare a new one."""

        # Save previous chapter (if any)
        if self.chapter:
            self.chapter.save()
            self.position_in_chapter = 0
            self.position_in_part += 1
            self.chapter_position_in_tutorial += 1

        # Prepare new chapter
        if self.size == 'M':
            part = self.base_part
        else:
            part = self.part

        self.chapter = Chapter(
            title=self.current_title,
            position_in_part=self.position_in_part,
            position_in_tutorial=self.chapter_position_in_tutorial,
            part=part)
示例#2
0
    def prepare_base_items(self):
        """Create the base database items and save them for the import.

        This will save optional Part and Chapter depending on the size of the
        tutorial, plus the Tutorial database instance itself.
        """
        # We create the initial tutorial database element
        self.tutorial = Tutorial(title=self.titles[0][2],
                                 size=self.size,
                                 pubdate=datetime.now())

        # We save it for the first time in order to make the m2m relations work
        self.tutorial.save()

        self.tutorial.authors.add(self.author)

        # Create required base elements depending on tutorial size
        if self.size == 'S':
            self.base_chapter = Chapter(tutorial=self.tutorial)
            self.base_chapter.save()

        elif self.size == 'M':
            self.base_part = Part(tutorial=self.tutorial)
            self.base_part.save()