Beispiel #1
0
    def handle(self, *args, **options):
        if len(args) == 0:
            raise CommandError("Please specify a track.md file to ingest")

        for md in args:
            print'\n\nProcessing: %s' % md
            # frontmatter is a dict, content is html
            frontmatter, content, content_md = self.read_track_file(md)

            # Ensure all the required frontmatter exists
            self.confirm_frontmatter(frontmatter)

            # Print information just for info
            self.print_frontmatter(frontmatter)
            self.stdout.write('Parsing markdown successful!')

            slug = self.generate_slug(md)

            try:
                # If something with that title already exists, update that instead
                track = Track.objects.get(slug=slug)

                self.stdout.write('Track already exists')

                track.title      = frontmatter['title']
                track.excerpt    = frontmatter['excerpt']
                track.slug       = slug
                track.thumbnail = frontmatter['thumbnail']
                track.description= content

            except Track.DoesNotExist, e:
                self.stdout.write('Track does not exist - trying to create it')
                # It doesn't exist yet - create the track object
                track = Track(title       = frontmatter['title'],
                              excerpt     = frontmatter['excerpt'],
                              slug        = slug,
                              thumbnail   = frontmatter['thumbnail'],
                              description = content)

            # Run the INSERT/UPDATE query
            track.save()
            self.stdout.write('Track update successful!')
Beispiel #2
0
    def handle(self, *args, **options):
        if 'track' not in options or len(options['track']) == 0:
            raise CommandError("Please specify a track.md file to ingest")

        for md in options['track']:
            print'\n\nProcessing: %s' % md
            # frontmatter is a dict, content is html
            frontmatter, content, content_md = self.read_track_file(md)

            # Ensure all the required frontmatter exists
            self.confirm_frontmatter(frontmatter)

            # Print information just for info
            self.print_frontmatter(frontmatter)
            self.stdout.write('Parsing markdown successful!')

            slug = self.generate_slug(md)

            try:
                # If something with that title already exists, update that instead
                track = Track.objects.get(slug=slug)

                self.stdout.write('Track already exists')

                track.title      = frontmatter['title']
                track.excerpt    = frontmatter['excerpt']
                track.slug       = slug
                track.thumbnail = frontmatter['thumbnail']
                track.description= content

            except Track.DoesNotExist, e:
                self.stdout.write('Track does not exist - trying to create it')
                # It doesn't exist yet - create the track object
                track = Track(title       = frontmatter['title'],
                              excerpt     = frontmatter['excerpt'],
                              slug        = slug,
                              thumbnail   = frontmatter['thumbnail'],
                              description = content)

            # Run the INSERT/UPDATE query
            track.save()
            self.stdout.write('Track update successful!')
                    order = TutorialSeriesOrder(series=series,
                                                tutorial=tutorial,
                                                order=frontmatter['part'])
                    order.save()

                tutorial.series = series
                tutorial.save()

            if 'track' in frontmatter:
                try:
                    track = Track.objects.get(title=frontmatter['track'])
                except Track.DoesNotExist, e:
                    self.stdout.write('Track "%s" does not exist' %
                                      frontmatter['track'])

                    track = Track(title=frontmatter['track'])
                    track.save()

                tuts = track.tutorial_list()
                if tutorial not in tuts:
                    order = TrackTutorials(track=track,
                                           tutorial=tutorial,
                                           order=frontmatter['track_part'])
                    order.save()

            # Clear the cache for this particular tutorial (if it already existed there)
            # TODO

        self.stdout.write('Next steps:')
        self.stdout.write(' * python mange.py parse_series')
        self.stdout.write(' * python mange.py update_related_tutorials')
Beispiel #4
0
                tuts = series.tutorial_list()
                if tutorial not in tuts:
                    order = TutorialSeriesOrder(series=series, tutorial=tutorial, order=frontmatter['part'])
                    order.save()

                tutorial.series = series
                tutorial.save()

            if 'track' in frontmatter:
                try:
                    track = Track.objects.get(title=frontmatter['track'])
                except Track.DoesNotExist, e:
                    self.stdout.write('Track "%s" does not exist' % frontmatter['track'])

                    track = Track(title=frontmatter['track'])
                    track.save()

                tuts = track.tutorial_list()
                if tutorial not in tuts:
                    order = TrackTutorials(track=track, tutorial=tutorial, order=frontmatter['track_part'])
                    order.save()


            # Clear the cache for this particular tutorial (if it already existed there)
            # TODO


        self.stdout.write('Next steps:')
        self.stdout.write(' * python mange.py parse_series')
        self.stdout.write(' * python mange.py update_related_tutorials')