summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2016-07-28 15:54:36 +0530
committeradityacp2016-07-28 15:56:06 +0530
commit26157fd30edf834aa53c1bda58cdf277255d1fc4 (patch)
tree6bce3bf4cdd9dd2f574f943d7f4d9d1386742768 /yaksh/views.py
parent5507ac28187fbb2605334bce618cc543725e8334 (diff)
downloadonline_test-26157fd30edf834aa53c1bda58cdf277255d1fc4.tar.gz
online_test-26157fd30edf834aa53c1bda58cdf277255d1fc4.tar.bz2
online_test-26157fd30edf834aa53c1bda58cdf277255d1fc4.zip
changes in views questions file upload
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py33
1 files changed, 16 insertions, 17 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index c659369..e1ec44e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -25,7 +25,7 @@ import json
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
-from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, QuestionsFileUpload,\
+from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUpload,\
has_profile
from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
QuestionForm, RandomQuestionForm,\
@@ -160,7 +160,7 @@ def add_question(request):
files = request.FILES.getlist('file_field')
if files:
for file in files:
- QuestionsFileUpload.objects.get_or_create(question=new_question, files=file)
+ FileUpload.objects.get_or_create(question=new_question, file=file)
return my_redirect("/exam/manage/addquestion/{0}".format(new_question.id))
else:
return my_render_to_response('yaksh/add_question.html',
@@ -188,9 +188,9 @@ def edit_question(request, question_id=None):
if request.method == "POST" and 'delete_files' in request.POST:
remove_files_id = request.POST.getlist('clear')
if remove_files_id:
- files = QuestionsFileUpload.objects.filter(id__in=remove_files_id)
- file = QuestionsFileUpload()
- file.delete_files(files)
+ files = FileUpload.objects.filter(id__in=remove_files_id)
+ for file in files:
+ file.remove()
if request.method == "POST" and 'save_question' in request.POST:
question_form = QuestionForm(request.POST, instance=question_instance)
form = FileForm(request.POST, request.FILES)
@@ -198,11 +198,11 @@ def edit_question(request, question_id=None):
extract_files_id = request.POST.getlist('extract')
if files:
for file in files:
- QuestionsFileUpload.objects.get_or_create(question=question_instance, files=file)
+ FileUpload.objects.get_or_create(question=question_instance, file=file)
if extract_files_id:
- files = QuestionsFileUpload.objects.filter(id__in=extract_files_id)
- file = QuestionsFileUpload()
- file.set_extract_status(files)
+ files = FileUpload.objects.filter(id__in=extract_files_id)
+ for file in files:
+ file.set_extract_status()
if question_form.is_valid():
new_question = question_form.save(commit=False)
test_case_type = question_form.cleaned_data.get('test_case_type')
@@ -220,7 +220,7 @@ def edit_question(request, question_id=None):
test_case_model_class = get_model_class(test_case_type)
TestCaseInlineFormSet = inlineformset_factory(Question, test_case_model_class, form=test_case_form_class, extra=1)
test_case_formset = TestCaseInlineFormSet(request.POST, request.FILES, instance=question_instance)
- uploaded_files = QuestionsFileUpload.objects.filter(question_id=question_instance.id)
+ uploaded_files = FileUpload.objects.filter(question_id=question_instance.id)
return my_render_to_response('yaksh/add_question.html',
{'form': question_form,
'test_case_formset': test_case_formset,
@@ -236,7 +236,7 @@ def edit_question(request, question_id=None):
test_case_model_class = get_model_class(test_case_type)
TestCaseInlineFormSet = inlineformset_factory(Question, test_case_model_class, form=test_case_form_class, extra=1)
test_case_formset = TestCaseInlineFormSet(instance=question_instance)
- uploaded_files = QuestionsFileUpload.objects.filter(question_id=question_instance.id)
+ uploaded_files = FileUpload.objects.filter(question_id=question_instance.id)
return my_render_to_response('yaksh/add_question.html',
{'form': question_form,
'test_case_formset': test_case_formset,
@@ -435,7 +435,7 @@ def show_question(request, question, paper, error_message=None):
reason='Your time is up!'
return complete(request, reason, paper.attempt_number, paper.question_paper.id)
test_cases = question.get_test_cases()
- files = QuestionsFileUpload.objects.filter(question_id=question.id)
+ files = FileUpload.objects.filter(question_id=question.id)
context = {'question': question, 'paper': paper, 'error_message': error_message,
'test_cases': test_cases, 'files': files,
'last_attempt': question.snippet.encode('unicode-escape')}
@@ -859,11 +859,10 @@ def show_all_questions(request):
data = request.POST.getlist('question')
if data is not None:
questions = Question.objects.filter(id__in=data, user_id=user.id)
- for question in questions:
- files = QuestionsFileUpload.objects.filter(question_id=question.id)
- if files:
- file = QuestionsFileUpload()
- file.delete_files(files)
+ files = FileUpload.objects.filter(question_id__in=questions)
+ if files:
+ for file in files:
+ file.remove()
questions.delete()
if request.POST.get('upload') == 'upload':