From fb72704a3339157f4f401a7f8b689bf549529b8c Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 9 Mar 2022 14:32:50 +0530 Subject: [PATCH] feat: cookie policy --- school/fixtures/custom_field.json | 4 +-- school/hooks.py | 3 +- .../doctype/lms_settings/lms_settings.json | 26 +++++++++++++++-- school/lms/utils.py | 28 +++++++++++++++++++ school/templates/signup-form.html | 21 +------------- 5 files changed, 57 insertions(+), 25 deletions(-) diff --git a/school/fixtures/custom_field.json b/school/fixtures/custom_field.json index 0eb474a6..c48b71f9 100644 --- a/school/fixtures/custom_field.json +++ b/school/fixtures/custom_field.json @@ -80,10 +80,10 @@ "in_standard_filter": 0, "insert_after": "country", "is_virtual": 0, - "label": "Acceptance for Terms of Use and/or Privacy Policy", + "label": "Acceptance for Terms and/or Policies", "length": 0, "mandatory_depends_on": null, - "modified": "2021-12-31 19:15:34.932910", + "modified": "2021-12-31 19:15:34.932911", "module": null, "name": "User-verify_terms", "no_copy": 0, diff --git a/school/hooks.py b/school/hooks.py index 63c792cb..53f67397 100644 --- a/school/hooks.py +++ b/school/hooks.py @@ -185,7 +185,8 @@ jinja = { "school.lms.utils.get_initial_members", "school.lms.utils.get_sorted_reviews", "school.lms.utils.is_instructor", - "school.lms.utils.convert_number_to_character" + "school.lms.utils.convert_number_to_character", + "school.lms.utils.get_signup_optin_checks" ], "filters": [] } diff --git a/school/lms/doctype/lms_settings/lms_settings.json b/school/lms/doctype/lms_settings/lms_settings.json index 35c07925..53197ad4 100644 --- a/school/lms/doctype/lms_settings/lms_settings.json +++ b/school/lms/doctype/lms_settings/lms_settings.json @@ -13,9 +13,12 @@ "signup_settings_section", "terms_of_use", "terms_page", - "column_break_12", + "column_break_9", "privacy_policy", "privacy_policy_page", + "column_break_12", + "cookie_policy", + "cookie_policy_page", "mentor_request_section", "mentor_request_creation", "mentor_request_status_update" @@ -96,17 +99,36 @@ "fieldname": "privacy_policy_page", "fieldtype": "Link", "label": "Privacy Policy Page", + "mandatory_depends_on": "privacy_policy", "options": "Web Page" }, { "fieldname": "column_break_12", "fieldtype": "Column Break" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "cookie_policy", + "fieldtype": "Check", + "label": "Show Cookie Policy on Signup" + }, + { + "depends_on": "cookie_policy", + "fieldname": "cookie_policy_page", + "fieldtype": "Link", + "label": "Cookie Policy Page", + "mandatory_depends_on": "cookie_policy", + "options": "Web Page" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2022-02-23 16:15:28.586903", + "modified": "2022-03-09 12:40:27.464136", "modified_by": "Administrator", "module": "LMS", "name": "LMS Settings", diff --git a/school/lms/utils.py b/school/lms/utils.py index 1eae98e7..8f2356fe 100644 --- a/school/lms/utils.py +++ b/school/lms/utils.py @@ -3,6 +3,7 @@ import frappe from frappe.utils import flt, cint, cstr from school.lms.md import markdown_to_html import string +from frappe import _ RE_SLUG_NOTALLOWED = re.compile("[^a-z0-9]+") @@ -296,3 +297,30 @@ def is_instructor(course): def convert_number_to_character(number): return string.ascii_uppercase[number] + +def get_signup_optin_checks(): + + mapper = frappe._dict({ + "terms_of_use": { + "page_name": "terms_page", + "title": _("Terms of Use") + }, + "privacy_policy": { + "page_name": "privacy_policy_page", + "title": _("Privacy Policy") + }, + "cookie_policy": { + "page_name": "cookie_policy_page", + "title": _("Cookie Policy") + } + }) + checks = ["terms_of_use", "privacy_policy", "cookie_policy"] + links = [] + + for check in checks: + if frappe.db.get_single_value("LMS Settings", check): + page = frappe.db.get_single_value("LMS Settings", mapper[check].get("page_name")) + route = frappe.db.get_value("Web Page", page, "route") + links.append("" + mapper[check].get("title") + "") + + return (", ").join(links) diff --git a/school/templates/signup-form.html b/school/templates/signup-form.html index 91c77910..1c668757 100644 --- a/school/templates/signup-form.html +++ b/school/templates/signup-form.html @@ -10,24 +10,6 @@ - {% set terms_of_use = frappe.db.get_single_value("LMS Settings", "terms_of_use") %} - {% set privacy_policy = frappe.db.get_single_value("LMS Settings", "privacy_policy") %} - - {% if terms_of_use or privacy_policy %} - - {% if terms_of_use %} - {% set terms_page = frappe.db.get_single_value("LMS Settings", "terms_page") %} - {% set terms_page_route = frappe.db.get_value("Web Page", terms_page, "route") %} - {% set terms_link = "" + _("Terms of Use") + "" %} - {% endif %} - - {% if privacy_policy %} - {% set privacy_policy_page = frappe.db.get_single_value("LMS Settings", "privacy_policy_page") %} - {% set privacy_page_route = frappe.db.get_value("Web Page", privacy_policy_page, "route") %} - {% set privacy_link = "" + _("Privacy Policy") + "" %} - {% endif %} - - {% set final_link = terms_link + _(" and ") + privacy_link if terms_of_use and privacy_policy else terms_link if terms_of_use else privacy_link %}
@@ -37,13 +19,12 @@ data-fieldtype="Check" data-fieldname="terms" id="signup-terms" required> - {{ _("I have read and agree to your {0}").format(final_link) }} + {{ _("I have read and agree to your {0}").format(get_signup_optin_checks()) }}

- {% endif %}