From a101e7b089ea35ef16a6c69d5e899ce52f35dda7 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 2 Jun 2023 13:53:09 +0530 Subject: [PATCH] fix: class pages --- .vscode/settings.json | 3 - lms/hooks.py | 4 - .../lms_assignment_submission.py | 3 +- lms/lms/doctype/lms_batch/lms_batch.py | 1 - lms/public/css/style.css | 21 +--- lms/www/assignment_grading/__init__.py | 0 .../assignment_grading.html | 80 ------------- .../assignment_grading/assignment_grading.js | 55 --------- .../assignment_grading/assignment_grading.py | 35 ------ lms/www/classes/class.py | 36 +++--- lms/www/classes/index.py | 3 - lms/www/classes/progress.html | 109 ++---------------- lms/www/classes/progress.py | 4 +- lms/www/utils.py | 5 +- 14 files changed, 37 insertions(+), 322 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 lms/www/assignment_grading/__init__.py delete mode 100644 lms/www/assignment_grading/assignment_grading.html delete mode 100644 lms/www/assignment_grading/assignment_grading.js delete mode 100644 lms/www/assignment_grading/assignment_grading.py diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index de288e1e..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "python.formatting.provider": "black" -} \ No newline at end of file diff --git a/lms/hooks.py b/lms/hooks.py index 04482be2..07b8d74b 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -179,10 +179,6 @@ website_route_rules = [ "from_route": "/classes//students/", "to_route": "/classes/progress", }, - { - "from_route": "/assignment-grading/", - "to_route": "assignment_grading/assignment_grading", - }, {"from_route": "/assignments/", "to_route": "assignments/assignment"}, { "from_route": "/assignment-submission//", diff --git a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py index d1ca029b..e69558c7 100644 --- a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py +++ b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py @@ -46,8 +46,7 @@ def upload_assignment( "member": frappe.session.user, } ) - print(doc.assignment) - print(comments) + doc.update( { "assignment_attachment": assignment_attachment, diff --git a/lms/lms/doctype/lms_batch/lms_batch.py b/lms/lms/doctype/lms_batch/lms_batch.py index b2d13a79..6e005024 100644 --- a/lms/lms/doctype/lms_batch/lms_batch.py +++ b/lms/lms/doctype/lms_batch/lms_batch.py @@ -80,7 +80,6 @@ def switch_batch(course_name, email, batch_name): old_batch = frappe.get_doc("LMS Batch", membership.batch) - print("updating membership", membership.name) membership.batch = batch_name membership.save() diff --git a/lms/public/css/style.css b/lms/public/css/style.css index 5842cea7..342c14e6 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -115,26 +115,11 @@ body { } .image-preview { - width: 100%; - height: 100%; + width: 280px; + height: 178px; border-radius: var(--border-radius-md); -} - -.file-source-preview { - display: flex; - align-items: center; - justify-content: center; - position: relative; - width: 100%; - height: 250px; border: 1px solid var(--gray-300); - border-radius: var(--border-radius-md); -} - -.file-source-preview .btn-close { - position: absolute; - top: 5%; - right: 5%; + margin-top: 1rem; } textarea.field-input { diff --git a/lms/www/assignment_grading/__init__.py b/lms/www/assignment_grading/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/lms/www/assignment_grading/assignment_grading.html b/lms/www/assignment_grading/assignment_grading.html deleted file mode 100644 index eebfee2f..00000000 --- a/lms/www/assignment_grading/assignment_grading.html +++ /dev/null @@ -1,80 +0,0 @@ -{% extends "templates/base.html" %} -{% block title %} - {{ _("Assignments") }} -{% endblock %} - - -{% block content %} -
-
-
-
{{ _("Assignment Grading") }}
- {{ AssignmentForm(assignment) }} -
-
-
- -{% endblock %} - - -{% macro AssignmentForm(assignment) %} -{% set course_title = frappe.db.get_value("LMS Course", assignment.course, "title") %} -{% set lesson_title = frappe.db.get_value("Course Lesson", assignment.lesson, "title") %} - -
- -
-
-
- - -
-
- - -
-
- -
-
-
- - -
- -
- -
- -
- - - -
-
-
-
- -
- - -
-
-
- -
- - {{ _("Open Attachment") }} - - -
-
-{% endmacro %} diff --git a/lms/www/assignment_grading/assignment_grading.js b/lms/www/assignment_grading/assignment_grading.js deleted file mode 100644 index 8c16136e..00000000 --- a/lms/www/assignment_grading/assignment_grading.js +++ /dev/null @@ -1,55 +0,0 @@ -frappe.ready(() => { - this.result; - let self = this; - - set_result(); - - $("#save-assignment").click((e) => { - save_assignment(e); - }); - - $("#result").change((e) => { - $("#result option:selected").each(function () { - self.result = $(this).val(); - }); - }); -}); - -const set_result = () => { - let self = this; - let result = $("#result").data("type"); - if (result) { - $("#result option").each((i, elem) => { - if ($(elem).val() == result) { - $(elem).attr("selected", true); - self.result = result; - } - }); - } -}; - -const save_assignment = (e) => { - e.preventDefault(); - if (!["Pass", "Fail"].includes(this.result)) - frappe.throw({ - title: __("Not Graded"), - message: __("Please grade the assignment."), - }); - frappe.call({ - method: "lms.lms.doctype.lms_assignment_submission.lms_assignment_submission.grade_assignment", - args: { - name: $(e.currentTarget).data("assignment"), - result: this.result, - comments: $("#comments").val(), - }, - callback: (data) => { - frappe.show_alert({ - message: __("Saved"), - indicator: "green", - }); - setTimeout(() => { - window.history.go(-2); - }, 2000); - }, - }); -}; diff --git a/lms/www/assignment_grading/assignment_grading.py b/lms/www/assignment_grading/assignment_grading.py deleted file mode 100644 index ab9c8233..00000000 --- a/lms/www/assignment_grading/assignment_grading.py +++ /dev/null @@ -1,35 +0,0 @@ -import frappe -from lms.lms.utils import has_course_moderator_role -from frappe import _ - - -def get_context(context): - context.no_cache = 1 - assignment = frappe.form_dict["assignment"] - - context.assignment = frappe.db.get_value( - "LMS Assignment Submission", - assignment, - [ - "assignment", - "comments", - "status", - "name", - "member", - "member_name", - "course", - "lesson", - ], - as_dict=True, - ) - context.is_moderator = has_course_moderator_role() - - if ( - not has_course_moderator_role() - and not frappe.session.user == context.assignment.member - ): - message = "You don't have the permissions to access this page." - if frappe.session.user == "Guest": - message = "Please login to access this page." - - raise frappe.PermissionError(_(message)) diff --git a/lms/www/classes/class.py b/lms/www/classes/class.py index e6620d03..93401570 100644 --- a/lms/www/classes/class.py +++ b/lms/www/classes/class.py @@ -68,22 +68,12 @@ def get_context(context): order_by="date", ) - context.assessments = get_assessments(context.is_moderator, class_name) + context.assessments = get_assessments(class_name) + context.all_assignments = get_all_assignments(class_name) + context.all_quizzes = get_all_quizzes(class_name) - all_assignments = frappe.get_all( - "LMS Assignment", {"owner": frappe.session.user}, ["name", "title"] - ) - for assignment in all_assignments: - assignment.checked = frappe.db.exists( - { - "doctype": "LMS Assessment", - "assessment_type": "LMS Assignment", - "assessment_name": assignment.name, - "parent": class_name, - } - ) - context.all_assignments = all_assignments +def get_all_quizzes(class_name): all_quizzes = frappe.get_all( "LMS Quiz", {"owner": frappe.session.user}, ["name", "title"] ) @@ -96,4 +86,20 @@ def get_context(context): "parent": class_name, } ) - context.all_quizzes = all_quizzes + return all_quizzes + + +def get_all_assignments(class_name): + all_assignments = frappe.get_all( + "LMS Assignment", {"owner": frappe.session.user}, ["name", "title"] + ) + for assignment in all_assignments: + assignment.checked = frappe.db.exists( + { + "doctype": "LMS Assessment", + "assessment_type": "LMS Assignment", + "assessment_name": assignment.name, + "parent": class_name, + } + ) + return all_assignments diff --git a/lms/www/classes/index.py b/lms/www/classes/index.py index 038dd575..8f44a81a 100644 --- a/lms/www/classes/index.py +++ b/lms/www/classes/index.py @@ -13,7 +13,6 @@ def get_context(context): past_classes, upcoming_classes = [], [] for class_ in classes: - print(class_.start_date) if getdate(class_.start_date) < getdate(): past_classes.append(class_) else: @@ -39,5 +38,3 @@ def get_context(context): ) context.my_classes = my_classes_info - - print(context.my_classes) diff --git a/lms/www/classes/progress.html b/lms/www/classes/progress.html index b2b2eaba..4f7be796 100644 --- a/lms/www/classes/progress.html +++ b/lms/www/classes/progress.html @@ -34,11 +34,13 @@ + {% if is_moderator %} + {% endif %} @@ -47,7 +49,8 @@ {% macro Progress(class_info, student) %} -
+{% if assessments | length %} +
-{% endmacro %} - - -{% macro Quiz(course, student) %} - {% for quiz in course.quizzes %} - {% set filters = { "member": student.name, "course": course.course } %} - {% set has_submitted = frappe.db.exists("LMS Quiz Submission", filters) %} - {% set submission = frappe.db.get_value("LMS Quiz Submission", filters, ["score", "creation"], as_dict=True) %} - {% set total_questions = frappe.db.count("LMS Quiz Question", {"parent": quiz.name}) %} - - - - - - - {{ _("Quiz") }} - - {{ quiz.title }} - {% if has_submitted %} - {{ submission.score }}/{{ total_questions }} - {{ frappe.utils.format_date(submission.creation, "medium") }} - {% else %} - - - -
- {{ _("Not Attempted") }} -
- - {% endif %} - - {% endfor %} -{% endmacro %} - - -{% macro Assignment(course, student, is_moderator) %} - {% for assignment in course.assignments %} - {% set filters = { "member": student.name, "course": course.course, "lesson": assignment.name } %} - {% set has_submitted = frappe.db.exists("LMS Assignment Submission", filters) %} - {% set submission = frappe.db.get_value("LMS Assignment Submission", filters, ["assignment", "creation", "status"], as_dict=True) %} - {% set status = submission.status %} - {% set color = "green" if status == "Pass" else "red" if status == "Fail" else "orange" %} - {% set can_see_details = has_submitted and (is_moderator or frappe.session.user == student.name) %} - - - - - - - {{ _("Assignment") }} - - - {{ assignment.title }} - - {% if has_submitted %} - -
- {{ status }} -
- - - {{ frappe.utils.format_date(submission.creation, "medium") }} - - {% else %} - - - - -
- {{ _("Not Attempted") }} -
- - {% endif %} - - {% endfor %} -{% endmacro %} - - -{% macro Evaluation(course, student, is_moderator) %} - {% for evaluation in course.evaluations %} - {% set color = "green" if evaluation.status == "Pass" else "red" %} - {% set can_see_details = is_moderator or frappe.session.user == student.name %} - - - - - - - {{ _("Evaluation") }} - - - - -
- {{ evaluation.status }} -
- - {{ frappe.utils.format_date(evaluation.creation, "medium") }} - - {% endfor %} -{% endmacro %} + +{% else %} +

