fix: pre commit issues

This commit is contained in:
Jannat Patel
2022-11-04 11:47:09 +05:30
parent cda26ab248
commit 603eddf878
210 changed files with 10725 additions and 6733 deletions

View File

@@ -16,121 +16,116 @@ be loaded in a webpage.
import frappe
class PageExtension:
"""PageExtension is a plugin to inject custom styles and scripts
into a web page.
"""PageExtension is a plugin to inject custom styles and scripts
into a web page.
The subclasses should overwrite the `render_header()` and
`render_footer()` methods to inject whatever styles/scripts into
the webpage.
"""
def __init__(self):
self.context = frappe._dict()
The subclasses should overwrite the `render_header()` and
`render_footer()` methods to inject whatever styles/scripts into
the webpage.
"""
def set_context(self, context):
self.context = context
def __init__(self):
self.context = frappe._dict()
def render_header(self):
"""Returns the HTML snippet to be included in the head section
of the web page.
def set_context(self, context):
self.context = context
Typically used to include the stylesheets and javascripts to be
included in the <head> of the webpage.
"""
return ""
def render_header(self):
"""Returns the HTML snippet to be included in the head section
of the web page.
def render_footer(self):
"""Returns the HTML snippet to be included in the body tag at
the end of web page.
Typically used to include the stylesheets and javascripts to be
included in the <head> of the webpage.
"""
return ""
def render_footer(self):
"""Returns the HTML snippet to be included in the body tag at
the end of web page.
Typically used to include javascripts that need to be executed
after the page is loaded.
"""
return ""
Typically used to include javascripts that need to be executed
after the page is loaded.
"""
return ""
class ProfileTab:
"""Base class for profile tabs.
"""Base class for profile tabs.
Every subclass of ProfileTab must implement two methods:
- get_title()
- render()
"""
def __init__(self, user):
self.user = user
Every subclass of ProfileTab must implement two methods:
- get_title()
- render()
"""
def get_title(self):
"""Returns the title of the tab.
def __init__(self, user):
self.user = user
Every subclass must implement this.
"""
raise NotImplementedError()
def get_title(self):
"""Returns the title of the tab.
def render(self):
"""Renders the contents of the tab as HTML.
Every subclass must implement this.
"""
raise NotImplementedError()
def render(self):
"""Renders the contents of the tab as HTML.
Every subclass must implement this.
"""
raise NotImplementedError()
Every subclass must implement this.
"""
raise NotImplementedError()
class LiveCodeExtension(PageExtension):
def render_header(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {
"livecode_url": livecode_url
}
return frappe.render_template(
"templates/livecode/extension_header.html",
context)
def render_header(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {"livecode_url": livecode_url}
return frappe.render_template("templates/livecode/extension_header.html", context)
def render_footer(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {"livecode_url": livecode_url}
return frappe.render_template("templates/livecode/extension_footer.html", context)
def render_footer(self):
livecode_url = frappe.get_value("LMS Settings", None, "livecode_url")
context = {
"livecode_url": livecode_url
}
return frappe.render_template(
"templates/livecode/extension_footer.html",
context)
def set_mandatory_fields_for_profile():
profile_form = frappe.get_doc("Web Form", "profile")
profile_mandatory_fields = frappe.get_hooks("profile_mandatory_fields")
for field in profile_form.web_form_fields:
field.reqd = 0
if field.fieldname in profile_mandatory_fields:
field.reqd = 1
profile_form = frappe.get_doc("Web Form", "profile")
profile_mandatory_fields = frappe.get_hooks("profile_mandatory_fields")
for field in profile_form.web_form_fields:
field.reqd = 0
if field.fieldname in profile_mandatory_fields:
field.reqd = 1
profile_form.save()
profile_form.save()
def quiz_renderer(quiz_name):
quiz = frappe.get_doc("LMS Quiz", quiz_name)
quiz = frappe.get_doc("LMS Quiz", quiz_name)
context = {
"quiz": quiz
}
context = {"quiz": quiz}
no_of_attempts = frappe.db.count("LMS Quiz Submission", {
"owner": frappe.session.user,
"quiz": quiz_name})
no_of_attempts = frappe.db.count(
"LMS Quiz Submission", {"owner": frappe.session.user, "quiz": quiz_name}
)
if quiz.max_attempts and no_of_attempts >= quiz.max_attempts:
last_attempt_score = frappe.db.get_value("LMS Quiz Submission", {
"owner": frappe.session.user,
"quiz": quiz_name
}, ["score"])
if quiz.max_attempts and no_of_attempts >= quiz.max_attempts:
last_attempt_score = frappe.db.get_value(
"LMS Quiz Submission", {"owner": frappe.session.user, "quiz": quiz_name}, ["score"]
)
context.update({"attempts_exceeded": True, "last_attempt_score": last_attempt_score})
return frappe.render_template("templates/quiz.html", context)
context.update({
"attempts_exceeded": True,
"last_attempt_score": last_attempt_score
})
return frappe.render_template("templates/quiz.html", context)
def exercise_renderer(argument):
exercise = frappe.get_doc("Exercise", argument)
context = dict(exercise=exercise)
return frappe.render_template("templates/exercise.html", context)
exercise = frappe.get_doc("Exercise", argument)
context = dict(exercise=exercise)
return frappe.render_template("templates/exercise.html", context)
def youtube_video_renderer(video_id):
return f"""
return f"""
<iframe width="100%" height="400"
src="https://www.youtube.com/embed/{video_id}"
title="YouTube video player"
@@ -141,23 +136,29 @@ def youtube_video_renderer(video_id):
</iframe>
"""
def video_renderer(src):
return "<video controls width='100%'><source src={0} type='video/mp4'></video>".format(src)
return f"<video controls width='100%'><source src={src} type='video/mp4'></video>"
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/*"
}
question = detail.split("-")[0]
file_type = detail.split("-")[1]
accept = supported_types[file_type] if file_type else ""
return frappe.render_template("templates/assignment.html", {"question": question, "accept": accept})
supported_types = {
"Document": ".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"PDF": ".pdf",
"Image": ".png, .jpg, .jpeg",
"Video": "video/*",
}
question = detail.split("-")[0]
file_type = detail.split("-")[1]
accept = supported_types[file_type] if file_type else ""
return frappe.render_template(
"templates/assignment.html", {"question": question, "accept": accept}
)
def show_custom_signup():
if (frappe.db.get_single_value("LMS Settings", "terms_of_use")
or frappe.db.get_single_value("LMS Settings", "privacy_policy")):
return "lms/templates/signup-form.html"
return "frappe/templates/signup.html"
if frappe.db.get_single_value(
"LMS Settings", "terms_of_use"
) or frappe.db.get_single_value("LMS Settings", "privacy_policy"):
return "lms/templates/signup-form.html"
return "frappe/templates/signup.html"