diff options
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/admin.py | 2 | ||||
-rw-r--r-- | testapp/exam/fixtures/initial_fixture.json | 91 | ||||
-rw-r--r-- | testapp/exam/forms.py | 2 | ||||
-rw-r--r-- | testapp/exam/management/commands/add_group.py | 33 | ||||
-rw-r--r-- | testapp/exam/urls.py | 2 | ||||
-rw-r--r-- | testapp/exam/views.py | 8 |
6 files changed, 40 insertions, 98 deletions
diff --git a/testapp/exam/admin.py b/testapp/exam/admin.py index 8482ef9..060859a 100644 --- a/testapp/exam/admin.py +++ b/testapp/exam/admin.py @@ -1,4 +1,4 @@ -from exam.models import Question, Quiz +from testapp.exam.models import Question, Quiz from django.contrib import admin admin.site.register(Question) diff --git a/testapp/exam/fixtures/initial_fixture.json b/testapp/exam/fixtures/initial_fixture.json deleted file mode 100644 index da3cf18..0000000 --- a/testapp/exam/fixtures/initial_fixture.json +++ /dev/null @@ -1,91 +0,0 @@ -[ - { - "fields": { - "active": true, - "description": "\nWrite a function called <code>fact</code> which takes a single integer argument\n(say <code>n</code>) and returns the factorial of the number. \nFor example:<br/>\n<code>fact(3) -> 6</code>\n", - "options": "", - "points": 2.0, - "summary": "Factorial", - "test": "\nassert fact(0) == 1\nassert fact(5) == 120\n", - "type": "python" - }, - "model": "exam.question", - "pk": 1 - }, - { - "fields": { - "active": true, - "description": "Create a simple function called <code>sqr</code> which takes a single \nargument and returns the square of the argument. For example: <br/>\n<code>sqr(3) -> 9</code>.", - "options": "", - "points": 1.0, - "summary": "Simple function", - "test": "\nimport math\nassert sqr(3) == 9\nassert abs(sqr(math.sqrt(2)) - 2.0) < 1e-14 \n ", - "type": "python" - }, - "model": "exam.question", - "pk": 2 - }, - { - "fields": { - "active": true, - "description": "Write a shell script which takes two arguments on the\ncommand line and prints the sum of the two on the output.", - "options": "", - "points": 2.0, - "summary": "Bash addition", - "test": "docs/sample.sh\ndocs/sample.args\n", - "type": "bash" - }, - "model": "exam.question", - "pk": 3 - }, - { - "fields": { - "active": true, - "description": "What is the largest integer value that can be represented\nin Python?", - "options": "No Limit\n2**32\n2**32 - 1\nNone of the above\n", - "points": 0.5, - "summary": "Size of integer in Python", - "test": "No Limit", - "type": "mcq" - }, - "model": "exam.question", - "pk": 4 - }, - { - "fields": { - "active": true, - "description": "Basic Python Quiz 1", - "duration": 10, - "start_date": "2012-03-29" - }, - "model": "exam.quiz", - "pk": 1 - }, - { - "fields": { - "name": "moderator", - "permissions": [ - 31, - 37, - 43, - 32, - 38, - 44, - 33, - 39, - 45, - 34, - 40, - 46, - 35, - 41, - 47, - 36, - 42, - 48 - ] - }, - "model": "auth.group", - "pk": 1 - } -] diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 9d68ce2..169632d 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -1,5 +1,5 @@ from django import forms -from exam.models import Profile, Quiz, Question +from testapp.exam.models import Profile, Quiz, Question from django.contrib.auth import authenticate from django.contrib.auth.models import User 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/urls.py b/testapp/exam/urls.py index d553941..d71329c 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import patterns, include, url -urlpatterns = patterns('exam.views', +urlpatterns = patterns('testapp.exam.views', url(r'^$', 'index'), url(r'^login/$', 'user_login'), url(r'^quizzes/$','quizlist_user'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 44884fd..8fde7a7 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -15,11 +15,11 @@ from django.views.decorators.csrf import csrf_exempt from taggit.models import Tag from itertools import chain # Local imports. -from exam.models import Quiz, Question, QuestionPaper, QuestionSet -from exam.models import Profile, Answer, AnswerPaper, User -from exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\ +from testapp.exam.models import Quiz, Question, QuestionPaper, QuestionSet +from testapp.exam.models import Profile, Answer, AnswerPaper, User +from testapp.exam.forms import UserRegisterForm, UserLoginForm, QuizForm,\ QuestionForm, RandomQuestionForm -from exam.xmlrpc_clients import code_server +from testapp.exam.xmlrpc_clients import code_server from settings import URL_ROOT |