fix: file type support

This commit is contained in:
Jannat Patel
2021-12-23 17:58:39 +05:30
parent a6bdbd7cf1
commit 6e3de21f6e
7 changed files with 99 additions and 38 deletions

View File

@@ -9,7 +9,7 @@ frappe.ui.form.on('Course Lesson', {
frm.get_field('help').html(` frm.get_field('help').html(`
<p>You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p> <p>You can add some more additional content to the lesson using a special syntax. The table below mentions all types of dynamic content that you can add to the lessons and the syntax for the same.</p>
<div class="row font-weight-bold mb-3"> <div class="row font-weight-bold mb-3">
<div class="col-sm-4"> <div class="col-sm-8">
Content Type Content Type
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
@@ -18,7 +18,7 @@ frappe.ui.form.on('Course Lesson', {
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-sm-4"> <div class="col-sm-8">
Video Video
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
@@ -27,7 +27,7 @@ frappe.ui.form.on('Course Lesson', {
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-sm-4"> <div class="col-sm-8">
YouTube Video YouTube Video
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
@@ -36,7 +36,7 @@ frappe.ui.form.on('Course Lesson', {
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-sm-4"> <div class="col-sm-8">
Exercise Exercise
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
@@ -45,13 +45,60 @@ frappe.ui.form.on('Course Lesson', {
</div> </div>
<div class="row mb-3"> <div class="row mb-3">
<div class="col-sm-4"> <div class="col-sm-8">
Quiz Quiz
</div> </div>
<div class="col-sm-4"> <div class="col-sm-4">
{{ Quiz("lms_quiz_name") }} {{ Quiz("lms_quiz_name") }}
</div> </div>
</div> </div>
<div class="row mb-3">
<div class="col-sm-8">
Assignment
</div>
<div class="col-sm-4">
{{ Assignment("id-filetype") }}
</div>
</div>
<hr>
<div class="row font-weight-bold mb-3">
<div class="col-sm-8">
Supported File Types for Assignment
</div>
<div class="col-sm-4">
Syntax
</div>
</div>
<div class="row mb-3">
<div class="col-sm-8">
.doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document
</div>
<div class="col-sm-4">
Document
</div>
</div>
<div class="row mb-3">
<div class="col-sm-8">
.pdf
</div>
<div class="col-sm-4">
PDF
</div>
</div>
<div class="row mb-3">
<div class="col-sm-8">
.png, .jpg, .jpeg
</div>
<div class="col-sm-4">
Image
</div>
</div>
`); `);
} }
}); });

View File

@@ -10,15 +10,19 @@ class LessonAssignment(Document):
@frappe.whitelist() @frappe.whitelist()
def upload_assignment(assignment, lesson, identifier): def upload_assignment(assignment, lesson, identifier):
lesson_work = frappe.get_doc({ args = {
"doctype": "Lesson Assignment", "doctype": "Lesson Assignment",
"lesson": lesson, "lesson": lesson,
"user": frappe.session.user, "user": frappe.session.user,
"assignment": assignment,
"id": identifier "id": identifier
}) }
lesson_work = frappe.db.exists(args)
if lesson_work:
frappe.db.set_value("Lesson Assignment", lesson_work[0], "assignment", assignment)
else:
args.update({"assignment": assignment})
lesson_work = frappe.get_doc(args)
lesson_work.save(ignore_permissions=True) lesson_work.save(ignore_permissions=True)
return lesson_work.name
@frappe.whitelist() @frappe.whitelist()
def get_assignment(lesson): def get_assignment(lesson):
@@ -28,6 +32,10 @@ def get_assignment(lesson):
"user": frappe.session.user "user": frappe.session.user
}, },
["lesson", "user", "id", "assignment"]) ["lesson", "user", "id", "assignment"])
if len(assignments):
for assignment in assignments:
assignment.file_name = frappe.db.get_value("File", {"file_url": assignment.assignment}, "file_name")
return assignments

View File

@@ -121,8 +121,16 @@ def youtube_video_renderer(video_id):
def video_renderer(src): def video_renderer(src):
return "<video controls width='100%'><source src={0} type='video/mp4'></video>".format(src) return "<video controls width='100%'><source src={0} type='video/mp4'></video>".format(src)
def assignment_renderer(id): def assignment_renderer(detail):
return frappe.render_template("templates/assignment.html", {"id": id}) supported_types = {
"Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"PDF": ".pdf",
"Image": ".png, .jpg, .jpeg",
"Video": "video/*"
}
file_type = detail.split("-")[1]
accept = supported_types[file_type] if file_type else ""
return frappe.render_template("templates/assignment.html", {"id": detail.split("-")[0], "accept": accept})
def show_custom_signup(): def show_custom_signup():
if frappe.db.get_single_value("LMS Settings", "terms_of_use"): if frappe.db.get_single_value("LMS Settings", "terms_of_use"):

View File

