Merge pull request #605 from pateljannat/assignment-url
feat: Assignment as URL
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
"member_name",
|
||||
"type",
|
||||
"assignment_attachment",
|
||||
"answer",
|
||||
"section_break_rqal",
|
||||
"status",
|
||||
"column_break_esgd",
|
||||
@@ -93,18 +94,18 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.type != \"URL\";",
|
||||
"fieldname": "assignment_attachment",
|
||||
"fieldtype": "Attach",
|
||||
"label": "Assignment Attachment",
|
||||
"reqd": 1
|
||||
"mandatory_depends_on": "eval:doc.type != \"URL\";"
|
||||
},
|
||||
{
|
||||
"fetch_from": "assignment.type",
|
||||
"fieldname": "type",
|
||||
"fieldtype": "Select",
|
||||
"label": "Type",
|
||||
"options": "Document\nPDF\nURL\nImage",
|
||||
"read_only": 1
|
||||
"options": "Document\nPDF\nURL\nImage"
|
||||
},
|
||||
{
|
||||
"fetch_from": "assignment.question",
|
||||
@@ -134,12 +135,19 @@
|
||||
{
|
||||
"fieldname": "column_break_ygdu",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.type == \"URL\";",
|
||||
"fieldname": "answer",
|
||||
"fieldtype": "Long Text",
|
||||
"label": "Answer",
|
||||
"mandatory_depends_on": "eval:doc.type == \"URL\";"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"make_attachments_public": 1,
|
||||
"modified": "2023-06-05 09:39:37.672298",
|
||||
"modified": "2023-08-30 12:09:03.332820",
|
||||
"modified_by": "Administrator",
|
||||
"module": "LMS",
|
||||
"name": "LMS Assignment Submission",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import validate_url
|
||||
|
||||
|
||||
class LMSAssignmentSubmission(Document):
|
||||
@@ -25,7 +26,8 @@ class LMSAssignmentSubmission(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def upload_assignment(
|
||||
assignment_attachment,
|
||||
assignment_attachment=None,
|
||||
answer=None,
|
||||
assignment=None,
|
||||
lesson=None,
|
||||
status="Not Graded",
|
||||
@@ -35,6 +37,17 @@ def upload_assignment(
|
||||
if frappe.session.user == "Guest":
|
||||
return
|
||||
|
||||
assignment_type = frappe.db.get_value("LMS Assignment", assignment, "type")
|
||||
|
||||
if assignment_type == "URL" and not answer:
|
||||
frappe.throw(_("Please enter the URL for assignment submission."))
|
||||
|
||||
if assignment_type == "File" and not assignment_attachment:
|
||||
frappe.throw(_("Please upload the assignment file."))
|
||||
|
||||
if assignment_type == "URL" and not validate_url(answer):
|
||||
frappe.throw(_("Please enter a valid URL."))
|
||||
|
||||
if submission:
|
||||
doc = frappe.get_doc("LMS Assignment Submission", submission)
|
||||
else:
|
||||
@@ -44,6 +57,7 @@ def upload_assignment(
|
||||
"assignment": assignment,
|
||||
"lesson": lesson,
|
||||
"member": frappe.session.user,
|
||||
"type": assignment_type,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -52,6 +66,7 @@ def upload_assignment(
|
||||
"assignment_attachment": assignment_attachment,
|
||||
"status": status,
|
||||
"comments": comments,
|
||||
"answer": answer,
|
||||
}
|
||||
)
|
||||
doc.save(ignore_permissions=True)
|
||||
|
||||
@@ -39,7 +39,8 @@
|
||||
|
||||
|
||||
<div class="align-self-center">
|
||||
<button class="btn btn-primary btn-sm btn-save-assignment" {% if assignment.name %} data-assignment="{{ assignment.name }}" {% endif %}
|
||||
<button class="btn btn-primary btn-sm btn-save-assignment"
|
||||
data-assignment="{{ assignment.name }}" data-type="{{ assignment.type }}"
|
||||
{% if submission.name %} data-submission="{{ submission.name }}" {% endif %}>
|
||||
{{ _("Save") }}
|
||||
</button>
|
||||
@@ -53,7 +54,7 @@
|
||||
<article class="field-parent">
|
||||
{% if submission.name and is_moderator %}
|
||||
<div class="field-group">
|
||||
<div class="field-label">
|
||||
<div class="bold-heading">
|
||||
{{ _("Student Name") }}
|
||||
</div>
|
||||
{{ submission.member_name }}
|
||||
@@ -61,14 +62,15 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="field-group">
|
||||
<div class="field-label">
|
||||
<div class="bold-heading">
|
||||
{{ _("Question")}}
|
||||
</div>
|
||||
{{ assignment.question }}
|
||||
</div>
|
||||
|
||||
{% if assignment.type != "URL" %}
|
||||
<div class="field-group">
|
||||
<div class="field-label">
|
||||
<div class="bold-heading">
|
||||
{{ _("Submit")}}
|
||||
</div>
|
||||
<div class="field-description">
|
||||
@@ -88,6 +90,19 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<div class="field-group">
|
||||
<div class="bold-heading">
|
||||
{{ _("Submit")}}
|
||||
</div>
|
||||
<div class="field-description">
|
||||
{{ _("Enter a URL") }}
|
||||
</div>
|
||||
<input id="assignment-url" type="text" class="field-input" placeholder="https://"
|
||||
{% if submission.answer %} value="{{ submission.answer }}" {% endif %}>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if is_moderator %}
|
||||
<div class="field-group">
|
||||
|
||||
@@ -47,12 +47,26 @@ const upload_file = (e) => {
|
||||
};
|
||||
|
||||
const save_assignment = (e) => {
|
||||
let file = $("#assignment-preview a").attr("href");
|
||||
if (!file) {
|
||||
frappe.throw({
|
||||
title: __("No File"),
|
||||
message: __("Please upload a file."),
|
||||
});
|
||||
let data = $(e.currentTarget).data("type");
|
||||
let answer,
|
||||
file = "";
|
||||
|
||||
if (data == "URL") {
|
||||
answer = $("#assignment-url").val();
|
||||
if (!answer) {
|
||||
frappe.throw({
|
||||
title: __("No URL"),
|
||||
message: __("Please enter a URL."),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
file = $("#assignment-preview a").attr("href");
|
||||
if (!file) {
|
||||
frappe.throw({
|
||||
title: __("No File"),
|
||||
message: __("Please upload a file."),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
frappe.call({
|
||||
@@ -61,6 +75,7 @@ const save_assignment = (e) => {
|
||||
assignment: $(e.currentTarget).data("assignment"),
|
||||
submission: $(e.currentTarget).data("submission") || "",
|
||||
assignment_attachment: file,
|
||||
answer: answer,
|
||||
status: $("#status").val(),
|
||||
comments: $("#comments").val(),
|
||||
},
|
||||
|
||||
@@ -23,7 +23,15 @@ def get_context(context):
|
||||
context.submission = frappe.db.get_value(
|
||||
"LMS Assignment Submission",
|
||||
submission,
|
||||
["name", "assignment_attachment", "comments", "status", "member", "member_name"],
|
||||
[
|
||||
"name",
|
||||
"assignment_attachment",
|
||||
"answer",
|
||||
"comments",
|
||||
"status",
|
||||
"member",
|
||||
"member_name",
|
||||
],
|
||||
as_dict=True,
|
||||
)
|
||||
if not context.is_moderator and frappe.session.user != context.submission.member:
|
||||
|
||||
Reference in New Issue
Block a user