diff --git a/school/hooks.py b/school/hooks.py index d0180537..b6c9e956 100644 --- a/school/hooks.py +++ b/school/hooks.py @@ -172,6 +172,7 @@ jinja = { #] profile_mandatory_fields = [ + "first_name", "last_name", "user_image", "bio", diff --git a/school/lms/doctype/certification/certification.json b/school/lms/doctype/certification/certification.json index 8aef0e9b..cbd5be2e 100644 --- a/school/lms/doctype/certification/certification.json +++ b/school/lms/doctype/certification/certification.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-07 12:20:37.143096", "doctype": "DocType", "editable_grid": 1, @@ -61,10 +62,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-14 11:42:24.844113", + "modified": "2021-12-21 10:05:43.377876", "modified_by": "Administrator", "module": "LMS", "name": "Certification", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/doctype/education_detail/education_detail.json b/school/lms/doctype/education_detail/education_detail.json index e448a4b4..70f085dc 100644 --- a/school/lms/doctype/education_detail/education_detail.json +++ b/school/lms/doctype/education_detail/education_detail.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-07 12:15:46.078717", "doctype": "DocType", "editable_grid": 1, @@ -74,10 +75,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-10 12:12:58.827429", + "modified": "2021-12-21 09:58:42.343823", "modified_by": "Administrator", "module": "LMS", "name": "Education Detail", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/doctype/function/function.json b/school/lms/doctype/function/function.json index 269ef60e..918ceb3e 100644 --- a/school/lms/doctype/function/function.json +++ b/school/lms/doctype/function/function.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-14 14:02:46.474260", + "modified": "2021-12-21 09:34:35.018280", "modified_by": "Administrator", "module": "LMS", "name": "Function", @@ -37,6 +37,16 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, + "share": 1 } ], "sort_field": "modified", diff --git a/school/lms/doctype/industry/industry.json b/school/lms/doctype/industry/industry.json index c0c2ce2d..2ab23031 100644 --- a/school/lms/doctype/industry/industry.json +++ b/school/lms/doctype/industry/industry.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-14 14:38:10.405473", + "modified": "2021-12-21 09:35:20.443192", "modified_by": "Administrator", "module": "LMS", "name": "Industry", @@ -37,6 +37,16 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, + "share": 1 } ], "sort_field": "modified", diff --git a/school/lms/doctype/lms_settings/lms_settings.py b/school/lms/doctype/lms_settings/lms_settings.py index 46064cd3..0681a991 100644 --- a/school/lms/doctype/lms_settings/lms_settings.py +++ b/school/lms/doctype/lms_settings/lms_settings.py @@ -14,7 +14,7 @@ def check_profile_restriction(): force_profile_completion = frappe.db.get_single_value("LMS Settings", "force_profile_completion") user = frappe.db.get_value("User", frappe.session.user, ["profile_complete", "username"], as_dict=True) return { - "redirect": force_profile_completion and not user.profile_complete, + "restrict": force_profile_completion and not user.profile_complete, "username": user.username, - "prefix": frappe.get_hooks("profile_url_prefix") or "/users/" + "prefix": frappe.get_hooks("profile_url_prefix")[0] or "/users/" } diff --git a/school/lms/doctype/preferred_function/preferred_function.json b/school/lms/doctype/preferred_function/preferred_function.json index c47b5d81..d4bafd05 100644 --- a/school/lms/doctype/preferred_function/preferred_function.json +++ b/school/lms/doctype/preferred_function/preferred_function.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-14 14:42:48.823215", "doctype": "DocType", "editable_grid": 1, @@ -12,19 +13,20 @@ { "fieldname": "function", "fieldtype": "Link", + "ignore_user_permissions": 1, "in_list_view": 1, "label": "Function", - "options": "Function", - "reqd": 1 + "options": "Function" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-14 14:42:48.823215", + "modified": "2021-12-21 10:07:01.448239", "modified_by": "Administrator", "module": "LMS", "name": "Preferred Function", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/doctype/preferred_industry/preferred_industry.json b/school/lms/doctype/preferred_industry/preferred_industry.json index d4be8c76..9e5c1402 100644 --- a/school/lms/doctype/preferred_industry/preferred_industry.json +++ b/school/lms/doctype/preferred_industry/preferred_industry.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-14 14:44:06.808797", "doctype": "DocType", "editable_grid": 1, @@ -21,10 +22,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-14 14:44:21.215262", + "modified": "2021-12-21 10:07:14.537564", "modified_by": "Administrator", "module": "LMS", "name": "Preferred Industry", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/doctype/skill/skill.json b/school/lms/doctype/skill/skill.json index 70fd28e3..c9d1820e 100644 --- a/school/lms/doctype/skill/skill.json +++ b/school/lms/doctype/skill/skill.json @@ -19,7 +19,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-12 10:02:39.584832", + "modified": "2021-12-21 09:35:44.265910", "modified_by": "Administrator", "module": "LMS", "name": "Skill", @@ -37,6 +37,16 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "All", + "select": 1, + "share": 1 } ], "sort_field": "modified", diff --git a/school/lms/doctype/skills/skills.json b/school/lms/doctype/skills/skills.json index 21bdcade..856b0053 100644 --- a/school/lms/doctype/skills/skills.json +++ b/school/lms/doctype/skills/skills.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-07 12:22:44.139341", "doctype": "DocType", "editable_grid": 1, @@ -21,10 +22,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-13 14:42:43.962186", + "modified": "2021-12-21 09:59:31.631132", "modified_by": "Administrator", "module": "LMS", "name": "Skills", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/doctype/work_experience/work_experience.json b/school/lms/doctype/work_experience/work_experience.json index a5f0fa45..1aea3779 100644 --- a/school/lms/doctype/work_experience/work_experience.json +++ b/school/lms/doctype/work_experience/work_experience.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "autoname": "hash", "creation": "2021-12-07 12:17:49.571045", "doctype": "DocType", "editable_grid": 1, @@ -70,10 +71,11 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-12-09 16:25:48.104205", + "modified": "2021-12-21 09:58:56.254035", "modified_by": "Administrator", "module": "LMS", "name": "Work Experience", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/school/lms/web_form/profile/profile.js b/school/lms/web_form/profile/profile.js index 0822212c..f76ec156 100644 --- a/school/lms/web_form/profile/profile.js +++ b/school/lms/web_form/profile/profile.js @@ -14,7 +14,7 @@ frappe.ready(function () { frappe.web_form.validate = () => { let information_missing; const data = frappe.web_form.get_values(); - data.work_experience.forEach(exp => { + data.work_experience && data.work_experience.length && data.work_experience.forEach(exp => { if (!exp.current && !exp.to_date) { information_missing = true frappe.msgprint('To Date is mandatory in Work Experience.'); diff --git a/school/lms/web_form/profile/profile.json b/school/lms/web_form/profile/profile.json index 7044f897..c581e8c6 100644 --- a/school/lms/web_form/profile/profile.json +++ b/school/lms/web_form/profile/profile.json @@ -21,7 +21,7 @@ "is_standard": 1, "login_required": 1, "max_attachment_size": 0, - "modified": "2021-12-20 13:20:19.810134", + "modified": "2021-12-21 11:05:56.505121", "modified_by": "Administrator", "module": "LMS", "name": "profile", @@ -330,7 +330,7 @@ "fieldname": "preferred_location", "fieldtype": "Data", "hidden": 0, - "label": "Preferred Location", + "label": "Preferred Locations", "max_length": 0, "max_value": 0, "options": "", @@ -411,7 +411,7 @@ "label": "Location Preference", "max_length": 0, "max_value": 0, - "options": "Travel to work\nOffice close to Home", + "options": "Travel\nOffice close to Home", "read_only": 0, "reqd": 0, "show_in_filter": 0 @@ -456,4 +456,4 @@ "show_in_filter": 0 } ] -} \ No newline at end of file +} diff --git a/school/overrides/user.py b/school/overrides/user.py index 417ab656..03fc9f77 100644 --- a/school/overrides/user.py +++ b/school/overrides/user.py @@ -51,6 +51,12 @@ class CustomUser(User): if len(self.username) < 4: frappe.throw(_("Username cannot be less than 4 characters")) + def get_username_from_first_name(self): + return frappe.scrub(self.first_name) + str(random.randint(0, 99)) + + def remove_illegal_characters(self): + return re.sub("[^\w]+", "", self.username).strip("_") + def validate_skills(self): unique_skills = [] for skill in self.skill: @@ -61,12 +67,18 @@ class CustomUser(User): else: frappe.throw(_("Skills must be unique")) + def validate_completion(self): + all_fields_have_value = True + if frappe.db.get_single_value("LMS Settings", "force_profile_completion"): + profile_mandatory_fields = frappe.get_hooks("profile_mandatory_fields") + docfields = frappe.get_meta(self.doctype).fields - def get_username_from_first_name(self): - return frappe.scrub(self.first_name) + str(random.randint(0, 99)) + for field in profile_mandatory_fields: + if not self.get(field): + all_fields_have_value = False + break - def remove_illegal_characters(self): - return re.sub("[^\w]+", "", self.username).strip("_") + self.profile_complete = all_fields_have_value def get_authored_courses(self) -> int: """Returns the number of courses authored by this user. diff --git a/school/plugins.py b/school/plugins.py index 5643f57c..e44ba124 100644 --- a/school/plugins.py +++ b/school/plugins.py @@ -86,6 +86,17 @@ class LiveCodeExtension(PageExtension): "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: + print(field.fieldname) + field.reqd = 1 + + profile_form.save() + def quiz_renderer(quiz_name): quiz = frappe.get_doc("LMS Quiz", quiz_name) context = dict(quiz=quiz) diff --git a/school/public/js/profile.js b/school/public/js/profile.js index dd093224..b0aa3ccc 100644 --- a/school/public/js/profile.js +++ b/school/public/js/profile.js @@ -1,6 +1,5 @@ frappe.ready(() => { hide_profile_for_guest_users(); - restrict_users_to_profile_page(); }); const hide_profile_for_guest_users = () => { @@ -9,19 +8,3 @@ const hide_profile_for_guest_users = () => { link_array.length && $(link_array[0]).addClass("hide"); } }; - -const restrict_users_to_profile_page = () => { - setTimeout(() => { - var link_array = $('.nav-link').filter((i, elem) => $(elem).text().trim() === "My Profile"); - if (frappe.session.user != "Guest" && link_array.length && !$(link_array[0]).hasClass("active")) { - frappe.call({ - "method": "school.lms.doctype.lms_settings.lms_settings.check_profile_restriction", - "callback": (data) => { - if (data.message && data.message.redirect) { - window.location.href = `${data.message.prefix}${data.message.username}`; - } - } - }); - } - }, 10); -}; diff --git a/school/www/courses/course.html b/school/www/courses/course.html index 364fdeec..cff86929 100644 --- a/school/www/courses/course.html +++ b/school/www/courses/course.html @@ -43,9 +43,9 @@
- {% if not course.disable_self_learning and not membership and not course.upcoming %} + {% if not course.disable_self_learning and not membership and not course.upcoming and not restriction.restrict %}
- Start Learning + {{ _("Start Learning") }}
{% endif %} diff --git a/school/www/courses/course.py b/school/www/courses/course.py index 71e1708e..39a891bd 100644 --- a/school/www/courses/course.py +++ b/school/www/courses/course.py @@ -1,4 +1,5 @@ import frappe +from school.lms.doctype.lms_settings.lms_settings import check_profile_restriction def get_context(context): context.no_cache = 1 @@ -20,6 +21,7 @@ def get_context(context): context.membership = membership if context.course.upcoming: context.is_user_interested = get_user_interest(context.course.name) + context.restriction = check_profile_restriction() context.metatags = { "title": course.title, "image": course.image, diff --git a/school/www/courses/index.html b/school/www/courses/index.html index 78843b7e..237d6cea 100644 --- a/school/www/courses/index.html +++ b/school/www/courses/index.html @@ -9,9 +9,16 @@ {% block content %}
+ {% if restriction.restrict %} + {% set site_link = " profile " %} +
+
{{ _("You haven't completed your profile.") }}
+

{{ _("Complete your {0} to access the courses.").format(site_link) }}

+
+ + {% else %} {% include "school/templates/search_course/search_course.html" %} -
{% set title = _("Live Courses") %} {% set courses = live_courses %} @@ -23,6 +30,7 @@ {% set classes = "upcoming-courses mt-10" %} {% include "school/templates/course_list.html" %}
+ {% endif %}
{% endblock %} diff --git a/school/www/courses/index.py b/school/www/courses/index.py index f4981077..7c3a37a7 100644 --- a/school/www/courses/index.py +++ b/school/www/courses/index.py @@ -1,8 +1,10 @@ import frappe +from school.lms.doctype.lms_settings.lms_settings import check_profile_restriction def get_context(context): context.no_cache = 1 context.live_courses, context.upcoming_courses = get_courses() + context.restriction = check_profile_restriction() context.metatags = { "title": "All Courses", "image": frappe.db.get_single_value("Website Settings", "banner_image"), diff --git a/school/www/profiles/profile.html b/school/www/profiles/profile.html index 2f02ed04..a2751a8f 100644 --- a/school/www/profiles/profile.html +++ b/school/www/profiles/profile.html @@ -290,12 +290,16 @@
{{ edu.institution_name }}
{{ edu.degree_type }} {{ edu.major }} - {% if not member.hide_private %} + {% if not member.hide_private %} - {% if edu.grade %} {{ edu.grade }} {% endif %} + {% if edu.grade %} {{ edu.grade }} {% endif %} {% endif %}
-
{{ frappe.utils.format_date(edu.start_date, "MMM YYYY") }} - {{ frappe.utils.format_date(edu.end_date, "MMM YYYY") }}
+
+ {% if edu.start_date %} + {{ frappe.utils.format_date(edu.start_date, "MMM YYYY") }} - + {% endif %} + {{ frappe.utils.format_date(edu.end_date, "MMM YYYY") }}
{{ edu.location }}
{% endfor %}