summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2021-03-15 14:59:55 +0530
committerCruiseDevice2021-03-15 14:59:55 +0530
commit1793f445ec0cbc67df4b4cd3151859e01ed4b2a0 (patch)
tree95437a97f0ba81b2394593a7db5dca393a06c204
parentb457c973b491d373ed9c5087b61bf29ce128d766 (diff)
downloadonline_test-1793f445ec0cbc67df4b4cd3151859e01ed4b2a0.tar.gz
online_test-1793f445ec0cbc67df4b4cd3151859e01ed4b2a0.tar.bz2
online_test-1793f445ec0cbc67df4b4cd3151859e01ed4b2a0.zip
PEP8 fix
-rw-r--r--yaksh/admin.py2
-rw-r--r--yaksh/models.py54
-rw-r--r--yaksh/test_models.py43
-rw-r--r--yaksh/test_views.py2
4 files changed, 65 insertions, 36 deletions
diff --git a/yaksh/admin.py b/yaksh/admin.py
index 011e24f..1010536 100644
--- a/yaksh/admin.py
+++ b/yaksh/admin.py
@@ -64,4 +64,4 @@ admin.site.register(Topic)
admin.site.register(TableOfContents)
admin.site.register(LessonQuizAnswer)
admin.site.register(Answer)
-admin.site.register(AssignmentUpload) \ No newline at end of file
+admin.site.register(AssignmentUpload)
diff --git a/yaksh/models.py b/yaksh/models.py
index 4661ea7..610e984 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -131,6 +131,7 @@ def get_assignment_dir(instance, filename):
filename
))
+
def get_model_class(model):
ctype = ContentType.objects.get(app_label="yaksh", model=model)
model_class = ctype.model_class()
@@ -1381,7 +1382,9 @@ class Question(models.Model):
# Solution for the question.
solution = models.TextField(blank=True)
- content = GenericRelation("TableOfContents", related_query_name='questions')
+ content = GenericRelation(
+ "TableOfContents", related_query_name='questions'
+ )
tc_code_types = {
"python": [
@@ -1838,7 +1841,8 @@ class QuestionPaper(models.Model):
all_questions = questions
return all_questions
- def make_answerpaper(self, user, ip, attempt_num, course_id, special=False):
+ def make_answerpaper(self,
+ user, ip, attempt_num, course_id, special=False):
"""Creates an answer paper for the user to attempt the quiz"""
try:
ans_paper = AnswerPaper.objects.get(user=user,
@@ -2035,6 +2039,7 @@ class AnswerPaperManager(models.Manager):
).order_by("id").values(
"answerpaper__id", "question_id", "correct", "answer"
)
+
def _get_per_tc_data(answers, q_type):
tc = []
for answer in answers["answer"]:
@@ -2047,11 +2052,11 @@ class AnswerPaperManager(models.Manager):
df = pd.DataFrame(answers)
if not df.empty:
for question in all_questions:
- que = df[df["question_id"]==question.id].groupby(
+ que = df[df["question_id"] == question.id].groupby(
"answerpaper__id").tail(1)
if not que.empty:
total_attempts = que.shape[0]
- correct_attempts = que[que["correct"]==True].shape[0]
+ correct_attempts = que[que["correct"] == True].shape[0]
per_tc_ans = {}
if question.type in ["mcq", "mcc"]:
per_tc_ans = _get_per_tc_data(que, question.type)
@@ -2643,13 +2648,16 @@ class AssignmentUploadManager(models.Manager):
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, answer_paper__user_id=user_id,
- answer_paper__question_paper=qp, answer_paper__course_id=course_id
+ assignmentQuestion_id=que_id,
+ answer_paper__user_id=user_id,
+ answer_paper__question_paper=qp,
+ answer_paper__course_id=course_id
)
file_name = User.objects.get(id=user_id).get_full_name()
else:
assignment_files = AssignmentUpload.objects.filter(
- answer_paper__question_paper=qp, answer_paper__course_id=course_id
+ answer_paper__question_paper=qp,
+ answer_paper__course_id=course_id
)
file_name = "{0}_Assignment_files".format(
assignment_files[0].answer_paper.course.name
@@ -2895,7 +2903,6 @@ class TOCManager(models.Manager):
toc.get_toc_as_yaml(file_path)
return file_path
-
def get_question_stats(self, toc_id):
answers = LessonQuizAnswer.objects.get_queryset().filter(
toc_id=toc_id).order_by('id')
@@ -2929,7 +2936,7 @@ class TOCManager(models.Manager):
if j not in mydata:
mydata[j] = 1
else:
- mydata[j] +=1
+ mydata[j] += 1
data = mydata.copy()
if is_percent:
for key, value in data.items():
@@ -2975,17 +2982,20 @@ class TOCManager(models.Manager):
if not is_valid_time_format(time):
messages.append(
(False,
- f"Invalid time format in {name}. "
+ f"Invalid time format in {name}. "
"Format should be 00:00:00")
- )
+ )
else:
if content_type == 1:
topic = Topic.objects.create(**content)
toc.append(TableOfContents(
- course_id=course_id, lesson_id=lesson_id, time=time,
- content_object=topic, content=content_type
+ course_id=course_id,
+ lesson_id=lesson_id, time=time,
+ content_object=topic, content=content_type
))
- messages.append((True, f"{topic.name} added successfully"))
+ messages.append(
+ (True, f"{topic.name} added successfully")
+ )
else:
content['user'] = user
test_cases = content.pop("testcase")
@@ -3002,10 +3012,13 @@ class TOCManager(models.Manager):
else:
que = Question.objects.create(**content)
for test_case in test_cases:
- test_case_type = test_case.pop('test_case_type')
+ test_case_type = test_case.pop(
+ 'test_case_type'
+ )
model_class = get_model_class(test_case_type)
model_class.objects.get_or_create(
- question=que, **test_case, type=test_case_type
+ question=que,
+ **test_case, type=test_case_type
)
toc.append(TableOfContents(
course_id=course_id, lesson_id=lesson_id,
@@ -3021,7 +3034,12 @@ class TOCManager(models.Manager):
class TableOfContents(models.Model):
- toc_types = ((1, "Topic"), (2, "Graded Quiz"), (3, "Exercise"), (4, "Poll"))
+ toc_types = (
+ (1, "Topic"),
+ (2, "Graded Quiz"),
+ (3, "Exercise"),
+ (4, "Poll")
+ )
course = models.ForeignKey(Course, on_delete=models.CASCADE,
related_name='course')
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE,
@@ -3039,7 +3057,7 @@ class TableOfContents(models.Model):
def get_toc_text(self):
if self.content == 1:
- content_name = self.content_object.name
+ content_name = self.content_object.name
else:
content_name = self.content_object.summary
return content_name
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 86890c0..ae1ff22 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -107,6 +107,7 @@ def setUpModule():
MicroManager.objects.create(manager=user, course=course, quiz=quiz,
student=course_user)
+
def tearDownModule():
User.objects.all().delete()
Question.objects.all().delete()
@@ -2203,23 +2204,34 @@ class TestCaseTestCases(unittest.TestCase):
class AssignmentUploadTestCases(unittest.TestCase):
def setUp(self):
- self.user1 = User.objects.create_user(username='creator1',
- password='demo',
- email='demo@test1.com')
- self.user2 = User.objects.create_user(username='creator2',
- password='demo',
- email='demo@test2.com')
+ self.user1 = User.objects.create_user(
+ username='creator1',
+ password='demo',
+ email='demo@test1.com'
+ )
+ self.user2 = User.objects.create_user(
+ username='creator2',
+ password='demo',
+ email='demo@test2.com'
+ )
self.quiz = Quiz.objects.create(
- start_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
- end_date_time=datetime(2199, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc),
- duration=30, active=True,
- attempts_allowed=1, time_between_attempts=0,
- description='demo quiz 1', pass_criteria=0,
- instructions="Demo Instructions")
-
+ start_date_time=datetime(
+ 2015, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc
+ ),
+ end_date_time=datetime(
+ 2199, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc
+ ),
+ duration=30, active=True,
+ attempts_allowed=1, time_between_attempts=0,
+ description='demo quiz 1', pass_criteria=0,
+ instructions="Demo Instructions"
+ )
- self.course = Course.objects.create(name="Python Course",
- enrollment="Enroll Request", creator=self.user1)
+ self.course = Course.objects.create(
+ name="Python Course",
+ enrollment="Enroll Request",
+ creator=self.user1
+ )
self.questionpaper = QuestionPaper.objects.create(
quiz=self.quiz, total_marks=0.0, shuffle_questions=True
@@ -2250,7 +2262,6 @@ class AssignmentUploadTestCases(unittest.TestCase):
assignmentFile=file_path2, answer_paper=self.answerpaper1,
)
-
def test_get_assignments_for_user_files(self):
assignment_files, file_name = AssignmentUpload.objects.get_assignments(
self.questionpaper, self.question.id,
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 9d14490..e5ba8dd 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1054,7 +1054,7 @@ class TestDownloadAssignment(TestCase):
self.learning_module.delete()
self.learning_unit.delete()
self.mod_group.delete()
- dir_name = f'{self.course.name.replace(" ", "_")}_{self.course.id}'
+ dir_name = f'Course_{self.course.id}'
file_path = os.sep.join((settings.MEDIA_ROOT, dir_name))
if os.path.exists(file_path):
shutil.rmtree(file_path)