@@ -1458,3 +1458,8 @@ pre {
.no-discussions { .no-discussions {
width: 80% !important; width: 80% !important;
} }
.preview-work {
width: 50%;
justify-content: space-between;
}

View File

@@ -1,10 +1,10 @@
<div class="form-group"> <div class="form-group">
<div class="d-flex"> <div class="d-flex">
<input class="btn btn-default btn-sm mr-3 attach-file" type="file" id="{{id}}" /> <input class="btn btn-default btn-sm mr-3 attach-file" type="file" id="{{ id }}" accept="{{ accept }}" />
<div class="button is-secondary submit-work">Submit Work</div> <div class="button is-secondary submit-work">Submit Work</div>
<div class="preview-work button mr-3 hide"> <div class="preview-work button is-default hide">
<a target="_blank"></a> <a target="_blank"></a>
<div class="button is-secondary clear-work hide">Clear</div> <div class="button is-secondary clear-work">Change</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -263,25 +263,14 @@ const upload_file = (file, target) => {
let response = JSON.parse(xhr.responseText) let response = JSON.parse(xhr.responseText)
create_lesson_work(response.message, target); create_lesson_work(response.message, target);
} else if (xhr.status === 403) { } else if (xhr.status === 403) {
file.failed = true;
let response = JSON.parse(xhr.responseText); let response = JSON.parse(xhr.responseText);
file.error_message = `Not permitted. ${response._error_message || ''}`; frappe.msgprint(`Not permitted. ${response._error_message || ''}`);
} else if (xhr.status === 413) { } else if (xhr.status === 413) {
file.failed = true; frappe.msgprint('Size exceeds the maximum allowed file size.');
file.error_message = 'Size exceeds the maximum allowed file size.';
} else { } else {
file.failed = true; frappe.msgprint(xhr.status === 0 ? 'XMLHttpRequest Error' : `${xhr.status} : ${xhr.statusText}`);
file.error_message = xhr.status === 0 ? 'XMLHttpRequest Error' : `${xhr.status} : ${xhr.statusText}`;
let error = null;
try {
error = JSON.parse(xhr.responseText);
} catch(e) {
// pass
}
frappe.request.cleanup({}, error);
} }
} }
} }
@@ -291,7 +280,7 @@ const upload_file = (file, target) => {
let form_data = new FormData(); let form_data = new FormData();
if (file.file_obj) { if (file.file_obj) {
form_data.append('file', file.file_obj, file.name); form_data.append('file', file.file_obj, `${frappe.session.user}-${file.name}`);
form_data.append('folder', `${$(".title").attr("data-lesson")} ${$(".title").attr("data-course")}`) form_data.append('folder', `${$(".title").attr("data-lesson")} ${$(".title").attr("data-course")}`)
} }
@@ -312,7 +301,6 @@ const create_lesson_work = (file, target) => {
target.siblings(".preview-work").removeClass("hide"); target.siblings(".preview-work").removeClass("hide");
target.siblings(".preview-work").find("a").attr("href", file.file_url).text(file.file_name) target.siblings(".preview-work").find("a").attr("href", file.file_url).text(file.file_name)
target.addClass("hide"); target.addClass("hide");
target.next(".clear-work").removeClass("hide");
} }
}); });
}; };
@@ -352,10 +340,10 @@ const add_files = (files) => {
const clear_work = (e) => { const clear_work = (e) => {
const target = $(e.currentTarget); const target = $(e.currentTarget);
target.siblings(".attach-file").removeClass("hide").val(null); const parent = target.closest(".preview-work");
target.siblings(".preview-work").addClass("hide"); parent.addClass("hide");
target.siblings(".submit-work").removeClass("hide"); parent.siblings(".attach-file").removeClass("hide").val(null);
target.addClass("hide"); parent.siblings(".submit-work").removeClass("hide");
} }
const fetch_assignments = () => { const fetch_assignments = () => {
@@ -367,8 +355,13 @@ const fetch_assignments = () => {
}, },
callback: (data) => { callback: (data) => {
if (data.message && data.message.length) { if (data.message && data.message.length) {
for (let assignment in data.message) { const assignments = data.message;
console.log(assignment.id) for (let i in assignments) {
let target = $(`#${assignments[i]["id"]}`);
target.addClass("hide");
target.siblings(".submit-work").addClass("hide");
target.siblings(".preview-work").removeClass("hide");
target.siblings(".preview-work").find("a").attr("href", assignments[i]["assignment"]).text(assignments[i]["file_name"]);
} }
} }
} }

View File

@@ -244,7 +244,7 @@
{% endif %} {% endif %}
{% if member.mobile_no and not member.hide_private %} {% if member.mobile_no and not member.hide_private %}
<a class="button-links" href="tel:{{ member.mobile_no }}" > <a class="button-links mobile-no" href="tel:{{ member.mobile_no }}" >
<img src="/assets/school/icons/call.svg"> {{ member.mobile_no }} <img src="/assets/school/icons/call.svg"> {{ member.mobile_no }}
</a> </a>
{% endif %} {% endif %}