Compare commits

..

1 Commits

Author SHA1 Message Date
Anand Chitipothu
5feeb4ca0c feat: widgets interface
Widgets are reusable jinja templates which can be used in other
themplates. Widgets are written in widgets/ directory in every frappe
module and can be accessed as `{{ widgets.WidgetName(...) }}` from any
template.
2021-04-29 10:37:36 +05:30
28 changed files with 163 additions and 498 deletions

View File

@@ -9,51 +9,7 @@ The App has following components:
Community is built on the [Frappe Framework](https://github.com/frappe/frappe), a full-stack web app framework built with Python & JavaScript. Community is built on the [Frappe Framework](https://github.com/frappe/frappe), a full-stack web app framework built with Python & JavaScript.
## Development Setup ### Local Setup
**Step 1:** Clone the repo
```
$ git clone https://github.com/fossunited/community.git
$ cd community
```
**Step 2:** Run docker-compose
```
$ docker-compose up
```
**Step 3:** Visit the website at http://localhost:8000/
You'll have to go through the setup wizard to setup the website for the first time you access it. Login using the following credentiasl to complete the setup wizard.
```
Username: Administrator
password: admin
```
TODO: Explain how to load sample data
## Stopping the server
Press `ctrl+c` in the terminal to stop the server. You can also run `docker-compose down` in another terminal to stop it.
To completely reset the instance, do the following:
```
$ docker-compose down --volumes
$ docker-compose up
```
## Making Code Changes
The dev setup is configured to reload whenever any code is changed. Just edit the code and reload the webpage.
Commit the changes in a branch and send a pull request.
## Local Setup - The Hard Way
To setup the repository locally follow the steps mentioned below: To setup the repository locally follow the steps mentioned below:
@@ -65,7 +21,7 @@ To setup the repository locally follow the steps mentioned below:
1. Map your site to localhost with the command ```bench --site community.test add-to-hosts``` 1. Map your site to localhost with the command ```bench --site community.test add-to-hosts```
1. Now open the URL http://community.test:8000/docs in your browser, you should see the app running. 1. Now open the URL http://community.test:8000/docs in your browser, you should see the app running.
### Contribution Guidelines (for The Hard Way) ### Contribution Guidelines
1. Go to the apps/community directory of your installation and execute git pull --unshallow to ensure that you have the full git repository. Also fork the fossunited/community repository on GitHub. 1. Go to the apps/community directory of your installation and execute git pull --unshallow to ensure that you have the full git repository. Also fork the fossunited/community repository on GitHub.
1. Check out a working branch in git (e.g. git checkout -b my-new-branch). 1. Check out a working branch in git (e.g. git checkout -b my-new-branch).
@@ -76,4 +32,4 @@ To setup the repository locally follow the steps mentioned below:
#### License #### License
AGPL AGPL

View File

@@ -11,15 +11,15 @@
"email", "email",
"enabled", "enabled",
"column_break_4", "column_break_4",
"username", "role",
"email_preference", "short_intro",
"section_break_7", "section_break_7",
"bio", "bio",
"section_break_9", "section_break_9",
"role", "username",
"photo", "photo",
"column_break_12", "column_break_12",
"short_intro", "email_preference",
"route", "route",
"abbr" "abbr"
], ],
@@ -77,10 +77,8 @@
"unique": 1 "unique": 1
}, },
{ {
"allow_in_quick_entry": 1,
"fieldname": "username", "fieldname": "username",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1,
"label": "User Name", "label": "User Name",
"unique": 1 "unique": 1
}, },
@@ -113,9 +111,10 @@
"read_only": 1 "read_only": 1
} }
], ],
"has_web_view": 1,
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-04-28 11:22:35.402217", "modified": "2021-04-16 10:22:46.837311",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Community", "module": "Community",
"name": "Community Member", "name": "Community Member",

View File