{{ _("No Assessments") }}

+{% endif %} +{% endmacro %} \ No newline at end of file diff --git a/lms/www/classes/progress.py b/lms/www/classes/progress.py index 83f4f21f..be922dd1 100644 --- a/lms/www/classes/progress.py +++ b/lms/www/classes/progress.py @@ -21,6 +21,4 @@ def get_context(context): "LMS Class", class_name, ["name"], as_dict=True ) - context.assessments = get_assessments( - context.is_moderator, class_name, context.student.name - ) + context.assessments = get_assessments(class_name, context.student.name) diff --git a/lms/www/utils.py b/lms/www/utils.py index 1400f826..4cb7c32e 100644 --- a/lms/www/utils.py +++ b/lms/www/utils.py @@ -59,7 +59,7 @@ def get_current_lesson_details(lesson_number, context, is_edit=False): return lesson_info -def get_assessments(is_moderator, class_name, member=None): +def get_assessments(class_name, member=None): if not member: member = frappe.session.user @@ -92,7 +92,6 @@ def get_assessments(is_moderator, class_name, member=None): ) assessment.edit_url = f"/assignments/{assessment.assessment_name}" - assessment.grade_url = f"/assignment-grading/{existing_submission}" submission_name = existing_submission if existing_submission else "new-submission" assessment.url = ( f"/assignment-submission/{assessment.assessment_name}/{submission_name}" @@ -103,5 +102,5 @@ def get_assessments(is_moderator, class_name, member=None): "LMS Quiz", assessment.assessment_name, "title" ) assessment.url = f"/quizzes/{assessment.assessment_name}" - + print(assessments) return assessments