summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2017-03-16 16:43:12 +0530
committeradityacp2017-03-16 16:43:12 +0530
commitb37244f2c6573b0f16b9dcea614400ee1ae24cf8 (patch)
treee5ae120f2c47d78e53513db25e01d028954d9f5f /yaksh
parent508a576ccfb63169c24056ded25f742bdcd186f2 (diff)
downloadonline_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.tar.gz
online_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.tar.bz2
online_test-b37244f2c6573b0f16b9dcea614400ee1ae24cf8.zip
Changes in models views and urls
- Handle Json parsing error - Remove Sample file download from views and urls
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py30
-rw-r--r--yaksh/urls.py1
-rw-r--r--yaksh/views.py13
3 files changed, 18 insertions, 26 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 0a84d4e..dc015d5 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -318,17 +318,19 @@ class Question(models.Model):
file_names = question.pop('files')
test_cases = question.pop('testcase')
que, result = Question.objects.get_or_create(**question)
- if file_names:
- que._add_files_to_db(file_names, file_path)
- for test_case in test_cases:
- test_case_type = test_case.pop('test_case_type')
- model_class = get_model_class(test_case_type)
- new_test_case, obj_create_status = \
- model_class.objects.get_or_create(
- question=que, **test_case
- )
- new_test_case.type = test_case_type
- new_test_case.save()
+ if not result:
+ if file_names:
+ que._add_files_to_db(file_names, file_path)
+ for test_case in test_cases:
+ test_case_type = test_case.pop('test_case_type')
+ model_class = get_model_class(test_case_type)
+ new_test_case, obj_create_status = \
+ model_class.objects.get_or_create(
+ question=que, **test_case
+ )
+ new_test_case.type = test_case_type
+ new_test_case.save()
+
if files_list:
delete_files(files_list, file_path)
@@ -401,7 +403,11 @@ class Question(models.Model):
if os.path.exists(json_file):
with open(json_file, 'r') as q_file:
questions_list = q_file.read()
- self.load_questions(questions_list, user, file_path, files)
+ try:
+ self.load_questions(questions_list, user, file_path, files)
+ except ValueError:
+ return "Syntax Error in Json. Please check your json file."
+
return "Questions Uploaded Successfully"
else:
return "Please upload zip file with questions_dump.json in it."
diff --git a/yaksh/urls.py b/yaksh/urls.py
index e7a3a66..ad58985 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -28,7 +28,6 @@ urlpatterns = [
url(r'^view_answerpaper/(?P<questionpaper_id>\d+)/$', views.view_answerpaper, name='view_answerpaper'),
url(r'^manage/$', views.prof_manage, name='manage'),
url(r'^manage/addquestion/$', views.add_question),
- url(r'^manage/download_demo_question/$', views.download_demo_questions),
url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.add_question),
url(r'^manage/addquiz/(?P<course_id>\d+)/$', views.add_quiz, name='add_quiz'),
url(r'^manage/addquiz/(?P<course_id>\d+)/(?P<quiz_id>\d+)/$', views.add_quiz, name='edit_quiz'),
diff --git a/yaksh/views.py b/yaksh/views.py
index 02019f4..daa81eb 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -30,7 +30,6 @@ from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
get_object_form, FileForm, QuestionPaperForm
from .settings import URL_ROOT
-from django.conf import settings
from yaksh.models import AssignmentUpload
from .file_utils import extract_files
@@ -950,18 +949,6 @@ def show_all_questions(request):
context_instance=ci)
@login_required
-def download_demo_questions(request):
- user = request.user
- if not is_moderator(user):
- raise Http404("You are not allowed to download!")
- f_path = os.path.join(settings.FIXTURE_DIRS, "demo_questions.zip")
- zip_file = open(f_path, "rb")
- response = HttpResponse(zip_file, content_type='application/zip')
- response['Content-Disposition'] = '''attachment;\
- filename=demo_questions.zip'''
- return response
-
-@login_required
def user_data(request, user_id, questionpaper_id=None):
"""Render user data."""
current_user = request.user