fix: file type support
This commit is contained in:
@@ -9,7 +9,7 @@ frappe.ui.form.on('Course Lesson', {
|
||||
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>
|
||||
<div class="row font-weight-bold mb-3">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-8">
|
||||
Content Type
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
@@ -18,7 +18,7 @@ frappe.ui.form.on('Course Lesson', {
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-8">
|
||||
Video
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
@@ -27,7 +27,7 @@ frappe.ui.form.on('Course Lesson', {
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-8">
|
||||
YouTube Video
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
@@ -36,7 +36,7 @@ frappe.ui.form.on('Course Lesson', {
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-8">
|
||||
Exercise
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
@@ -45,13 +45,60 @@ frappe.ui.form.on('Course Lesson', {
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-sm-4">
|
||||
<div class="col-sm-8">
|
||||
Quiz
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
{{ Quiz("lms_quiz_name") }}
|
||||
</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>
|
||||
`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,15 +10,19 @@ class LessonAssignment(Document):
|
||||
|
||||
@frappe.whitelist()
|
||||
def upload_assignment(assignment, lesson, identifier):
|
||||
lesson_work = frappe.get_doc({
|
||||
args = {
|
||||
"doctype": "Lesson Assignment",
|
||||
"lesson": lesson,
|
||||
"user": frappe.session.user,
|
||||
"assignment": assignment,
|
||||
"id": identifier
|
||||
})
|
||||
lesson_work.save(ignore_permissions=True)
|
||||
return lesson_work.name
|
||||
}
|
||||
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)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_assignment(lesson):
|
||||
@@ -28,6 +32,10 @@ def get_assignment(lesson):
|
||||
"user": frappe.session.user
|
||||
},
|
||||
["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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -121,8 +121,16 @@ def youtube_video_renderer(video_id):
|
||||
def video_renderer(src):
|
||||
return "<video controls width='100%'><source src={0} type='video/mp4'></video>".format(src)
|
||||
|
||||
def assignment_renderer(id):
|
||||
return frappe.render_template("templates/assignment.html", {"id": id})
|
||||
def assignment_renderer(detail):
|
||||
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():
|
||||
if frappe.db.get_single_value("LMS Settings", "terms_of_use"):
|
||||
|
||||
@@ -1458,3 +1458,8 @@ pre {
|
||||
.no-discussions {
|
||||
width: 80% !important;
|
||||
}
|
||||
|
||||
.preview-work {
|
||||
width: 50%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<div class="form-group">
|
||||
<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="preview-work button mr-3 hide">
|
||||
<div class="preview-work button is-default hide">
|
||||
<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>
|
||||
|
||||
@@ -263,25 +263,14 @@ const upload_file = (file, target) => {
|
||||
let response = JSON.parse(xhr.responseText)
|
||||
create_lesson_work(response.message, target);
|
||||
} else if (xhr.status === 403) {
|
||||
file.failed = true;
|
||||
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) {
|
||||
file.failed = true;
|
||||
file.error_message = 'Size exceeds the maximum allowed file size.';
|
||||
frappe.msgprint('Size exceeds the maximum allowed file size.');
|
||||
|
||||
} else {
|
||||
file.failed = true;
|
||||
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);
|
||||
frappe.msgprint(xhr.status === 0 ? 'XMLHttpRequest Error' : `${xhr.status} : ${xhr.statusText}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +280,7 @@ const upload_file = (file, target) => {
|
||||
|
||||
let form_data = new FormData();
|
||||
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")}`)
|
||||
}
|
||||
|
||||
@@ -312,7 +301,6 @@ const create_lesson_work = (file, target) => {
|
||||
target.siblings(".preview-work").removeClass("hide");
|
||||
target.siblings(".preview-work").find("a").attr("href", file.file_url).text(file.file_name)
|
||||
target.addClass("hide");
|
||||
target.next(".clear-work").removeClass("hide");
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -352,10 +340,10 @@ const add_files = (files) => {
|
||||
|
||||
const clear_work = (e) => {
|
||||
const target = $(e.currentTarget);
|
||||
target.siblings(".attach-file").removeClass("hide").val(null);
|
||||
target.siblings(".preview-work").addClass("hide");
|
||||
target.siblings(".submit-work").removeClass("hide");
|
||||
target.addClass("hide");
|
||||
const parent = target.closest(".preview-work");
|
||||
parent.addClass("hide");
|
||||
parent.siblings(".attach-file").removeClass("hide").val(null);
|
||||
parent.siblings(".submit-work").removeClass("hide");
|
||||
}
|
||||
|
||||
const fetch_assignments = () => {
|
||||
@@ -367,8 +355,13 @@ const fetch_assignments = () => {
|
||||
},
|
||||
callback: (data) => {
|
||||
if (data.message && data.message.length) {
|
||||
for (let assignment in data.message) {
|
||||
console.log(assignment.id)
|
||||
const assignments = data.message;
|
||||
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"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% 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 }}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user