Пример #1
0
    def prepare_next_part(self):
        """Save the previous part in database and prepare a new one."""

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

        # Prepare new part
        self.part = Part(title=self.current_title,
                         position_in_tutorial=self.position_in_tutorial,
                         tutorial=self.tutorial)
Пример #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()