From 2955c57b10c33a12b9c6def60169ee2105ca20e4 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 10 Mar 2017 11:10:09 +0530 Subject: Changes in models and views - Display error message if questions_dump.json is not found in zip file - Provide a sample zip file to for easy zip file creation --- yaksh/views.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 63653e6..02019f4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -20,7 +20,6 @@ import pytz from taggit.models import Tag from itertools import chain import json -import zipfile import six # Local imports. from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course @@ -31,6 +30,7 @@ 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 @@ -894,7 +894,8 @@ def show_all_questions(request): if request.POST.get('delete') == 'delete': data = request.POST.getlist('question') if data is not None: - questions = Question.objects.filter(id__in=data, user_id=user.id, active=True) + questions = Question.objects.filter(id__in=data, user_id=user.id, + active=True) for question in questions: question.active = False question.save() @@ -907,7 +908,8 @@ def show_all_questions(request): if file_name[-1] == "zip": ques = Question() files, extract_path = extract_files(questions_file) - ques.read_json(extract_path, user, files) + context['message'] = ques.read_json(extract_path, user, + files) else: message = "Please Upload a ZIP file" context['message'] = message @@ -947,6 +949,17 @@ def show_all_questions(request): return my_render_to_response('yaksh/showquestions.html', context, 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): -- cgit From b37244f2c6573b0f16b9dcea614400ee1ae24cf8 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 16 Mar 2017 16:43:12 +0530 Subject: Changes in models views and urls - Handle Json parsing error - Remove Sample file download from views and urls --- yaksh/views.py | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'yaksh/views.py') 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 @@ -949,18 +948,6 @@ def show_all_questions(request): return my_render_to_response('yaksh/showquestions.html', context, 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.""" -- cgit