Compare commits

...

15 Commits

Author SHA1 Message Date
Anand Chitipothu
9deaa182b7 refactor: switched to less for css
- Added build setup to include styles.less in building community.css
- The old styles are still in style.css. Those styles will be slowly moved to style.less.
- Move all the new styles to style.less
2021-04-29 15:43:58 +05:30
Anand Chitipothu
4bc05bfda8 Merge pull request #46 from fossunited/docker-compose
feat: dev-instance using docker-compose
2021-04-29 15:25:31 +05:30
Anand Chitipothu
0cfd6d7634 feat: dev-instance using docker-compose 2021-04-29 14:13:01 +05:30
Anand Chitipothu
f7434f376f Merge pull request #41 from fossunited/home-page
Home page
2021-04-29 13:59:54 +05:30
Anand Chitipothu
905f51ee76 fix: styles on home page 2021-04-29 12:16:48 +05:30
Anand Chitipothu
e207320721 feat: added home page
- Refactored the lms_course page and added find_all method to find courses
- Added CourseTeaser widget
- Added /home as a portal page
2021-04-29 10:57:29 +05:30
Anand Chitipothu
20ccc09869 refactor: sketches page
- Added new widget SketchTeaser
- Moved get_recent_sketches as static method in LMSSketch
- Added `models.py` to make it easy to import Course and Sketch class
- Updated the sketches template to use the SketchTeaser widget
2021-04-29 10:55:21 +05:30
Anand Chitipothu
e78c6020e7 Merge pull request #37 from fossunited/batch-discussions
fix: Batch discussions and Community Member fixes
2021-04-29 10:53:20 +05:30
Anand Chitipothu
4874d99e44 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:49:37 +05:30
pateljannat
a022804381 test: users with same name, username validations, users without username 2021-04-28 22:04:42 +05:30
pateljannat
7a40b3e7a5 fix: test for community member and lms course 2021-04-28 17:52:12 +05:30
pateljannat
7b142fd72d test: member creation from user 2021-04-28 13:50:40 +05:30
pateljannat
fc8ff9c7fd Merge branch 'main' of https://github.com/frappe/community into batch-discussions 2021-04-28 13:08:23 +05:30
pateljannat
c6bd47eb62 fix: user validaton and community member name issue 2021-04-28 13:08:09 +05:30
pateljannat
d68f1de796 feat: #27 discussion message publish realtime 2021-04-27 16:32:34 +05:30
31 changed files with 590 additions and 163 deletions

View File

@@ -9,7 +9,51 @@ 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.
### Local Setup
## Development 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:
@@ -21,7 +65,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. Now open the URL http://community.test:8000/docs in your browser, you should see the app running.
### Contribution Guidelines
### Contribution Guidelines (for The Hard Way)
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).

View File

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

View File

@@ -4,12 +4,12 @@
from __future__ import unicode_literals
import frappe
from frappe.website.website_generator import WebsiteGenerator
import re
from frappe import _
from frappe.model.rename_doc import rename_doc
from frappe.model.document import Document
import random
class CommunityMember(WebsiteGenerator):
class CommunityMember(Document):
def validate(self):
self.validate_username()
@@ -18,6 +18,9 @@ class CommunityMember(WebsiteGenerator):
self.route = self.username
def validate_username(self):
if not self.username:
self.username = create_username_from_email(self.email)
if self.username:
if len(self.username) < 4:
frappe.throw(_("Username must be atleast 4 characters long."))
@@ -29,12 +32,33 @@ class CommunityMember(WebsiteGenerator):
return f"<CommunityMember: {self.email}>"
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({
"doctype": "Community Member",
"full_name": doc.full_name,
"username": doc.username if len(doc.username) > 3 else ("").join([ s for s in doc.full_name.split() ]),
"username": username,
"email": doc.email,
"route": doc.username,
"owner": doc.email
})
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,9 +2,91 @@
# Copyright (c) 2021, Frappe and Contributors
# See license.txt
from __future__ import unicode_literals
# import frappe
from community.lms.doctype.lms_course.test_lms_course import new_user
import frappe
import unittest
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,7 +7,6 @@ def create_members_from_users():
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() ])
if not frappe.db.exists("Community Member", username):
print(doc.email, username)
member = frappe.new_doc("Community Member")
member.full_name = doc.full_name
member.username = username

