From 565787eeb6a8a4c44297a702c11ab573a41cdb2f Mon Sep 17 00:00:00 2001 From: pateljannat Date: Mon, 3 May 2021 12:33:31 +0530 Subject: [PATCH] feat: new-sign-up-form, request invite widget, request invite tests, get_sketches with owner --- community/hooks.py | 1 + .../invite_request/invite_request.json | 14 +--- .../doctype/invite_request/invite_request.py | 23 ++++--- .../invite_request/test_invite_request.py | 65 ++++++++++++++++++- .../lms/doctype/lms_sketch/lms_sketch.py | 6 +- community/lms/widgets/RequestInvite.html | 4 ++ community/public/css/style.less | 5 ++ community/www/home/index.html | 4 +- community/www/home/index.js | 19 ++++++ community/www/new-sign-up.html | 17 +++-- community/www/profiles/profile.py | 4 +- 11 files changed, 124 insertions(+), 38 deletions(-) create mode 100644 community/lms/widgets/RequestInvite.html create mode 100644 community/www/home/index.js diff --git a/community/hooks.py b/community/hooks.py index eec63a4f..6b1fb371 100644 --- a/community/hooks.py +++ b/community/hooks.py @@ -136,6 +136,7 @@ primary_rules = [ {"from_route": "/sketches/", "to_route": "sketches/sketch"}, {"from_route": "/courses/", "to_route": "courses/course"}, {"from_route": "/courses//", "to_route": "courses/topic"}, + {"from_route": "/hackathons", "to_route": "hackathons"}, {"from_route": "/hackathons/", "to_route": "hackathons/hackathon"}, {"from_route": "/hackathons//", "to_route": "hackathons/project"}, {"from_route": "/dashboard", "to_route": ""}, diff --git a/community/lms/doctype/invite_request/invite_request.json b/community/lms/doctype/invite_request/invite_request.json index 426f53e0..636c44b8 100644 --- a/community/lms/doctype/invite_request/invite_request.json +++ b/community/lms/doctype/invite_request/invite_request.json @@ -60,7 +60,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2021-05-01 13:59:27.624814", + "modified": "2021-05-03 09:22:20.954921", "modified_by": "Administrator", "module": "LMS", "name": "Invite Request", @@ -77,18 +77,6 @@ "role": "System Manager", "share": 1, "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Guest", - "share": 1, - "write": 1 } ], "quick_entry": 1, diff --git a/community/lms/doctype/invite_request/invite_request.py b/community/lms/doctype/invite_request/invite_request.py index 39ca37c7..922ec89b 100644 --- a/community/lms/doctype/invite_request/invite_request.py +++ b/community/lms/doctype/invite_request/invite_request.py @@ -15,14 +15,15 @@ class InviteRequest(Document): self.send_email() def create_user(self, password): + full_name_split = self.full_name.split(" ") user = frappe.get_doc({ "doctype": "User", "email": self.signup_email, - "first_name": self.full_name.split(" ")[0], - "full_name": self.full_name, + "first_name": full_name_split[0], + "last_name": full_name_split[1] if len(full_name_split) > 1 else "", "username": self.username, "send_welcome_email": 0, - "user_type": 'Website User', + "user_type": "Website User", "new_password": password }) user.save(ignore_permissions=True) @@ -44,15 +45,19 @@ class InviteRequest(Document): args=args) @frappe.whitelist(allow_guest=True) -def create_invite_request(email): - frappe.get_doc({ - "doctype": "Invite Request", - "invite_email": email - }).save(ignore_permissions=True) +def create_invite_request(invite_email): + try: + frappe.get_doc({ + "doctype": "Invite Request", + "invite_email": invite_email + }).save(ignore_permissions=True) + return "OK" + except frappe.UniqueValidationError: + frappe.throw(_("Email {0} has already been used to request an invite").format(invite_email)) @frappe.whitelist(allow_guest=True) def update_invite(data): - data = frappe._dict(json.loads(data)) + data = frappe._dict(json.loads(data)) if type(data) == str else frappe._dict(data) try: doc = frappe.get_doc("Invite Request", data.invite_code) diff --git a/community/lms/doctype/invite_request/test_invite_request.py b/community/lms/doctype/invite_request/test_invite_request.py index 557d95e9..eedfe2a8 100644 --- a/community/lms/doctype/invite_request/test_invite_request.py +++ b/community/lms/doctype/invite_request/test_invite_request.py @@ -2,9 +2,68 @@ # Copyright (c) 2021, FOSS United and Contributors # See license.txt from __future__ import unicode_literals - -# import frappe +from community.lms.doctype.invite_request.invite_request import create_invite_request, update_invite +import frappe import unittest class TestInviteRequest(unittest.TestCase): - pass + + @classmethod + def setUpClass(self): + create_invite_request("test_invite@example.com") + + def test_create_invite_request(self): + if frappe.db.exists("Invite Request", {"invite_email": "test_invite@example.com"}): + invite = frappe.db.get_value("Invite Request", + filters={"invite_email": "test_invite@example.com"}, + fieldname=["invite_email", "status", "signup_email"], + as_dict=True) + self.assertEqual(invite.status, "Pending") + self.assertEqual(invite.signup_email, None) + + def test_create_invite_request_update(self): + if frappe.db.exists("Invite Request", {"invite_email": "test_invite@example.com"}): + + data = { + "signup_email": "test_invite@example.com", + "username": "test_invite", + "full_name": "Test Invite", + "password": "Test@invite", + "invite_code": frappe.db.get_value("Invite Request", {"invite_email": "test_invite@example.com"}, "name") + } + + update_invite(data) + invite = frappe.db.get_value("Invite Request", + filters={"invite_email": "test_invite@example.com"}, + fieldname=["invite_email", "status", "signup_email", "full_name", "username", "invite_code", "name"], + as_dict=True) + self.assertEqual(invite.signup_email, "test_invite@example.com") + self.assertEqual(invite.full_name, "Test Invite") + self.assertEqual(invite.username, "test_invite") + self.assertEqual(invite.invite_code, invite.name) + self.assertEqual(invite.status, "Registered") + + user = frappe.db.get_value("User", "test_invite@example.com", + fieldname=["first_name", "username", "send_welcome_email", "user_type"], + as_dict=True) + self.assertTrue(user) + self.assertEqual(user.first_name, invite.full_name.split(" ")[0]) + self.assertEqual(user.username, invite.username) + self.assertEqual(user.send_welcome_email, 0) + self.assertEqual(user.user_type, "Website User") + + member = frappe.db.get_value("Community Member", {"email": "test_invite@example.com"}) + self.assertTrue(member) + + @classmethod + def tearDownClass(self): + + if frappe.db.exists("Community Member", {"email": "test_invite@example.com"}): + frappe.delete_doc("Community Member", {"email": "test_invite@example.com"}) + + if frappe.db.exists("User", "test_invite@example.com"): + frappe.delete_doc("User", "test_invite@example.com") + + invite_request = frappe.db.exists("Invite Request", {"invite_email": "test_invite@example.com"}) + if invite_request: + frappe.delete_doc("Invite Request", invite_request) diff --git a/community/lms/doctype/lms_sketch/lms_sketch.py b/community/lms/doctype/lms_sketch/lms_sketch.py index e26ff490..5c665305 100644 --- a/community/lms/doctype/lms_sketch/lms_sketch.py +++ b/community/lms/doctype/lms_sketch/lms_sketch.py @@ -52,11 +52,15 @@ class LMSSketch(Document): return value @staticmethod - def get_recent_sketches(limit=100): + def get_recent_sketches(limit=100, owner=None): """Returns the recent sketches. """ + filters = {} + if owner: + filters = {"owner": owner} sketches = frappe.get_all( "LMS Sketch", + filters=filters, fields='*', order_by='modified desc', page_length=limit diff --git a/community/lms/widgets/RequestInvite.html b/community/lms/widgets/RequestInvite.html new file mode 100644 index 00000000..2c17a465 --- /dev/null +++ b/community/lms/widgets/RequestInvite.html @@ -0,0 +1,4 @@ +
+ + Request Invite +
\ No newline at end of file diff --git a/community/public/css/style.less b/community/public/css/style.less index a138e984..ea328dc5 100644 --- a/community/public/css/style.less +++ b/community/public/css/style.less @@ -66,3 +66,8 @@ section.lightgray { #hero .jumbotron { background: inherit; } + +.field-width { + width: 40%; + display: inline-block; +} diff --git a/community/www/home/index.html b/community/www/home/index.html index c087d76e..ec42209a 100644 --- a/community/www/home/index.html +++ b/community/www/home/index.html @@ -12,9 +12,7 @@

Guided online courses, with a mentor at your back.

Hands-on online courses designed by experts, delivered by passionate mentors.

-

- Request Invite -

+ {{ widgets.RequestInvite() }}
diff --git a/community/www/home/index.js b/community/www/home/index.js new file mode 100644 index 00000000..9eb0aefd --- /dev/null +++ b/community/www/home/index.js @@ -0,0 +1,19 @@ +frappe.ready(() => { + $("#submit").click(function () { + frappe.call({ + method: "community.lms.doctype.invite_request.invite_request.create_invite_request", + args: { + invite_email: $("#invite_email").val() + }, + callback: (data) => { + if (data.message == "OK") { + $("#invite-request-form").hide(); + var message = `
+

Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.

+
`; + $(".jumbotron").append(message); + } + } + }) + }) +}) \ No newline at end of file diff --git a/community/www/new-sign-up.html b/community/www/new-sign-up.html index 51247f4a..05a6c3d8 100644 --- a/community/www/new-sign-up.html +++ b/community/www/new-sign-up.html @@ -4,24 +4,29 @@ {% block page_content %} -
+
- + +
- + +
- + +
- + +
- Invite Code: +
diff --git a/community/www/profiles/profile.py b/community/www/profiles/profile.py index 30c5b2a5..9fb6b74b 100644 --- a/community/www/profiles/profile.py +++ b/community/www/profiles/profile.py @@ -4,13 +4,11 @@ from community.lms.models import Sketch def get_context(context): context.no_cache = 1 context.username = frappe.form_dict["username"] - print(frappe.form_dict["username"]) context.member = get_member(context.username) - print(context.member) if not context.member: context.template = "www/404.html" else: - context.sketches = list(filter(lambda x: x.owner == context.member.email, Sketch.get_recent_sketches())) + context.sketches = Sketch.get_recent_sketches(context.member.email) def get_member(username): try: