From 2a0909ef9d1107ec09a870947946cb336f0373c3 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Thu, 25 Aug 2016 16:23:43 +0530
Subject: added upload and download questions with files
---
yaksh/models.py | 46 +++++++++++++++++++++++++++++++++++++++-------
yaksh/views.py | 44 +++++++++++++++++++++++++++++++++-----------
2 files changed, 72 insertions(+), 18 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/models.py b/yaksh/models.py
index 73d4b27..d626b26 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -10,9 +10,13 @@ from django.forms.models import model_to_dict
from django.contrib.contenttypes.models import ContentType
from taggit.managers import TaggableManager
from django.utils import timezone
+from django.core.files import File
+from StringIO import StringIO
import pytz
import os
import shutil
+import zipfile
+
languages = (
("python", "Python"),
@@ -231,27 +235,32 @@ class Question(models.Model):
def dump_into_json(self, question_ids, user):
questions = Question.objects.filter(id__in=question_ids, user_id=user.id)
questions_dict = []
+ zip_file_name = StringIO()
+ zip_file = zipfile.ZipFile(zip_file_name, "a")
for question in questions:
test_case = question.get_test_cases()
+ files = question._add_and_get_files(zip_file)
q_dict = {'summary': question.summary,
'description': question.description,
- 'points': question.points,
- 'language': question.language,
- 'type': question.type,
- 'active': question.active,
+ 'points': question.points, 'language': question.language,
+ 'type': question.type, 'active': question.active,
'test_case_type': question.test_case_type,
'snippet': question.snippet,
- 'testcase': [case.get_field_value() for case in test_case]}
+ 'testcase': [case.get_field_value() for case in test_case],
+ 'files': files}
questions_dict.append(q_dict)
-
- return json.dumps(questions_dict, indent=2)
+ question._add_json_to_zip(zip_file, questions_dict)
+ return zip_file_name
def load_from_json(self, questions_list, user):
questions = json.loads(questions_list)
+ ques = Question()
for question in questions:
question['user'] = user
+ files = question.pop('files')
test_cases = question.pop('testcase')
que, result = Question.objects.get_or_create(**question)
+ que._add_files_to_db(files)
model_class = get_model_class(que.test_case_type)
for test_case in test_cases:
model_class.objects.get_or_create(question=que, **test_case)
@@ -278,6 +287,29 @@ class Question(models.Model):
return test_case
+ def _add_and_get_files(self, zip_file):
+ files = FileUpload.objects.filter(question=self)
+ for file in files:
+ zip_file.write(file.file.path, (os.path.basename(file.file.path)))
+ files_list = [os.path.basename(file.file.name) for file in files]
+ return files_list
+
+ def _add_files_to_db(self, files):
+ if files:
+ for file_name in files:
+ file = open(file_name, 'r')
+ django_file = File(file)
+ f = FileUpload.objects.get_or_create(file=django_file, question=self)
+ os.remove(file_name)
+
+ def _add_json_to_zip(self, zip_file, q_dict):
+ json_data = json.dumps(q_dict, indent=2)
+ with open("questions_dump.json", "w") as json_file:
+ json_file.write(json_data)
+ zip_file.write(json_file.name)
+ zip_file.close()
+ os.remove(json_file.name)
+
def __unicode__(self):
return self.summary
diff --git a/yaksh/views.py b/yaksh/views.py
index e1ec44e..87e6005 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -22,6 +22,7 @@ import pytz
from taggit.models import Tag
from itertools import chain
import json
+import zipfile
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
@@ -73,6 +74,7 @@ def is_moderator(user):
if user.groups.filter(name='moderator').exists():
return True
+
def add_to_group(users):
""" add users to moderator group """
group = Group.objects.get(name="moderator")
@@ -80,6 +82,22 @@ def add_to_group(users):
if not is_moderator(user):
user.groups.add(group)
+
+def extract_files(questions_file):
+ if zipfile.is_zipfile(questions_file):
+ zip_file = zipfile.ZipFile(questions_file, 'r')
+ zip_file.extractall()
+
+
+def read_json(json_file, user):
+ question = Question()
+ if os.path.exists(json_file):
+ with open(json_file, 'r') as q_file:
+ questions_list = q_file.read()
+ question.load_from_json(questions_list, user)
+ os.remove(json_file)
+
+
def index(request):
"""The start page.
"""
@@ -663,9 +681,11 @@ def courses(request):
ci = RequestContext(request)
if not is_moderator(user):
raise Http404('You are not allowed to view this page')
- courses = Course.objects.filter(creator=user, is_trial=False)
+ demo_user = User.objects.get(username="demo_user")
+ courses = Course.objects.filter(Q(creator=user) | Q(creator=demo_user),
+ is_trial=False)
return my_render_to_response('yaksh/courses.html', {'courses': courses},
- context_instance=ci)
+ context_instance=ci)
@login_required
@@ -869,22 +889,24 @@ def show_all_questions(request):
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
questions_file = request.FILES['file']
- if questions_file.name.split('.')[-1] == "json":
- questions_list = questions_file.read()
- question = Question()
- question.load_from_json(questions_list, user)
+ file_name = questions_file.name.split('.')
+ if file_name[-1] == "zip":
+ extract_files(questions_file)
+ read_json("questions_dump.json", user)
else:
- message = "Please Upload a JSON file"
+ message = "Please Upload a ZIP file"
context['message'] = message
if request.POST.get('download') == 'download':
question_ids = request.POST.getlist('question')
if question_ids:
question = Question()
- questions = question.dump_into_json(question_ids, user)
- response = HttpResponse(questions, content_type='text/json')
- response['Content-Disposition'] = 'attachment; filename=\
- "{0}_questions.json"'.format(user)
+ zip_file = question.dump_into_json(question_ids, user)
+ response = HttpResponse(content_type='application/zip')
+ response['Content-Disposition'] = '''attachment;\
+ filename={0}_questions.zip'''.format(user)
+ zip_file.seek(0)
+ response.write(zip_file.read())
return response
else:
context['msg'] = "Please select atleast one question to download"
--
cgit
From 074ca3fe68b790279c6ed8e0dda580b5ade8586e Mon Sep 17 00:00:00 2001
From: adityacp
Date: Thu, 25 Aug 2016 16:24:56 +0530
Subject: changed templates to view demo quiz
---
yaksh/templates/yaksh/courses.html | 5 ++++-
yaksh/templates/yaksh/showquestions.html | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html
index 06c848c..910a68d 100644
--- a/yaksh/templates/yaksh/courses.html
+++ b/yaksh/templates/yaksh/courses.html
@@ -15,9 +15,12 @@
{% else %}
Course(s) Added
{% for course in courses %}
- {% if user != course.creator %}
+ {% if user != course.creator and course.name != "Demo_course"%}
{{course.creator.get_full_name}} added you to this course
{% endif %}
+ {% if course.name == "Demo_course" %}
+ This is Demo Course
+ {% endif %}
diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html
index 2f4d218..185cbfb 100644
--- a/yaksh/templates/yaksh/showquestions.html
+++ b/yaksh/templates/yaksh/showquestions.html
@@ -11,7 +11,7 @@
{% block manage %}
-
Upload json file for adding questions
+
Upload ZIP file for adding questions
@@ -156,7 +157,7 @@
{% if demo_course %}
{% with demo_course as course %}
-
This is a Demo Course
+ Demo Course
Help
@@ -199,7 +200,7 @@
{% endwith %}
-{% endif %}
+{% endif %}
{% endblock %}
--
cgit
From 4bc766cb85fd999a8e2ac6d7e87e62730edb1244 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Mon, 19 Sep 2016 14:47:09 +0530
Subject: removed string comparison for demo course
---
yaksh/test_views.py | 9 ++++++---
yaksh/views.py | 12 +++++++++---
2 files changed, 15 insertions(+), 6 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 4f9b18d..e88956c 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -650,9 +650,12 @@ class TestCourses(TestCase):
self.client = Client()
self.mod_group = Group.objects.create(name='moderator')
- User.objects.get_or_create(username='demo_user',
- password='demo',
- email='demo@test.com')
+ user = User.objects.get_or_create(username='yaksh_demo_user',
+ password='demo',
+ email='demo@test.com')
+ course = Course.objects.get_or_create(name="Yaksh Demo course",
+ enrollment="open",
+ creator=user[0])
# Create Moderator with profile
self.user1_plaintext_pass = 'demo1'
self.user1 = User.objects.create_user(
diff --git a/yaksh/views.py b/yaksh/views.py
index 6d5ac30..3e42b64 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -256,9 +256,15 @@ def add_quiz(request, course_id, quiz_id=None):
user = request.user
course = get_object_or_404(Course, pk=course_id)
ci = RequestContext(request)
- if course.name != "Yaksh_Demo_course":
- if not is_moderator(user) or (user != course.creator and user not in course.teachers.all()):
- raise Http404('You are not allowed to view this page!')
+ if not is_moderator(user):
+ raise Http404('You are not allowed to view this page!')
+ try:
+ demo_user = User.objects.get(username="yaksh_demo_user")
+ except User.DoesNotExist:
+ demo_user = None
+ if course.creator != demo_user:
+ if (user != course.creator and user not in course.teachers.all()):
+ raise Http404('You are not allowed to view this course !')
context = {}
if request.method == "POST":
if quiz_id is None:
--
cgit
From 485f3a74a59402fa2adca7bbea025b856f12d854 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 14:52:05 +0530
Subject: deleted course fixture file
---
yaksh/management/commands/create_demo_course.py | 99 -------------------------
1 file changed, 99 deletions(-)
delete mode 100644 yaksh/management/commands/create_demo_course.py
(limited to 'yaksh')
diff --git a/yaksh/management/commands/create_demo_course.py b/yaksh/management/commands/create_demo_course.py
deleted file mode 100644
index 6e2712f..0000000
--- a/yaksh/management/commands/create_demo_course.py
+++ /dev/null
@@ -1,99 +0,0 @@
-import os
-import sys
-from django.core.management.base import BaseCommand
-from yaksh.models import Course, Question, Quiz, QuestionPaper, Profile, FileUpload
-from yaksh.file_utils import extract_files
-from yaksh.views import add_to_group
-from django.contrib.auth.models import User
-from django.utils import timezone
-from django.contrib.auth.models import Group
-from datetime import datetime, timedelta
-
-
-def create_demo_course():
- """ creates a demo course, quiz """
-
- success = False
- group = Group.objects.filter(name="moderator")
- if group:
- print("Creating Demo User...")
- # create a demo user
- user, u_status = User.objects.get_or_create(username='yaksh_demo_user',
- email='demo@test.com')
- user.set_password("demo")
- user.save()
- Profile.objects.get_or_create(user=user, roll_number=0,
- institute='demo_institute',
- department='demo_department',
- position='Faculty')
- # add demo user to moderator group
- demo_user = User.objects.filter(username='yaksh_demo_user')
- add_to_group(demo_user)
- else:
- print ("Please Create 'moderator' Group")
- print ("Unable to create Demo Course")
- sys.exit()
-
- print("Creating Demo Course...")
- # create a demo course
- course, c_status = Course.objects.get_or_create(name="Yaksh Demo course",
- enrollment="open",
- creator=user)
-
- print("Creating Demo Quiz...")
- demo_quiz = Quiz.objects.filter(course=course)
- if not demo_quiz:
- # create a demo quiz
- demo_quiz = Quiz.objects.get_or_create(start_date_time=timezone.now(),
- end_date_time=timezone.now() + timedelta(176590),
- duration=30, active=True,
- attempts_allowed=-1,
- time_between_attempts=0,
- description='Yaksh Demo quiz', pass_criteria=0,
- language='Python', prerequisite=None,
- course=course)
- else:
- print("Demo Quiz Already Created")
-
- print("Creating Demo Questions...")
- questions = Question.objects.filter(active=True, summary="Yaksh Demo Question")
- files = FileUpload.objects.filter(question__in=questions)
- if not files:
- #create demo question
- f_path = os.path.join(os.getcwd(), 'yaksh', 'fixtures', 'demo_questions.json')
- zip_file_path = os.path.join(os.getcwd(), 'yaksh', 'fixtures', 'demo_questions.zip')
- extract_files(zip_file_path)
- ques = Question()
- ques.read_json("questions_dump.json", user)
-
- if questions:
- print("Creating Demo Question Paper...")
- # create a demo questionpaper
- que_ppr = QuestionPaper.objects.filter(quiz=demo_quiz[0])
- if not que_ppr:
- question_paper, q_ppr_status = QuestionPaper.objects.get_or_create(quiz=demo_quiz[0],
- total_marks=5.0,
- shuffle_questions=True
- )
- # add fixed set of questions to the question paper
- for question in questions:
- question_paper.fixed_questions.add(question)
- else:
- print("Question Paper Already Created")
- else:
- print("Questions Not Found Please Check Question Summary")
-
- success = True
- return success
-
-
-class Command(BaseCommand):
- help = "Create a Demo Course, Demo Quiz"
-
- def handle(self, *args, **options):
- """ Handle command to create demo course """
- status = create_demo_course()
- if status:
- self.stdout.write("Successfully Created")
- else:
- self.stdout.write("Unable to create Demo Course")
--
cgit
From 6d3ece46b9a6569c711e20db2c3220e32a82751c Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 14:53:01 +0530
Subject: changed manage and courses template
---
yaksh/templates/manage.html | 20 ++++++++++++++++
yaksh/templates/yaksh/courses.html | 47 --------------------------------------
2 files changed, 20 insertions(+), 47 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html
index b628a44..ea587df 100644
--- a/yaksh/templates/manage.html
+++ b/yaksh/templates/manage.html
@@ -77,6 +77,26 @@
Moderator's Dashboard!
Click on the button given below to add a new course.
+ Click on the button to Create a Demo course.
+ Help
+
+
+
+
+ - A Demo Course and Demo Quiz will be created (Click Courses link on nav bar to view courses).
+ - Some Demo Questions are also created for you (Click Questions link on nav bar to view questions).
+ - In Courses you can view Demo Quiz.
+ - Click on the Demo Quiz and Click on User Mode or God Mode to take the quiz.
+
+ - You can also edit Demo quiz.
+
+
+
+ Close
+
+ {% if msg %}
+ {{ msg }}
+ {% endif %}
{% if trial_paper %}
You have trial papers.
diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html
index bfc3cd8..43f323b 100644
--- a/yaksh/templates/yaksh/courses.html
+++ b/yaksh/templates/yaksh/courses.html
@@ -155,52 +155,5 @@
{% endif %}
-{% if demo_course %}
-{% with demo_course as course %}
- Demo Course
- Help
-
-
-
- - This is a Demo Course
-
- - You will not be able to edit Demo course and Demo Quiz.
- - You can only take Demo Quiz by User Mode or God Mode.
- - This is for you to get familiar with the interface.
-
-
- Close
-
-
-
-
-
-
- Course
- {% if course.active %}
- Active
- {% else %}
- Closed
- {% endif %}
-
-
{{ course.name }}
-
-
-
-
Quiz(zes)
- {% if course.get_quizzes %}
- {% for quiz in course.get_quizzes %}
-
{{ quiz.description }}
- {% endfor %}
- {% else %}
-
No quiz
- {% endif %}
-
-
-
-
-{% endwith %}
-
-{% endif %}
{% endblock %}
--
cgit
From f420bf2cf6b755dee76338134994f9746bbc0d2b Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 14:55:41 +0530
Subject: removed user creation for demo course
---
yaksh/test_views.py | 6 ------
1 file changed, 6 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index e88956c..8a38942 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -650,12 +650,6 @@ class TestCourses(TestCase):
self.client = Client()
self.mod_group = Group.objects.create(name='moderator')
- user = User.objects.get_or_create(username='yaksh_demo_user',
- password='demo',
- email='demo@test.com')
- course = Course.objects.get_or_create(name="Yaksh Demo course",
- enrollment="open",
- creator=user[0])
# Create Moderator with profile
self.user1_plaintext_pass = 'demo1'
self.user1 = User.objects.create_user(
--
cgit
From 2ac8383ceb3f8850043ab317a7a7ebd2bfcf3921 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 14:56:10 +0530
Subject: added url for demo course
---
yaksh/urls.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'yaksh')
diff --git a/yaksh/urls.py b/yaksh/urls.py
index daa6008..fb23c7b 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -101,5 +101,6 @@ urlpatterns += [
url(r'^manage/remove_teachers/(?P\d+)/$', views.remove_teachers, name='remove_teacher'),
url(r'^manage/download_questions/$', views.show_all_questions),
url(r'^manage/upload_questions/$', views.show_all_questions),
- url(r'^manage/(?P[\w\-]+)/(?P\d+)/$', views.test_quiz)
+ url(r'^manage/(?P[\w\-]+)/(?P\d+)/$', views.test_quiz),
+ url(r'^manage/create_demo_course/$', views.create_demo_course),
]
--
cgit
From 4d8a0b41935ecc182c90acf34e7696a207a664f6 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 14:56:55 +0530
Subject: Demo course creation without initial fixtures
---
yaksh/models.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++
yaksh/views.py | 38 ++++++++++++++++++++------------------
2 files changed, 67 insertions(+), 18 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/models.py b/yaksh/models.py
index e7a60df..870d8b9 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -17,6 +17,7 @@ import os
import shutil
import zipfile
import tempfile
+from file_utils import extract_files
languages = (
@@ -155,6 +156,23 @@ class Course(models.Model):
def remove_teachers(self, *teachers):
self.teachers.remove(*teachers)
+ def create_demo(self, user):
+ course = Course.objects.filter(creator=user, name="Yaksh Demo course")
+ if not course:
+ course, c_status= Course.objects.get_or_create(name="Yaksh Demo course",
+ enrollment="open",
+ creator=user)
+ quiz = Quiz()
+ demo_quiz = quiz.create_demo_quiz(course)
+ demo_ques = Question()
+ demo_ques.create_demo_questions(user)
+ demo_que_ppr = QuestionPaper()
+ demo_que_ppr.create_demo_que_ppr(demo_quiz)
+ success = True
+ else:
+ success = False
+ return success
+
def __unicode__(self):
return self.name
@@ -323,6 +341,13 @@ class Question(models.Model):
self.load_questions(questions_list, user)
os.remove(json_file)
+ def create_demo_questions(self, user):
+ zip_file_path = os.path.join(os.getcwd(), 'yaksh',
+ 'fixtures', 'demo_questions.zip')
+ extract_files(zip_file_path)
+ self.read_json("questions_dump.json", user)
+
+
def __unicode__(self):
return self.summary
@@ -487,6 +512,17 @@ class Quiz(models.Model):
def has_prerequisite(self):
return True if self.prerequisite else False
+
+ def create_demo_quiz(self, course):
+ demo_quiz = Quiz.objects.get_or_create(start_date_time=timezone.now(),
+ end_date_time=timezone.now() + timedelta(176590),
+ duration=30, active=True,
+ attempts_allowed=-1,
+ time_between_attempts=0,
+ description='Yaksh Demo quiz', pass_criteria=0,
+ language='Python', prerequisite=None,
+ course=course)
+ return demo_quiz
def __unicode__(self):
desc = self.description or 'Quiz'
@@ -618,6 +654,17 @@ class QuestionPaper(models.Model):
if self.quiz.has_prerequisite():
prerequisite = self._get_prequisite_paper()
return prerequisite._is_questionpaper_passed(user)
+
+ def create_demo_que_ppr(self, demo_quiz):
+ question_paper = QuestionPaper.objects.get_or_create(quiz=demo_quiz[0],
+ total_marks=5.0,
+ shuffle_questions=True
+ )
+ questions = Question.objects.filter(active=True,
+ summary="Yaksh Demo Question")
+ # add fixed set of questions to the question paper
+ for question in questions:
+ question_paper[0].fixed_questions.add(question)
def __unicode__(self):
return "Question Paper for " + self.quiz.description
diff --git a/yaksh/views.py b/yaksh/views.py
index 3e42b64..959d323 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -256,15 +256,8 @@ def add_quiz(request, course_id, quiz_id=None):
user = request.user
course = get_object_or_404(Course, pk=course_id)
ci = RequestContext(request)
- if not is_moderator(user):
- raise Http404('You are not allowed to view this page!')
- try:
- demo_user = User.objects.get(username="yaksh_demo_user")
- except User.DoesNotExist:
- demo_user = None
- if course.creator != demo_user:
- if (user != course.creator and user not in course.teachers.all()):
- raise Http404('You are not allowed to view this course !')
+ if not is_moderator(user) or (user != course.creator and user not in course.teachers.all()):
+ raise Http404('You are not allowed to view this course !')
context = {}
if request.method == "POST":
if quiz_id is None:
@@ -688,18 +681,10 @@ def courses(request):
ci = RequestContext(request)
if not is_moderator(user):
raise Http404('You are not allowed to view this page')
- try:
- demo_user = User.objects.get(username="yaksh_demo_user")
- demo_course = Course.objects.get(creator=demo_user)
- except User.DoesNotExist, Course.DoesNotExist:
- demo_user = None
- demo_course = None
-
courses = Course.objects.filter(creator=user, is_trial=False)
allotted_courses = Course.objects.filter(teachers=user, is_trial=False)
- context = {'courses': courses, "allotted_courses": allotted_courses,
- 'demo_course': demo_course}
+ context = {'courses': courses, "allotted_courses": allotted_courses}
return my_render_to_response('yaksh/courses.html', context,
context_instance=ci)
@@ -1309,3 +1294,20 @@ def view_answerpaper(request, questionpaper_id):
return my_render_to_response('yaksh/view_answerpaper.html', context)
else:
return my_redirect('/exam/quizzes/')
+
+
+@login_required
+def create_demo_course(request):
+ """ creates a demo course for user """
+ user = request.user
+ ci = RequestContext(request)
+ if not is_moderator(user):
+ raise("You are not allowed to view this page")
+ demo_course = Course()
+ success = demo_course.create_demo(user)
+ if success:
+ msg = "Created Demo course successfully"
+ else:
+ msg = "Demo course already created"
+ context = {'msg': msg}
+ return my_render_to_response('manage.html', context, context_instance=ci)
--
cgit
From a689afd85ef3f0e4ddb8255e06c50f400bebd165 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Tue, 20 Sep 2016 16:09:54 +0530
Subject: used create method instead of get_or_create to create course
---
yaksh/models.py | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/models.py b/yaksh/models.py
index 870d8b9..d176c57 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -159,9 +159,9 @@ class Course(models.Model):
def create_demo(self, user):
course = Course.objects.filter(creator=user, name="Yaksh Demo course")
if not course:
- course, c_status= Course.objects.get_or_create(name="Yaksh Demo course",
- enrollment="open",
- creator=user)
+ course = Course.objects.create(name="Yaksh Demo course",
+ enrollment="open",
+ creator=user)
quiz = Quiz()
demo_quiz = quiz.create_demo_quiz(course)
demo_ques = Question()
@@ -514,7 +514,7 @@ class Quiz(models.Model):
return True if self.prerequisite else False
def create_demo_quiz(self, course):
- demo_quiz = Quiz.objects.get_or_create(start_date_time=timezone.now(),
+ demo_quiz = Quiz.objects.create(start_date_time=timezone.now(),
end_date_time=timezone.now() + timedelta(176590),
duration=30, active=True,
attempts_allowed=-1,
@@ -656,15 +656,15 @@ class QuestionPaper(models.Model):
return prerequisite._is_questionpaper_passed(user)
def create_demo_que_ppr(self, demo_quiz):
- question_paper = QuestionPaper.objects.get_or_create(quiz=demo_quiz[0],
- total_marks=5.0,
- shuffle_questions=True
- )
+ question_paper = QuestionPaper.objects.create(quiz=demo_quiz,
+ total_marks=5.0,
+ shuffle_questions=True
+ )
questions = Question.objects.filter(active=True,
summary="Yaksh Demo Question")
# add fixed set of questions to the question paper
for question in questions:
- question_paper[0].fixed_questions.add(question)
+ question_paper.fixed_questions.add(question)
def __unicode__(self):
return "Question Paper for " + self.quiz.description
--
cgit
From e1811e3560742a4070f3e92e059a7cd1c50f1f36 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Wed, 21 Sep 2016 14:38:00 +0530
Subject: changed func name from create_demo_que_ppr to create_demo_quiz_paper
---
yaksh/models.py | 4 ++--
yaksh/templates/manage.html | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/models.py b/yaksh/models.py
index d176c57..71cd258 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -167,7 +167,7 @@ class Course(models.Model):
demo_ques = Question()
demo_ques.create_demo_questions(user)
demo_que_ppr = QuestionPaper()
- demo_que_ppr.create_demo_que_ppr(demo_quiz)
+ demo_que_ppr.create_demo_quiz_ppr(demo_quiz)
success = True
else:
success = False
@@ -655,7 +655,7 @@ class QuestionPaper(models.Model):
prerequisite = self._get_prequisite_paper()
return prerequisite._is_questionpaper_passed(user)
- def create_demo_que_ppr(self, demo_quiz):
+ def create_demo_quiz_ppr(self, demo_quiz):
question_paper = QuestionPaper.objects.create(quiz=demo_quiz,
total_marks=5.0,
shuffle_questions=True
diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html
index ea587df..a736b0a 100644
--- a/yaksh/templates/manage.html
+++ b/yaksh/templates/manage.html
@@ -88,7 +88,7 @@
In Courses you can view Demo Quiz.
Click on the Demo Quiz and Click on User Mode or God Mode to take the quiz.
- You can also edit Demo quiz.
+ You can also edit the Demo quiz.
--
cgit