@@ -4,12 +4,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.website.website_generator import WebsiteGenerator
import re import re
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.rename_doc import rename_doc
import random
class CommunityMember(Document): class CommunityMember(WebsiteGenerator):
def validate(self): def validate(self):
self.validate_username() self.validate_username()
@@ -18,9 +18,6 @@ class CommunityMember(Document):
self.route = self.username self.route = self.username
def validate_username(self): def validate_username(self):
if not self.username:
self.username = create_username_from_email(self.email)
if self.username: if self.username:
if len(self.username) < 4: if len(self.username) < 4:
frappe.throw(_("Username must be atleast 4 characters long.")) frappe.throw(_("Username must be atleast 4 characters long."))
@@ -32,33 +29,12 @@ class CommunityMember(Document):
return f"<CommunityMember: {self.email}>" return f"<CommunityMember: {self.email}>"
def create_member_from_user(doc, method): def create_member_from_user(doc, method):
username = doc.username
if ( doc.username and username_exists(doc.username)) or not doc.username:
username = create_username_from_email(doc.email)
elif len(doc.username) < 4:
username = adjust_username(doc.username)
if username_exists(username):
username = username + str(random.randint(0,9))
member = frappe.get_doc({ member = frappe.get_doc({
"doctype": "Community Member", "doctype": "Community Member",
"full_name": doc.full_name, "full_name": doc.full_name,
"username": username, "username": doc.username if len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ]),
"email": doc.email, "email": doc.email,
"route": doc.username, "route": doc.username,
"owner": doc.email "owner": doc.email
}) })
member.save(ignore_permissions=True) member.save(ignore_permissions=True)
def username_exists(username):
return frappe.db.exists("Community Member", dict(username=username))
def create_username_from_email(email):
string = email.split("@")[0]
return ''.join(e for e in string if e.isalnum())
def adjust_username(username):
return username.ljust(4, str(random.randint(0,9)))

View File

@@ -2,91 +2,9 @@
# Copyright (c) 2021, Frappe and Contributors # Copyright (c) 2021, Frappe and Contributors
# See license.txt # See license.txt
from __future__ import unicode_literals from __future__ import unicode_literals
from community.lms.doctype.lms_course.test_lms_course import new_user
import frappe # import frappe
import unittest import unittest
class TestCommunityMember(unittest.TestCase): class TestCommunityMember(unittest.TestCase):
pass
@classmethod
def setUpClass(self):
users = ["test_user@example.com","test_user1@example.com"]
for user in users:
if not frappe.db.exists("User", user):
new_user("Test User", user)
def test_member_created_from_user(self):
user = frappe.db.get_value("User","test_user@example.com", ["full_name", "email", "username"], as_dict=True)
self.assertTrue(frappe.db.exists("Community Member", {"username":user.username}))
member = frappe.db.get_value("Community Member",
filters={"email": user.email},
fieldname=["full_name", "email", "owner", "username", "route"],
as_dict=True
)
self.assertEqual(user.full_name, member.full_name)
self.assertEqual(member.owner, user.email)
self.assertEqual(user.username, member.username)
self.assertEqual(member.username, member.route)
def test_members_with_same_name(self):
user1 = frappe.db.get_value("User","test_user@example.com", ["email"], as_dict=True)
user2 = frappe.get_doc("User","test_user1@example.com", ["email"], as_dict=True)
self.assertTrue(frappe.db.exists("Community Member", {"email": user1.email} ))
self.assertTrue(frappe.db.exists("Community Member", {"email": user2.email }))
member1 = frappe.db.get_value("Community Member",
filters={"email": user1.email},
fieldname=["full_name", "email", "owner", "username", "route"],
as_dict=True
)
member2 = frappe.db.get_value("Community Member",
filters={"email": user2.email},
fieldname=["full_name", "email", "owner", "username", "route"],
as_dict=True
)
self.assertEqual(member1.full_name, member2.full_name)
self.assertEqual(member1.email, user1.email)
self.assertEqual(member2.email, user2.email)
self.assertNotEqual(member1.username, member2.username)
def test_username_validations(self):
user = new_user("Tst", "tst@example.com")
self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} ))
member = frappe.db.get_value("Community Member",
filters={"email": user.email},
fieldname=["username"],
as_dict=True
)
self.assertEqual(len(member.username), 4)
frappe.delete_doc("User", user.email)
def test_user_without_username(self):
user = new_user("Test User", "test_user2@example.com")
self.assertTrue(frappe.db.exists("Community Member", {"email":user.email} ))
member = frappe.db.get_value("Community Member",
filters={"email": user.email},
fieldname=["username"],
as_dict=True
)
self.assertTrue(member.username)
frappe.delete_doc("User", user.email)
@classmethod
def tearDownClass(self):
users = ["test_user@example.com","test_user1@example.com"]
for user in users:
if frappe.db.exists("User", user):
frappe.delete_doc("User", user)
if frappe.db.exists("Community Member", {"email": user}):
frappe.delete_doc("Community Member", {"email": user})

