feat: new-sign-up-form, request invite widget, request invite tests, get_sketches with owner
This commit is contained in:
@@ -136,6 +136,7 @@ primary_rules = [
|
|||||||
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
|
{"from_route": "/sketches/<sketch>", "to_route": "sketches/sketch"},
|
||||||
{"from_route": "/courses/<course>", "to_route": "courses/course"},
|
{"from_route": "/courses/<course>", "to_route": "courses/course"},
|
||||||
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
|
{"from_route": "/courses/<course>/<topic>", "to_route": "courses/topic"},
|
||||||
|
{"from_route": "/hackathons", "to_route": "hackathons"},
|
||||||
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
|
{"from_route": "/hackathons/<hackathon>", "to_route": "hackathons/hackathon"},
|
||||||
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
{"from_route": "/hackathons/<hackathon>/<project>", "to_route": "hackathons/project"},
|
||||||
{"from_route": "/dashboard", "to_route": ""},
|
{"from_route": "/dashboard", "to_route": ""},
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-05-01 13:59:27.624814",
|
"modified": "2021-05-03 09:22:20.954921",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "Invite Request",
|
"name": "Invite Request",
|
||||||
@@ -77,18 +77,6 @@
|
|||||||
"role": "System Manager",
|
"role": "System Manager",
|
||||||
"share": 1,
|
"share": 1,
|
||||||
"write": 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,
|
"quick_entry": 1,
|
||||||
|
|||||||
@@ -15,14 +15,15 @@ class InviteRequest(Document):
|
|||||||
self.send_email()
|
self.send_email()
|
||||||
|
|
||||||
def create_user(self, password):
|
def create_user(self, password):
|
||||||
|
full_name_split = self.full_name.split(" ")
|
||||||
user = frappe.get_doc({
|
user = frappe.get_doc({
|
||||||
"doctype": "User",
|
"doctype": "User",
|
||||||
"email": self.signup_email,
|
"email": self.signup_email,
|
||||||
"first_name": self.full_name.split(" ")[0],
|
"first_name": full_name_split[0],
|
||||||
"full_name": self.full_name,
|
"last_name": full_name_split[1] if len(full_name_split) > 1 else "",
|
||||||
"username": self.username,
|
"username": self.username,
|
||||||
"send_welcome_email": 0,
|
"send_welcome_email": 0,
|
||||||
"user_type": 'Website User',
|
"user_type": "Website User",
|
||||||
"new_password": password
|
"new_password": password
|
||||||
})
|
})
|
||||||
user.save(ignore_permissions=True)
|
user.save(ignore_permissions=True)
|
||||||
@@ -44,15 +45,19 @@ class InviteRequest(Document):
|
|||||||
args=args)
|
args=args)
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def create_invite_request(email):
|
def create_invite_request(invite_email):
|
||||||
frappe.get_doc({
|
try:
|
||||||
"doctype": "Invite Request",
|
frappe.get_doc({
|
||||||
"invite_email": email
|
"doctype": "Invite Request",
|
||||||
}).save(ignore_permissions=True)
|
"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)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def update_invite(data):
|
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:
|
try:
|
||||||
doc = frappe.get_doc("Invite Request", data.invite_code)
|
doc = frappe.get_doc("Invite Request", data.invite_code)
|
||||||
|
|||||||
@@ -2,9 +2,68 @@
|
|||||||
# Copyright (c) 2021, FOSS United and Contributors
|
# Copyright (c) 2021, FOSS United and Contributors
|
||||||
# See license.txt
|
# See license.txt
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from community.lms.doctype.invite_request.invite_request import create_invite_request, update_invite
|
||||||
# import frappe
|
import frappe
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestInviteRequest(unittest.TestCase):
|
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)
|
||||||
|
|||||||
@@ -52,11 +52,15 @@ class LMSSketch(Document):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_recent_sketches(limit=100):
|
def get_recent_sketches(limit=100, owner=None):
|
||||||
"""Returns the recent sketches.
|
"""Returns the recent sketches.
|
||||||
"""
|
"""
|
||||||
|
filters = {}
|
||||||
|
if owner:
|
||||||
|
filters = {"owner": owner}
|
||||||
sketches = frappe.get_all(
|
sketches = frappe.get_all(
|
||||||
"LMS Sketch",
|
"LMS Sketch",
|
||||||
|
filters=filters,
|
||||||
fields='*',
|
fields='*',
|
||||||
order_by='modified desc',
|
order_by='modified desc',
|
||||||
page_length=limit
|
page_length=limit
|
||||||
|
|||||||
4
community/lms/widgets/RequestInvite.html
Normal file
4
community/lms/widgets/RequestInvite.html
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<form id="invite-request-form">
|
||||||
|
<input class="form-control field-width mr-5" id="invite_email" type="email" placeholder="Email Address">
|
||||||
|
<a type="submit" id="submit" class="btn btn-primary btn-lg" href="#" role="button">Request Invite</a>
|
||||||
|
</form>
|
||||||
@@ -66,3 +66,8 @@ section.lightgray {
|
|||||||
#hero .jumbotron {
|
#hero .jumbotron {
|
||||||
background: inherit;
|
background: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-width {
|
||||||
|
width: 40%;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@
|
|||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1 class="display-4">Guided online courses, with a mentor at your back.</h1>
|
<h1 class="display-4">Guided online courses, with a mentor at your back.</h1>
|
||||||
<p class="lead">Hands-on online courses designed by experts, delivered by passionate mentors.</p>
|
<p class="lead">Hands-on online courses designed by experts, delivered by passionate mentors.</p>
|
||||||
<p class="lead">
|
{{ widgets.RequestInvite() }}
|
||||||
<a class="btn btn-primary btn-lg" href="#" role="button">Request Invite</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
19
community/www/home/index.js
Normal file
19
community/www/home/index.js
Normal file
@@ -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 = `<div>
|
||||||
|
<p class="lead">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p>
|
||||||
|
</div>`;
|
||||||
|
$(".jumbotron").append(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -4,24 +4,29 @@
|
|||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
|
|
||||||
<form id="reset-password">
|
<form id="new-sign-up">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="full_name" type="text" class="form-control" placeholder="{{ _('Full Name') }}" required>
|
<label for="full_name">Full Name:</label>
|
||||||
|
<input id="full_name" type="text" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="signup_email" type="email" class="form-control" placeholder="{{ _('Email') }}" required>
|
<label for="signup_email">Email:</label>
|
||||||
|
<input id="signup_email" type="email" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="username" type="text" class="form-control" placeholder="{{ _('Username') }}" required>
|
<label for="username">Username:</label>
|
||||||
|
<input id="username" type="text" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="password" type="password" class="form-control" placeholder="{{ _('Password') }}" required>
|
<label for="password">Password:</label>
|
||||||
|
<input id="password" type="password" class="form-control" required>
|
||||||
<span class="password-strength-indicator indicator"></span>
|
<span class="password-strength-indicator indicator"></span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<p class='password-strength-message text-muted small hidden'></p>
|
<p class='password-strength-message text-muted small hidden'></p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="invite_code" type="text" class="form-control" placeholder="{{ _('Invite Code') }}" readonly required
|
<label for="invite_code">Invite Code:</label>
|
||||||
|
<input id="invite_code" type="text" class="form-control" readonly required
|
||||||
value="{{ frappe.form_dict['invite_code'] }}">
|
value="{{ frappe.form_dict['invite_code'] }}">
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" id="submit" class="btn btn-primary">{{_("Submit")}}</button>
|
<button type="submit" id="submit" class="btn btn-primary">{{_("Submit")}}</button>
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ from community.lms.models import Sketch
|
|||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
context.username = frappe.form_dict["username"]
|
context.username = frappe.form_dict["username"]
|
||||||
print(frappe.form_dict["username"])
|
|
||||||
context.member = get_member(context.username)
|
context.member = get_member(context.username)
|
||||||
print(context.member)
|
|
||||||
if not context.member:
|
if not context.member:
|
||||||
context.template = "www/404.html"
|
context.template = "www/404.html"
|
||||||
else:
|
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):
|
def get_member(username):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user