diff options
author | ankitjavalkar | 2018-07-11 17:19:56 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-07-13 13:00:36 +0530 |
commit | e7c18d17c8b5ed193e4e34bdfe2072951d996530 (patch) | |
tree | abe3e154790aab9213ede12336a06f544ddbc79b /yaksh/models.py | |
parent | 69a07a92309105b289f4d08957729bda68727bf2 (diff) | |
download | online_test-e7c18d17c8b5ed193e4e34bdfe2072951d996530.tar.gz online_test-e7c18d17c8b5ed193e4e34bdfe2072951d996530.tar.bz2 online_test-e7c18d17c8b5ed193e4e34bdfe2072951d996530.zip |
Fix tests
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index e9d4947..7e0fbb2 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -8,7 +8,7 @@ from ruamel.yaml.comments import CommentedMap from random import sample from collections import Counter from django.db import models -from django.contrib.auth.models import User, Group +from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType from taggit.managers import TaggableManager from django.utils import timezone @@ -92,6 +92,8 @@ test_status = ( FIXTURES_DIR_PATH = os.path.join(settings.BASE_DIR, 'yaksh', 'fixtures') +MOD_GROUP_NAME = 'moderator' + def get_assignment_dir(instance, filename): upload_dir = instance.question_paper.quiz.description.replace(" ", "_") @@ -135,6 +137,21 @@ def get_file_dir(instance, filename): upload_dir = instance.name.replace(" ", "_") return os.sep.join((upload_dir, filename)) +def create_group(group_name, app_label): + try: + group = Group.objects.get(name=group_name) + except Group.DoesNotExist: + group = Group(name=group_name) + 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() + return group + ############################################################################### class CourseManager(models.Manager): @@ -1001,7 +1018,7 @@ class Profile(models.Model): os.chmod(user_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) return user_dir - def _toggle_moderator_group(self, group_name='moderator'): + def _toggle_moderator_group(self, group_name): group = Group.objects.get(name=group_name) if self.is_moderator: self.user.groups.add(group) @@ -1009,7 +1026,7 @@ class Profile(models.Model): self.user.groups.remove(group) def save(self, *args, **kwargs): - self._toggle_moderator_group() + self._toggle_moderator_group(group_name=MOD_GROUP_NAME) super(Profile, self).save(*args, **kwargs) def __str__(self): |