View File

@@ -7,6 +7,7 @@ def create_members_from_users():
doc = frappe.get_doc("User", {"email": user.email}) doc = frappe.get_doc("User", {"email": user.email})
username = doc.username if doc.username and len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ]) username = doc.username if doc.username and len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ])
if not frappe.db.exists("Community Member", username): if not frappe.db.exists("Community Member", username):
print(doc.email, username)
member = frappe.new_doc("Community Member") member = frappe.new_doc("Community Member")
member.full_name = doc.full_name member.full_name = doc.full_name
member.username = username member.username = username

View File

@@ -94,10 +94,7 @@ web_include_css = "/assets/css/community.css"
doc_events = { doc_events = {
"User": { "User": {
"after_insert": "community.community.doctype.community_member.community_member.create_member_from_user" "after_insert": "community.community.doctype.community_member.community_member.create_member_from_user"
}, }
"LMS Message": {
"after_insert": "community.lms.doctype.lms_message.lms_message.publish_message"
}
} }
# Scheduled Tasks # Scheduled Tasks
@@ -150,7 +147,6 @@ primary_rules = [
# Any frappe default URL is blocked by profile-rules, add it here to unblock it # Any frappe default URL is blocked by profile-rules, add it here to unblock it
whitelist = [ whitelist = [
"/home",
"/login", "/login",
"/update-password", "/update-password",
"/update-profile", "/update-profile",

View File

@@ -36,4 +36,5 @@ def save_message(message, batch):
"author": get_member_with_email(), "author": get_member_with_email(),
"message": message "message": message
}) })
doc.save(ignore_permissions=True) doc.save(ignore_permissions=True)
return doc

View File

@@ -88,15 +88,3 @@ class LMSCourse(Document):
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"})) member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
course_mentors.append(member) course_mentors.append(member)
return course_mentors return course_mentors
def get_instructor(self):
return frappe.get_doc("User", self.owner)
@staticmethod
def find_all():
"""Returns all published courses.
"""
rows = frappe.db.get_all("LMS Course",
filters={"is_published": True},
fields='*')
return [frappe.get_doc(dict(row, doctype='LMS Course')) for row in rows]

View File

