summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorKing2018-07-31 02:51:51 -0700
committerGitHub2018-07-31 02:51:51 -0700
commita4d5349e85503b4c030df392212bce4ab8866703 (patch)
treeb83692df5adc82ab0a3f4af7dabe7ba8aa4a7540 /yaksh/models.py
parent239ed05355e46448e3232d3a026e525f821a7841 (diff)
parentf4b6bf5349c3916321a5ed3d67159548b4bb56ce (diff)
downloadonline_test-a4d5349e85503b4c030df392212bce4ab8866703.tar.gz
online_test-a4d5349e85503b4c030df392212bce4ab8866703.tar.bz2
online_test-a4d5349e85503b4c030df392212bce4ab8866703.zip
Merge pull request #502 from adityacp/fix_assignment_upload
Fix assignment upload
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 49a2384..480a111 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -94,8 +94,10 @@ MOD_GROUP_NAME = 'moderator'
def get_assignment_dir(instance, filename):
- upload_dir = instance.question_paper.quiz.description.replace(" ", "_")
- return os.sep.join((upload_dir, instance.user.username,
+ folder_name = instance.course.name.replace(" ", "_")
+ sub_folder_name = instance.question_paper.quiz.description.replace(
+ " ", "_")
+ return os.sep.join((folder_name, sub_folder_name, instance.user.username,
str(instance.assignmentQuestion.id),
filename
))
@@ -2234,20 +2236,19 @@ class AnswerPaper(models.Model):
##############################################################################
class AssignmentUploadManager(models.Manager):
- def get_assignments(self, qp, que_id=None, user_id=None):
+ def get_assignments(self, qp, que_id=None, user_id=None, course_id=None):
if que_id and user_id:
assignment_files = AssignmentUpload.objects.filter(
assignmentQuestion_id=que_id, user_id=user_id,
- question_paper=qp
+ question_paper=qp, course_id=course_id
)
file_name = User.objects.get(id=user_id).get_full_name()
else:
assignment_files = AssignmentUpload.objects.filter(
- question_paper=qp
+ question_paper=qp, course_id=course_id
)
-
file_name = "{0}_Assignment_files".format(
- assignment_files[0].question_paper.quiz.description
+ assignment_files[0].course.name
)
return assignment_files, file_name
@@ -2259,6 +2260,7 @@ class AssignmentUpload(models.Model):
assignmentQuestion = models.ForeignKey(Question)
assignmentFile = models.FileField(upload_to=get_assignment_dir)
question_paper = models.ForeignKey(QuestionPaper, blank=True, null=True)
+ course = models.ForeignKey(Course, null=True, blank=True)
objects = AssignmentUploadManager()