View File

@@ -94,7 +94,10 @@ web_include_css = "/assets/css/community.css"
doc_events = {
"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
@@ -147,6 +150,7 @@ primary_rules = [
# Any frappe default URL is blocked by profile-rules, add it here to unblock it
whitelist = [
"/home",
"/login",
"/update-password",
"/update-profile",
@@ -169,3 +173,5 @@ profile_rules = [
]
website_route_rules = primary_rules + whitelist_rules + profile_rules
update_website_context = 'community.widgets.update_website_context'

View File

@@ -37,4 +37,3 @@ def save_message(message, batch):
"message": message
})
doc.save(ignore_permissions=True)
return doc

View File

@@ -88,3 +88,15 @@ class LMSCourse(Document):
member.batch_count = len(frappe.get_all("LMS Batch Membership", {"member": member.name, "member_type": "Mentor"}))
course_mentors.append(member)
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,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from .lms_course import LMSCourse
import unittest
class TestLMSCourse(unittest.TestCase):
@@ -11,7 +12,6 @@ class TestLMSCourse(unittest.TestCase):
frappe.db.sql('delete from `tabLMS Course Mentor Mapping`')
frappe.db.sql('delete from `tabLMS Course`')
frappe.db.sql('delete from `tabCommunity Member`')
frappe.db.sql('delete from `tabUser` where email like "%@example.com"')
def new_course(self, title):
doc = frappe.get_doc({
@@ -21,28 +21,48 @@ class TestLMSCourse(unittest.TestCase):
doc.insert()
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):
course = self.new_course("Test Course")
assert course.title == "Test Course"
assert course.slug == "test-course"
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
def _test_add_mentors(self):
course = self.new_course("Test Course")
assert course.get_mentors() == []
user = self.new_user("Tester", "tester@example.com")
user = new_user("Tester", "tester@example.com")
course.add_mentor("tester@example.com")
mentors = course.get_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}]
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,
"links": [],
"modified": "2021-04-26 16:11:20.142164",
"modified": "2021-04-28 10:17:57.618127",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Message",
@@ -80,5 +80,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "author",
"track_changes": 1
}

View File

@@ -7,10 +7,11 @@ import frappe
from frappe.model.document import Document
from frappe import _
from frappe.utils import add_days, nowdate
from community.www.courses.utils import get_batch_members
class LMSMessage(Document):
def after_insert(self):
frappe.publish_realtime("new_lms_message", {"message":"JJannat"}, user="Administrator")
self.send_email()
""" def after_insert(self):
self.send_email() """
def send_email(self):
membership = frappe.get_all("LMS Batch Membership", {"batch": self.batch}, ["member"])
@@ -61,3 +62,43 @@ def send_daily_digest():
},
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,9 +10,6 @@ from frappe.model.document import Document
from . import livecode
class LMSSketch(Document):
def get_owner_name(self):
return get_userinfo(self.owner)['full_name']
@property
def sketch_id(self):
"""Returns the numeric part of the name.
@@ -21,6 +18,14 @@ class LMSSketch(Document):
"""
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):
doc = frappe.get_cached_doc("LMS Settings")
return doc.livecode_url
@@ -46,6 +51,18 @@ class LMSSketch(Document):
cache.set(key, 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):
return f"<LMSSketch {self.name}>"
@@ -76,36 +93,3 @@ def save_sketch(name, title, code):
"status": status,
"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
}

5
community/lms/models.py Normal file
View File

