diff options
author | ankitjavalkar | 2018-03-14 12:32:37 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-03-14 12:32:37 +0530 |
commit | 62229427b651a52a2fc4d24d2a0bf764553277c0 (patch) | |
tree | 18a6a0718bbf449ff99c5453d061add2271a4d04 /yaksh/management/commands/add_moderator.py | |
parent | db267f32c158f4311c017ad3febe049a680ed5c0 (diff) | |
download | online_test-62229427b651a52a2fc4d24d2a0bf764553277c0.tar.gz online_test-62229427b651a52a2fc4d24d2a0bf764553277c0.tar.bz2 online_test-62229427b651a52a2fc4d24d2a0bf764553277c0.zip |
Add one command to create moderator group and add users to the group
Diffstat (limited to 'yaksh/management/commands/add_moderator.py')
-rw-r--r-- | yaksh/management/commands/add_moderator.py | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/yaksh/management/commands/add_moderator.py b/yaksh/management/commands/add_moderator.py deleted file mode 100644 index 5e63285..0000000 --- a/yaksh/management/commands/add_moderator.py +++ /dev/null @@ -1,37 +0,0 @@ -''' - This command adds users to the moderator group with permissions to add, change and delete - the objects in the exam app. -''' - -# django imports -from django.core.management.base import BaseCommand, CommandError -from django.contrib.auth.models import User, Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.db.utils import IntegrityError - -# Yaksh imports -from yaksh.models import Profile - -class Command(BaseCommand): - help = 'Adds users to the moderator group' - - def add_arguments(self, parser): - # Positional arguments - parser.add_argument('usernames', nargs='+', type=str) - - def handle(self, *args, **options): - try: - group = Group.objects.get(name='moderator') - except Group.DoesNotExist: - raise CommandError('Moderator Group does not exist') - - for uname in options['usernames']: - try: - user = User.objects.get(username=uname) - except User.DoesNotExist: - raise CommandError('User "{0}" does not exist'.format(uname)) - if user in group.user_set.all(): - self.stdout.write('User "{0}" is already a Moderator'.format(uname)) - else: - group.user_set.add(user) - self.stdout.write('Successfully added User "{0}" to Moderator group'.format(uname)) |