summaryrefslogtreecommitdiff
path: root/yaksh/management
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/management')
-rw-r--r--yaksh/management/commands/add_moderator.py37
-rw-r--r--yaksh/management/commands/create_mod_group.py (renamed from yaksh/management/commands/add_group.py)4
2 files changed, 38 insertions, 3 deletions
diff --git a/yaksh/management/commands/add_moderator.py b/yaksh/management/commands/add_moderator.py
new file mode 100644
index 0000000..461c03f
--- /dev/null
+++ b/yaksh/management/commands/add_moderator.py
@@ -0,0 +1,37 @@
+'''
+ 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))
+ continue
+ group.user_set.add(user)
+ self.stdout.write('Successfully added User "{0}" to Moderator group'.format(uname))
diff --git a/yaksh/management/commands/add_group.py b/yaksh/management/commands/create_mod_group.py
index 624ff3c..0bf08df 100644
--- a/yaksh/management/commands/add_group.py
+++ b/yaksh/management/commands/create_mod_group.py
@@ -1,8 +1,6 @@
'''
- This command adds moderator group with permissions to add, change and delete
+ This command creates a moderator group with permissions to add, change and delete
the objects in the exam app.
- We can modify this command to add more groups by providing arguments.
- Arguments like group-name, app-name can be passed.
'''
# django imports