@@ -0,0 +1,5 @@
"""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

@@ -0,0 +1,13 @@
<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

@@ -0,0 +1,14 @@
{#
Widget to demonostrate how to write a widget.
A wiget is a reusable template, that can be used in
other templates.
To this widget can be called as:
{{ widgets.HelloWorld(name="World") }}
#}
<div class="hello">
Hello, <em>{{ name }}</em>!
</div>

View File

@@ -0,0 +1,15 @@
<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,6 +3,8 @@
"public/css/lms.css"
],
"css/community.css": [
"public/css/style.css"
"public/css/vars.css",
"public/css/style.css",
"public/css/style.less"
]
}

View File

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

View File

@@ -0,0 +1,68 @@
@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

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

16
community/test_widgets.py Normal file
View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, FOSS United and Contributors
# See license.txt
import frappe
import unittest
from .widgets import Widget, Widgets
class TestWidgets(unittest.TestCase):
def test_Widgets(self):
widgets = Widgets()
assert widgets.Foo.name == "Foo"
assert widgets.Bar.name == "Bar"
def _test_Widget(self):
hello = Widget("HelloWorld")
assert hello(name="Test") == "Hello, Test"

60
community/widgets.py Normal file
View File

@@ -0,0 +1,60 @@
"""The widgets provides access to HTML widgets
provided in each frappe module.
Widgets are simple moduler templates that can reused
in multiple places. These are like macros, but accessing
them will be a lot easier.
The widgets will be provided
"""
import frappe
from frappe.utils.jinja import get_jenv
# search path for widgets.
# When {{widgets.SomeWidget()}} is called, it looks for
# widgets/SomeWidgets.html in each of these modules.
MODULES = [
"lms"
]
def update_website_context(context):
"""Adds widgets to the context.
Called from hooks.
"""
context.widgets = Widgets()
class Widgets:
"""The widget collection.
This is just a placeholder object and returns the appropriate
widget when accessed using attribute.
>>> widgets = Widgets()
>>> widgets.HelloWorld(name="World!")
'<div>Hello, World!</div>'
"""
def __getattr__(self, name):
if not name.startswith("__"):
return Widget(name)
else:
raise AttributeError(name)
class Widget:
"""The Widget class renders a widget.
Widget is a reusable template defined in widgets/ directory in
each frappe module.
>>> w = Widget("HelloWorld")
>>> w(name="World!")
'<div>Hello, World!</div>'
"""
def __init__(self, name):
self.name = name
def __call__(self, **kwargs):
# the widget could be in any of the modules
paths = [f"{module}/widgets/{self.name}.html" for module in MODULES]
env = get_jenv()
return env.get_or_select_template(paths).render(kwargs)

View File

@@ -1,15 +1,4 @@
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") {
frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
@@ -25,21 +14,6 @@ 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) => {
if (frappe.session.user == "Guest") {
window.location.href = "/login";
@@ -94,19 +68,4 @@ 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,7 +35,6 @@
<div class="mt-5">
{{ message.message }}
</div>
</div>
{% endfor %}
{% endmacro %}

View File

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

View File

@@ -0,0 +1,51 @@
{% 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

@@ -0,0 +1,7 @@
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):
try:
frappe.get_doc("Community Member", {"username":username})
return frappe.get_doc("Community Member", {"username":username})
except frappe.DoesNotExistError:
return

View File

@@ -16,37 +16,13 @@
<a href="/sketches/new">Create a New Sketch</a>
</div>
<div class='container'>
<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 %}
<div class="col mb-4">
<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 class="row">
{% for sketch in sketches %}
<div class="col-md-3">
{{ widgets.SketchTeaser(sketch=sketch) }}
</div>
<div class="sketch-author">
by {{sketch.get_owner_name()}}
</div>
</div>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
</div>
</section>
{% endblock %}
{% block style %}
{{super()}}
<style type="text/css">
svg {
width: 200px;
height: 200px;
}
</style>
{% endblock %}

View File

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

34
docker-compose.yml Normal file
View File

@@ -0,0 +1,34 @@
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: {}