summaryrefslogtreecommitdiff
path: root/yaksh/management/commands/create_moderator.py
diff options
context:
space:
mode:
authorKing2018-07-13 01:44:00 -0700
committerGitHub2018-07-13 01:44:00 -0700
commitf0f4a882a796319f766ff67cd3f8133a04054dfd (patch)
treea5c8a3ab617107743864f9faacad341d0e74da00 /yaksh/management/commands/create_moderator.py
parent661c9d82bb680e745cc6b498131a0793b954c436 (diff)
parent0af47ee9292132ab472e3e0bbae617d77437ff72 (diff)
downloadonline_test-f0f4a882a796319f766ff67cd3f8133a04054dfd.tar.gz
online_test-f0f4a882a796319f766ff67cd3f8133a04054dfd.tar.bz2
online_test-f0f4a882a796319f766ff67cd3f8133a04054dfd.zip
Merge pull request #480 from ankitjavalkar/toggle-mod
[Role based implementation] Allow moderator to switch between student and moderator roles
Diffstat (limited to 'yaksh/management/commands/create_moderator.py')
-rw-r--r--yaksh/management/commands/create_moderator.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/yaksh/management/commands/create_moderator.py b/yaksh/management/commands/create_moderator.py
index 86489d5..96276b5 100644
--- a/yaksh/management/commands/create_moderator.py
+++ b/yaksh/management/commands/create_moderator.py
@@ -7,7 +7,9 @@
# 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
+
+# local imports
+from yaksh.models import create_group
class Command(BaseCommand):
@@ -19,19 +21,9 @@ class Command(BaseCommand):
def handle(self, *args, **options):
app_label = 'yaksh'
-
- try:
- group = Group.objects.get(name='moderator')
- except Group.DoesNotExist:
- group = Group(name='moderator')
- group.save()
- # Get the models for the given app
- content_types = ContentType.objects.filter(app_label=app_label)
- # Get list of permissions for the models
- permission_list = Permission.objects.filter(
- content_type__in=content_types)
- group.permissions.add(*permission_list)
- group.save()
+ group_name = 'moderator'
+ group = create_group(group_name, app_label)
+ if group and isinstance(group, Group):
self.stdout.write('Moderator group added successfully')
if options['usernames']: