summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/forms.py2
-rw-r--r--yaksh/models.py12
-rw-r--r--yaksh/templates/yaksh/add_question.html2
-rw-r--r--yaksh/views.py12
4 files changed, 13 insertions, 15 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index bc9b4c0..1931fad 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -177,7 +177,7 @@ class QuestionForm(forms.ModelForm):
class Meta:
model = Question
- exclude = ['user']
+ exclude = ['user', 'active']
class FileForm(forms.Form):
diff --git a/yaksh/models.py b/yaksh/models.py
index c4a280a..cc64b98 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -271,7 +271,7 @@ class Question(models.Model):
return json.dumps(question_data)
def dump_questions(self, question_ids, user):
- questions = Question.objects.filter(id__in=question_ids, user_id=user.id)
+ questions = Question.objects.filter(id__in=question_ids, user_id=user.id, active=True)
questions_dict = []
zip_file_name = string_io()
zip_file = zipfile.ZipFile(zip_file_name, "a")
@@ -628,8 +628,7 @@ class QuestionPaper(models.Model):
def _get_questions_for_answerpaper(self):
""" Returns fixed and random questions for the answer paper"""
- questions = []
- questions = list(self.fixed_questions.all())
+ questions = list(self.fixed_questions.filter(active=True))
for question_set in self.random_questions.all():
questions += question_set.get_random_questions()
return questions
@@ -770,8 +769,9 @@ class AnswerPaperManager(models.Manager):
attempt_number)
questions = self.get_all_questions(questionpaper_id, attempt_number)
all_questions = Question.objects.filter(
- id__in=set(questions)
- ).order_by('type')
+ id__in=set(questions),
+ active=True
+ ).order_by('type')
for question in all_questions:
if question.id in questions_answered:
question_stats[question] = [questions_answered[question.id],
@@ -998,7 +998,7 @@ class AnswerPaper(models.Model):
return q_a
def get_questions(self):
- return self.questions.all()
+ return self.questions.filter(active=True)
def get_questions_answered(self):
return self.questions_answered.all()
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index f003256..5a5f1ce 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -20,7 +20,7 @@
<center><table class=span1>
<tr><td>Summary: <td>{{ form.summary }}{{ form.summary.errors }}
<tr><td> Language: <td> {{form.language}}{{form.language.errors}}
- <tr><td> Active: <td> {{ form.active }}{{form.active.errors}} &nbsp; Type: &nbsp;{{ form.type }}{{form.type.errors}}
+ <tr><td> Type: <td> {{ form.type }}{{form.type.errors}}
<tr><td>Points:<td><button class="btn-mini" type="button" onClick="increase(frm);">+</button>{{form.points }}<button class="btn-mini" type="button" onClick="decrease(frm);">-</button>{{ form.points.errors }}
<tr><td><strong>Rendered: </strong><td><p id='my'></p>
<tr><td>Description: <td>{{ form.description}} {{form.description.errors}}
diff --git a/yaksh/views.py b/yaksh/views.py
index 611403d..68e641e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -915,12 +915,10 @@ 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)
- files = FileUpload.objects.filter(question_id__in=questions)
- if files:
- for file in files:
- file.remove()
- questions.delete()
+ questions = Question.objects.filter(id__in=data, user_id=user.id, active=True)
+ for question in questions:
+ question.active = False
+ question.save()
if request.POST.get('upload') == 'upload':
form = UploadFileForm(request.POST, request.FILES)
@@ -959,7 +957,7 @@ def show_all_questions(request):
else:
context["msg"] = "Please select atleast one question to test"
- questions = Question.objects.filter(user_id=user.id)
+ questions = Question.objects.filter(user_id=user.id, active=True)
form = QuestionFilterForm(user=user)
upload_form = UploadFileForm()
context['papers'] = []