summaryrefslogtreecommitdiff
path: root/testapp/exam/management
diff options
context:
space:
mode:
authorprathamesh2015-02-19 12:36:02 +0530
committerprathamesh2015-02-19 12:36:02 +0530
commite7e82959bb819e60ef5ab21f1950404d20e661a8 (patch)
tree1fd64709e32dcb1a21332ebb3045c8723ea8c4be /testapp/exam/management
parent962cee1705509bb595cda51d104ef1ef7cf0b4fd (diff)
parent663e9945eddeda6bfe37b5d64c1a08a85d222f3e (diff)
downloadonline_test-e7e82959bb819e60ef5ab21f1950404d20e661a8.tar.gz
online_test-e7e82959bb819e60ef5ab21f1950404d20e661a8.tar.bz2
online_test-e7e82959bb819e60ef5ab21f1950404d20e661a8.zip
Merge branch 'app_package' into redirect_result_view
Diffstat (limited to 'testapp/exam/management')
-rw-r--r--testapp/exam/management/commands/add_group.py33
-rw-r--r--testapp/exam/management/commands/dump_user_data.py4
-rw-r--r--testapp/exam/management/commands/load_exam.py2
-rw-r--r--testapp/exam/management/commands/load_questions_xml.py2
-rw-r--r--testapp/exam/management/commands/results2csv.py2
5 files changed, 38 insertions, 5 deletions
diff --git a/testapp/exam/management/commands/add_group.py b/testapp/exam/management/commands/add_group.py
new file mode 100644
index 0000000..76cc655
--- /dev/null
+++ b/testapp/exam/management/commands/add_group.py
@@ -0,0 +1,33 @@
+'''
+ This command adds 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
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import Group, Permission
+from django.contrib.contenttypes.models import ContentType
+from django.db.utils import IntegrityError
+
+class Command(BaseCommand):
+ help = 'Adds the moderator group'
+
+ def handle(self, *args, **options):
+ app = 'exam'
+ group = Group(name='moderator')
+ try:
+ group.save()
+ except IntegrityError:
+ raise CommandError("The group already exits")
+ else:
+ # Get the models for the given app
+ content_types = ContentType.objects.filter(app_label=app)
+ # Get list of permissions for the models
+ permission_list = Permission.objects.filter(content_type=content_types)
+ for permission in permission_list:
+ group.permissions.add(permission)
+ group.save()
+
+ self.stdout.write('Moderator group added successfully')
diff --git a/testapp/exam/management/commands/dump_user_data.py b/testapp/exam/management/commands/dump_user_data.py
index ec016bb..c5537e5 100644
--- a/testapp/exam/management/commands/dump_user_data.py
+++ b/testapp/exam/management/commands/dump_user_data.py
@@ -5,8 +5,8 @@ from django.core.management.base import BaseCommand
from django.template import Template, Context
# Local imports.
-from exam.views import get_user_data
-from exam.models import User
+from testapp.exam.views import get_user_data
+from testapp.exam.models import User
data_template = Template('''\
===============================================================================
diff --git a/testapp/exam/management/commands/load_exam.py b/testapp/exam/management/commands/load_exam.py
index e3f72da..c4a34a3 100644
--- a/testapp/exam/management/commands/load_exam.py
+++ b/testapp/exam/management/commands/load_exam.py
@@ -5,7 +5,7 @@ from os.path import basename
from django.core.management.base import BaseCommand
# Local imports.
-from exam.models import Question, Quiz
+from testapp.exam.models import Question, Quiz
def clear_exam():
"""Deactivate all questions from the database."""
diff --git a/testapp/exam/management/commands/load_questions_xml.py b/testapp/exam/management/commands/load_questions_xml.py
index 8bc2701..3e13ae1 100644
--- a/testapp/exam/management/commands/load_questions_xml.py
+++ b/testapp/exam/management/commands/load_questions_xml.py
@@ -8,7 +8,7 @@ import re
from django.core.management.base import BaseCommand
# Local imports.
-from exam.models import Question
+from testapp.exam.models import Question
def decode_html(html_str):
"""Un-escape or decode HTML strings to more usable Python strings.
diff --git a/testapp/exam/management/commands/results2csv.py b/testapp/exam/management/commands/results2csv.py
index 2993745..1cdf8e3 100644
--- a/testapp/exam/management/commands/results2csv.py
+++ b/testapp/exam/management/commands/results2csv.py
@@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand
from django.template import Template, Context
# Local imports.
-from exam.models import Quiz, QuestionPaper
+from testapp.exam.models import Quiz, QuestionPaper
result_template = Template('''\
"name","username","rollno","email","answered","total","attempts","position",\