Exemplo n.º 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_user_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!')

            try:
                # If something with that title already exists, update that instead
                user = User.objects.get(email=frontmatter['email'])
                aiuser = AishackUser.objects.get(user=user)

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

                user.first_name = frontmatter['firstname']
                user.last_name = frontmatter['lastname']
                aiuser.short_bio = frontmatter['short_bio']
                aiuser.website = frontmatter['website']
                aiuser.bio = content

                user.save()
                aiuser.save()

            except User.DoesNotExist, e:
                self.stdout.write('User does not exist - trying to create it')
                # It doesn't exist yet - create the track object
                username = self.generate_username(md)
                user = User(username=username,
                            first_name=frontmatter['firstname'],
                            last_name=frontmatter['lastname'],
                            email=frontmatter['email'],
                            is_staff=False,
                            is_superuser=False)
                user.save()

                aiuser = AishackUser(user=user,
                                     short_bio=frontmatter['short_bio'],
                                     website=frontmatter['website'],
                                     bio=content)
                aiuser.save()
            except AishackUser.DoesNotExist, e:
                aiuser = AishackUser(user=user,
                                     short_bio=frontmatter['short_bio'],
                                     website=frontmatter['website'],
                                     bio=content)
                aiuser.save()
Exemplo n.º 2
0
    def handle(self, *args, **options):
        if 'user' not in options or len(options['user']) == 0:
            raise CommandError("Please specify a track.md file to ingest")

        for md in options['user']:
            print'\n\nProcessing: %s' % md
            # frontmatter is a dict, content is html
            frontmatter, content, content_md = self.read_user_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!')


            try:
                # If something with that title already exists, update that instead
                user = User.objects.get(email=frontmatter['email'])
                aiuser = AishackUser.objects.get(user = user)

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

                user.first_name   = frontmatter['firstname']
                user.last_name    = frontmatter['lastname']
                aiuser.short_bio  = frontmatter['short_bio']
                aiuser.website    = frontmatter['website']
                aiuser.bio        = content

                user.save()
                aiuser.save()

            except User.DoesNotExist, e:
                self.stdout.write('User does not exist - trying to create it')
                # It doesn't exist yet - create the track object
                username = self.generate_username(md)
                user = User(username = username,
                            first_name = frontmatter['firstname'],
                            last_name = frontmatter['lastname'],
                            email = frontmatter['email'],
                            is_staff = False,
                            is_superuser = False)
                user.save()
                
                aiuser = AishackUser(user = user,
                                     short_bio = frontmatter['short_bio'],
                                     website = frontmatter['website'],
                                     bio = content)
                aiuser.save()
            except AishackUser.DoesNotExist, e:
                aiuser = AishackUser(user = user,
                                     short_bio = frontmatter['short_bio'],
                                     website = frontmatter['website'],
                                     bio = content)
                aiuser.save()
Exemplo n.º 3
0
def get_aishack_user(user):
    try:
        aishack_user = AishackUser.objects.get(user=user)
    except AishackUser.DoesNotExist, e:
        aishack_user = AishackUser(user=user)
        aishack_user.save()
Exemplo n.º 4
0
def get_aishack_user(user):
    try:
        aishack_user = AishackUser.objects.get(user=user)
    except AishackUser.DoesNotExist, e:
        aishack_user = AishackUser(user=user)
        aishack_user.save()