@@ -4,7 +4,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from .lms_course import LMSCourse
import unittest import unittest
class TestLMSCourse(unittest.TestCase): class TestLMSCourse(unittest.TestCase):
@@ -12,6 +11,7 @@ class TestLMSCourse(unittest.TestCase):
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`') frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
frappe.db.sql('delete from `tabLMS Course`') frappe.db.sql('delete from `tabLMS Course`')
frappe.db.sql('delete from `tabCommunity Member`') frappe.db.sql('delete from `tabCommunity Member`')
frappe.db.sql('delete from `tabUser` where email like "%@example.com"')
def new_course(self, title): def new_course(self, title):
doc = frappe.get_doc({ doc = frappe.get_doc({
@@ -21,48 +21,28 @@ class TestLMSCourse(unittest.TestCase):
doc.insert() doc.insert()
return doc return doc
def new_user(self, name, email):
doc = frappe.get_doc(dict(
doctype='User',
email=email,
first_name=name))
doc.insert()
return doc
def test_new_course(self): def test_new_course(self):
course = self.new_course("Test Course") course = self.new_course("Test Course")
assert course.title == "Test Course" assert course.title == "Test Course"
assert course.slug == "test-course" assert course.slug == "test-course"
assert course.get_mentors() == [] assert course.get_mentors() == []
def test_find_all(self):
courses = LMSCourse.find_all()
assert courses == []
# new couse, but not published
course = self.new_course("Test Course")
assert courses == []
# publish the course
course.is_published = True
course.save()
# now we should find one course
courses = LMSCourse.find_all()
assert [c.slug for c in courses] == [course.slug]
# disabled this test as it is failing # disabled this test as it is failing
def _test_add_mentors(self): def _test_add_mentors(self):
course = self.new_course("Test Course") course = self.new_course("Test Course")
assert course.get_mentors() == [] assert course.get_mentors() == []
user = new_user("Tester", "tester@example.com") user = self.new_user("Tester", "tester@example.com")
course.add_mentor("tester@example.com") course.add_mentor("tester@example.com")
mentors = course.get_mentors() mentors = course.get_mentors()
mentors_data = [dict(email=mentor.email, batch_count=mentor.batch_count) for mentor in mentors] mentors_data = [dict(email=mentor.email, batch_count=mentor.batch_count) for mentor in mentors]
assert mentors_data == [{"email": "tester@example.com", "batch_count": 0}] assert mentors_data == [{"email": "tester@example.com", "batch_count": 0}]
def tearDown(self):
if frappe.db.exists("User", "tester@example.com"):
frappe.delete_doc("User", "tester@example.com")
def new_user(name, email):
doc = frappe.get_doc(dict(
doctype='User',
email=email,
first_name=name))
doc.insert()
return doc

View File

@@ -58,7 +58,7 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2021-04-28 10:17:57.618127", "modified": "2021-04-26 16:11:20.142164",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Message", "name": "LMS Message",
@@ -80,6 +80,5 @@
"quick_entry": 1, "quick_entry": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"title_field": "author",
"track_changes": 1 "track_changes": 1
} }

View File

@@ -7,12 +7,11 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
from frappe import _ from frappe import _
from frappe.utils import add_days, nowdate from frappe.utils import add_days, nowdate
from community.www.courses.utils import get_batch_members
class LMSMessage(Document): class LMSMessage(Document):
""" def after_insert(self): def after_insert(self):
self.send_email() """ frappe.publish_realtime("new_lms_message", {"message":"JJannat"}, user="Administrator")
self.send_email()
def send_email(self): def send_email(self):
membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"]) membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"])
for entry in membership: for entry in membership:
@@ -61,44 +60,4 @@ def send_daily_digest():
"batches": group_by_batch "batches": group_by_batch
}, },
delayed = False delayed = False
) )
def publish_message(doc, method):
email = frappe.db.get_value("Community Member", doc.author, "email")
template = get_message_template()
message = frappe._dict()
message.author_name = doc.author_name
message.message_time = frappe.utils.pretty_date(doc.creation)
message.message = frappe.utils.md_to_html(doc.message)
js = """
$(".msger-input").val("");
var template = `{0}`;
var message = {1};
var session_user = ("{2}" == frappe.session.user) ? true : false;
message.author_name = session_user ? "You" : message.author_name
message.is_author = session_user;
template = frappe.render_template(template, {{
"message": message
}})
$(".message-section").append(template);
""".format(template, message, email)
frappe.publish_realtime(event="eval_js", message=js, after_commit=True)
def get_message_template():
return """
<div class="discussion {% if message.is_author %} is-author {% endif %}">
<div class="d-flex justify-content-between">
<div class="font-weight-bold">
{{ message.author_name }}
</div>
<div class="text-muted">
{{ message.message_time }}
</div>
</div>
<div class="mt-5">
{{ message.message }}
</div>
</div>
"""

View File

@@ -10,6 +10,9 @@ from frappe.model.document import Document
from . import livecode from . import livecode
class LMSSketch(Document): class LMSSketch(Document):
def get_owner_name(self):
return get_userinfo(self.owner)['full_name']
@property @property
def sketch_id(self): def sketch_id(self):
"""Returns the numeric part of the name. """Returns the numeric part of the name.
@@ -18,14 +21,6 @@ class LMSSketch(Document):
""" """
return self.name.replace("SKETCH-", "") return self.name.replace("SKETCH-", "")
def get_owner(self):
"""Returns the owner of this sketch as a document.
"""
return frappe.get_doc("User", self.owner)
def get_owner_name(self):
return self.get_owner().full_name
def get_livecode_url(self): def get_livecode_url(self):
doc = frappe.get_cached_doc("LMS Settings") doc = frappe.get_cached_doc("LMS Settings")
return doc.livecode_url return doc.livecode_url
@@ -51,18 +46,6 @@ class LMSSketch(Document):
cache.set(key, value) cache.set(key, value)
return value return value
@staticmethod
def get_recent_sketches(limit=100):
"""Returns the recent sketches.
"""
sketches = frappe.get_all(
"LMS Sketch",
fields='*',
order_by='modified desc',
page_length=limit
)
return [frappe.get_doc(doctype='LMS Sketch', **doc) for doc in sketches]
def __repr__(self): def __repr__(self):
return f"<LMSSketch {self.name}>" return f"<LMSSketch {self.name}>"
@@ -93,3 +76,36 @@ def save_sketch(name, title, code):
"status": status, "status": status,
"name": doc.name, "name": doc.name,
} }
def get_recent_sketches():
"""Returns the recent sketches.
The return value will be a list of dicts with each entry containing
the following fields:
- name
- title
- owner
- owner_name
- modified
"""
sketches = frappe.get_all(
"LMS Sketch",
fields='*',
order_by='modified desc',
page_length=100
)
for s in sketches:
s['owner_name'] = get_userinfo(s['owner'])['full_name']
return [frappe.get_doc(doctype='LMS Sketch', **doc) for doc in sketches]
def get_userinfo(email):
"""Returns the username and fullname of a user.
Please note that the email could be "Administrator" or "Guest"
as a special case to denote the system admin and guest user respectively.
"""
user = frappe.get_doc("User", email)
return {
"full_name": user.full_name,
"username": user.username
}

View File

@@ -1,5 +0,0 @@
"""Handy module to make access to all doctypes from a single place.
"""
from .doctype.lms_course.lms_course import LMSCourse as Course
from .doctype.lms_sketch.lms_sketch import LMSSketch as Sketch

View File

@@ -1,13 +0,0 @@
<div class="course-teaser">
<div class="course-body">
<h3 class="course-title"><a href="/courses/{{ course.slug }}">{{ course.title }}</a></h3>
<div class="course-intro">
{{ course.short_introduction or "" }}
</div>
</div>
<div class="course-footer">
<div class="course-author">
{{ course.get_instructor().full_name }}
</div>
</div>
</div>

View File

@@ -1,15 +0,0 @@
<div class="sketch-teaser">
<div class="sketch-image">
<a href="/sketches/{{sketch.sketch_id}}">
{{ sketch.to_svg() }}
</a>
</div>
<div class="sketch-footer">
<div class="sketch-title">
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
</div>
<div class="sketch-author">
by {{sketch.get_owner().full_name}}
</div>
</div>
</div>

View File

@@ -3,8 +3,6 @@
"public/css/lms.css" "public/css/lms.css"
], ],
"css/community.css": [ "css/community.css": [
"public/css/vars.css", "public/css/style.css"
"public/css/style.css",
"public/css/style.less"
] ]
} }

View File

@@ -25,14 +25,12 @@
--cta-color: var(--c4); --cta-color: var(--c4);
--send-message: var(--c7); --send-message: var(--c7);
--received-message: var(--c8); --received-message: var(--c8);
--primary-color: #08B74F;
} }
body { body {
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
background: white; background: var(--bg);
} }
.course-header { .course-header {
@@ -202,6 +200,10 @@ img.profile-photo {
/* override style of base */ /* override style of base */
nav.navbar {
background: var(--c1) !important;
}
.message { .message {
border: 1px dashed var(--text-color); border: 1px dashed var(--text-color);
padding: 20px; padding: 20px;
@@ -288,5 +290,4 @@ img.profile-photo {
.message-section { .message-section {
margin-left: 5%; margin-left: 5%;
display: inline-block; }
}

View File

@@ -1,68 +0,0 @@
@primary-color: #08B74F;
.teaser {
background: white;
border-radius: 10px;
border: 1px solid #ddd;
}
.sketch-teaser {
.teaser();
width: 220px;
svg {
width: 200px;
height: 200px;
}
.sketch-image {
padding: 10px;
}
.sketch-footer {
padding: 10px;
background: #eee;
border-radius: 0px 0px 10px 10px;
}
}
.course-teaser {
.teaser();
color: #444;
h3, h4 {
color: black;
font-weight: bold;
}
.course-body, .course-footer {
padding: 20px;
}
.course-body {
min-height: 8em;
}
.course-footer {
border-top: 1px solid #ddd;
}
a, a:hover {
color: inherit;
text-decoration: none;
}
}
section {
padding: 60px 0px;
}
section h2 {
margin-bottom: 40px;
}
section.lightgray {
background: #f8f8f8;
}
#hero .jumbotron {
background: inherit;
}

View File

@@ -1,4 +0,0 @@
/* Define all your css variables here. */
:root {
--primary-color: #08B74F;
}

View File

@@ -1,4 +1,15 @@
frappe.ready(() => { frappe.ready(() => {
frappe.require("/assets/frappe/js/lib/socket.io.min.js");
frappe.require("/assets/frappe/js/frappe/socketio_client.js");
if (window.dev_server) {
frappe.boot.socketio_port = "9000" //use socketio port shown when bench starts
}
frappe.socketio.init();
console.log(frappe.socketio)
//frappe.socketio.emittedDemo("mydata");
frappe.realtime.on("new_lms_message", (data) => {
console.log(data)
})
if (frappe.session.user != "Guest") { if (frappe.session.user != "Guest") {
frappe.call({ frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested', 'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
@@ -14,6 +25,21 @@ frappe.ready(() => {
}) })
} }
$(".list-batch").click((e) => {
var batch = decodeURIComponent($(e.currentTarget).attr("data-label"))
$(".current-batch").text(batch)
$(".send-message").attr("data-batch", batch)
frappe.call("community.www.courses.course.get_messages", { batch: batch }, (data) => {
if (data.message) {
$(".discussions").children().remove();
for (var i = 0; i < data.message.length; i++) {
var element = add_message(data.message[i])
$(".discussions").append(element);
}
}
})
})
$(".apply-now").click((e) => { $(".apply-now").click((e) => {
if (frappe.session.user == "Guest") { if (frappe.session.user == "Guest") {
window.location.href = "/login"; window.location.href = "/login";
@@ -68,4 +94,19 @@ frappe.ready(() => {
}) })
}) })
}) })
/*
var show_enrollment_badge = () => {
$(".btn-enroll").addClass("hide");
$(".enrollment-badge").removeClass("hide");
}
var get_search_params = () => {
return new URLSearchParams(window.location.search)
}
$('.btn-enroll').on('click', (e) => {
frappe.call('community.www.courses.course.enroll', { course: get_search_params().get("course") }, (data) => {
show_enrollment_badge()
});
}); */

View File

@@ -35,6 +35,7 @@
<div class="mt-5"> <div class="mt-5">
{{ message.message }} {{ message.message }}
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}

View File

@@ -1,18 +1,22 @@
frappe.ready(() => { frappe.ready(() => {
const assets = [ const assets = [
"/assets/frappe/js/lib/socket.io.min.js", "/assets/frappe/js/lib/socket.io.min.js",
"/assets/frappe/js/frappe/socketio_client.js", "/assets/frappe/js/frappe/socketio_client.js"
] ]
frappe.require(assets, () => { frappe.require(assets, () => {
if (window.dev_server) { if (window.dev_server) {
frappe.boot.socketio_port = "9000" //use socketio port shown when bench starts frappe.boot.socketio_port = "9000" //use socketio port shown when bench starts
} }
frappe.socketio.init(9000); frappe.socketio.init(9000);
console.log(frappe.socketio)
})
frappe.realtime.on("new_lms_message", (data) => {
console.log(data)
}) })
setTimeout(() => { setTimeout(() => {
window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, document.body.scrollHeight);
}, 300); }, 0);
$(".msger-send-btn").click((e) => { $(".msger-send-btn").click((e) => {
e.preventDefault(); e.preventDefault();
@@ -23,6 +27,10 @@ frappe.ready(() => {
"args": { "args": {
"batch": decodeURIComponent($(e.target).attr("data-batch")), "batch": decodeURIComponent($(e.target).attr("data-batch")),
"message": message "message": message
},
"callback": (data) => {
$(".msger-input").val("");
frappe.realtime.publish("new_lms_message", {"message":"JJK"})
} }
}) })
} }

View File

@@ -1,51 +0,0 @@
{% extends "templates/base.html" %}
{% block content %}
{{ HeroSection() }}
{{ ExploreCourses(courses) }}
{{ RecentSketches(recent_sketches) }}
{% endblock %}
{% macro HeroSection() %}
<section id="hero">
<div class="container">
<div class="jumbotron">
<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">
<a class="btn btn-primary btn-lg" href="#" role="button">Request Invite</a>
</p>
</div>
</div>
</section>
{% endmacro %}
{% macro ExploreCourses(courses) %}
<section id="explore-courses" class="lightgray">
<div class="container lightgray">
<h2>Explore Courses</h2>
<div class="row">
{% for course in courses %}
<div class="col-md-6">
{{ widgets.CourseTeaser(course=course) }}
</div>
{% endfor %}
</div>
</div>
</section>
{% endmacro %}
{% macro RecentSketches(sketches) %}
<section id="recet-sketches">
<div class="container">
<h2>Recent Sketches</h2>
<div class="row">
{% for sketch in sketches %}
<div class="col-md-3">
{{ widgets.SketchTeaser(sketch=sketch) }}
</div>
{% endfor %}
</div>
</div>
</section>
{% endmacro %}

View File

@@ -1,7 +0,0 @@
import frappe
from community.lms.models import Course, Sketch
def get_context(context):
context.no_cache = 1
context.courses = Course.find_all()
context.recent_sketches = Sketch.get_recent_sketches(limit=8)

View File

@@ -12,6 +12,6 @@ def get_context(context):
def get_member(username): def get_member(username):
try: try:
return frappe.get_doc("Community Member", {"username":username}) frappe.get_doc("Community Member", {"username":username})
except frappe.DoesNotExistError: except frappe.DoesNotExistError:
return return

View File

@@ -16,13 +16,37 @@
<a href="/sketches/new">Create a New Sketch</a> <a href="/sketches/new">Create a New Sketch</a>
</div> </div>
<div class='container'> <div class='container'>
<div class="row"> <div class="row row-cols-1 row-cols-xl-5 row-cols-lg-4 row-cols-md-3 row-cols-sm-2 ">
{% for sketch in sketches %} {% for sketch in sketches %}
<div class="col-md-3"> <div class="col mb-4">
{{ widgets.SketchTeaser(sketch=sketch) }} <div class="card sketch-card" style="width: 200px;">
<div class="card-img-top">
<a href="/sketches/{{sketch.sketch_id}}">
{{ sketch.to_svg() }}
</a>
</div>
<div class="card-footer">
<div class="sketch-title">
<a href="sketches/{{sketch.sketch_id}}">{{sketch.title}}</a>
</div> </div>
{% endfor %} <div class="sketch-author">
by {{sketch.get_owner_name()}}
</div>
</div>
</div>
</div>
{% endfor %}
</div> </div>
</div> </div>
</section> </section>
{% endblock %} {% endblock %}
{% block style %}
{{super()}}
<style type="text/css">
svg {
width: 200px;
height: 200px;
}
</style>
{% endblock %}

View File

@@ -1,7 +1,7 @@
import frappe import frappe
from community.lms.models import Sketch from ...lms.doctype.lms_sketch.lms_sketch import get_recent_sketches
def get_context(context): def get_context(context):
context.no_cache = 1 context.no_cache = 1
context.sketches = Sketch.get_recent_sketches() context.sketches = get_recent_sketches()

View File

@@ -1,34 +0,0 @@
version: "3"
services:
redis-cache:
image: redis:alpine
redis-queue:
image: redis:alpine
redis-socketio:
image: redis:alpine
mariadb:
image: mariadb
volumes:
- mariadb-storage:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
bench:
image: anandology/frappe-bench
volumes:
- .:/home/bench/frappe-bench/apps/community
environment:
- FRAPPE_APPS=community
- FRAPPE_ALLOW_TESTS=true
- FRAPPE_SITE_NAME=frappe.localhost
depends_on:
- mariadb
- redis-cache
- redis-queue
- redis-socketio
ports:
- 8000:8000
- 9000:9000
volumes:
mariadb-storage: {}