summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2016-09-14 16:24:01 +0530
committeradityacp2016-09-14 16:24:01 +0530
commitb0d29a622f6d3fac39ac7881b3197d4db8fbd518 (patch)
treec76706235933c86a97bcf873f70fc6323cc6f08b /yaksh
parent3c1bbe9d8c53c419d2fa2a254228484ea74aab96 (diff)
downloadonline_test-b0d29a622f6d3fac39ac7881b3197d4db8fbd518.tar.gz
online_test-b0d29a622f6d3fac39ac7881b3197d4db8fbd518.tar.bz2
online_test-b0d29a622f6d3fac39ac7881b3197d4db8fbd518.zip
added check conditions in demo fixtures
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/management/commands/create_demo_course.py69
1 files changed, 42 insertions, 27 deletions
diff --git a/yaksh/management/commands/create_demo_course.py b/yaksh/management/commands/create_demo_course.py
index e71e0ae..9cb6058 100644
--- a/yaksh/management/commands/create_demo_course.py
+++ b/yaksh/management/commands/create_demo_course.py
@@ -2,9 +2,9 @@ import os
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.core.files import File
from datetime import datetime, timedelta
import pytz
import zipfile
@@ -17,12 +17,15 @@ def create_demo_course():
print("Creating Demo User...")
# create a demo user
user, u_status = User.objects.get_or_create(username='demo_user',
- password='demo',
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')
+ demo_user = User.objects.filter(username='demo_user')
+ add_to_group(demo_user)
print("Creating Demo Course...")
# create a demo course
@@ -31,35 +34,47 @@ def create_demo_course():
creator=user)
print("Creating Demo Quiz...")
+ demo_quiz = Quiz.objects.filter(course=course)
+ if not demo_quiz:
# create a demo quiz
- quiz, q_status = 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='Demo_quiz', pass_criteria=0,
- language='Python', prerequisite=None,
- course=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='Demo_quiz', pass_criteria=0,
+ language='Python', prerequisite=None,
+ course=course)
+ else:
+ print("Demo Quiz Already Created")
print("Creating Demo Questions...")
- #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)
+ questions = Question.objects.filter(active=True, summary="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)
- questions = Question.objects.filter(active=True, summary="Demo_Question")
-
- print("Creating Demo Question Paper...")
- # create a demo questionpaper
- question_paper, q_ppr_status = QuestionPaper.objects.get_or_create(quiz=quiz,
- 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)
+ 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