From c8d11463dc174765db45ef465b3a628175d367c3 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 13 Dec 2018 12:29:06 +0530 Subject: Create_moderator command sets is_moderator to True - Fixes #513. --- yaksh/management/commands/create_moderator.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/yaksh/management/commands/create_moderator.py b/yaksh/management/commands/create_moderator.py index 96276b5..b6bbc50 100644 --- a/yaksh/management/commands/create_moderator.py +++ b/yaksh/management/commands/create_moderator.py @@ -24,7 +24,8 @@ class Command(BaseCommand): group_name = 'moderator' group = create_group(group_name, app_label) if group and isinstance(group, Group): - self.stdout.write('Moderator group added successfully') + self.stdout.write(self.style.SUCCESS( + 'Moderator group added successfully')) if options['usernames']: for uname in options['usernames']: @@ -35,11 +36,13 @@ class Command(BaseCommand): uname) ) if user in group.user_set.all(): - self.stdout.write('User "{0}" is ' + self.stdout.write(self.style.WARNING('User "{0}" is ' 'already a Moderator'.format(uname) - ) + )) else: - group.user_set.add(user) - self.stdout.write('Successfully added User "{0}"' + user.profile.is_moderator = True + user.profile.save() + self.stdout.write(self.style.SUCCESS( + 'Successfully added User "{0}"' ' to Moderator group'.format(uname) - ) + )) -- cgit From d16d3fa6be39394bd39ae5da960f8013ffbe45ca Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Fri, 4 Jan 2019 11:44:23 +0530 Subject: Fix PEP8 and improve formatting --- yaksh/management/commands/create_moderator.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/yaksh/management/commands/create_moderator.py b/yaksh/management/commands/create_moderator.py index b6bbc50..3ec012e 100644 --- a/yaksh/management/commands/create_moderator.py +++ b/yaksh/management/commands/create_moderator.py @@ -32,17 +32,22 @@ class Command(BaseCommand): try: user = User.objects.get(username=uname) except User.DoesNotExist: - raise CommandError('User "{0}" does not exist'.format( - uname) + raise CommandError( + 'User "{0}" does not exist'.format(uname) ) if user in group.user_set.all(): - self.stdout.write(self.style.WARNING('User "{0}" is ' - 'already a Moderator'.format(uname) - )) + self.stdout.write( + self.style.WARNING( + 'User "{0}" is already' + ' a Moderator'.format(uname) + ) + ) else: user.profile.is_moderator = True user.profile.save() - self.stdout.write(self.style.SUCCESS( - 'Successfully added User "{0}"' - ' to Moderator group'.format(uname) - )) + self.stdout.write( + self.style.SUCCESS( + 'Successfully added User "{0}"' + ' to Moderator group'.format(uname) + ) + ) -- cgit