feat: project, talks, update pages and web forms

This commit is contained in:
pateljannat
2021-02-19 10:36:34 +05:30
parent 72135d7a73
commit 97db066922
32 changed files with 493 additions and 41 deletions

View File

@@ -0,0 +1,8 @@
// Copyright (c) 2021, Frappe and contributors
// For license information, please see license.txt
frappe.ui.form.on('Community Hackathon', {
// refresh: function(frm) {
// }
});

View File

@@ -0,0 +1,60 @@
{
"actions": [],
"autoname": "field:hackathon_name",
"creation": "2021-02-17 12:40:25.604012",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"hackathon_name",
"organizer",
"year"
],
"fields": [
{
"fieldname": "hackathon_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Hackathon Name",
"reqd": 1,
"unique": 1
},
{
"fieldname": "organizer",
"fieldtype": "Data",
"label": "Organizer",
"options": "Email"
},
{
"fieldname": "year",
"fieldtype": "Select",
"label": "Year",
"options": "\n2021\n2022\n2023\n2024\n2025"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-17 12:44:25.198010",
"modified_by": "Administrator",
"module": "Community",
"name": "Community Hackathon",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class CommunityHackathon(Document):
pass

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe and Contributors
# See license.txt
from __future__ import unicode_literals
# import frappe
import unittest
class TestCommunityHackathon(unittest.TestCase):
pass

View File

@@ -13,7 +13,7 @@
"video_link",
"telegram_id",
"project_description",
"event",
"hackathon",
"accepting_members",
"likes",
"project_search"
@@ -58,12 +58,6 @@
"fieldtype": "Markdown Editor",
"label": "Project Description"
},
{
"fieldname": "event",
"fieldtype": "Link",
"label": "Event",
"options": "Community Event"
},
{
"default": "0",
"fieldname": "accepting_members",
@@ -79,11 +73,17 @@
"fieldname": "project_search",
"fieldtype": "Small Text",
"label": "Project Search"
},
{
"fieldname": "hackathon",
"fieldtype": "Link",
"label": "Hackathon",
"options": "Community Hackathon"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-12 18:28:33.440328",
"modified": "2021-02-17 12:41:32.562346",
"modified_by": "Administrator",
"module": "Community",
"name": "Community Project",

View File

@@ -3,8 +3,15 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe import _
from frappe.model.document import Document
class CommunityProjectMember(Document):
pass
def validate(self):
self.validate_if_already_member()
def validate_if_already_member(self):
if frappe.get_all("Community Project Member", {"owner": self.owner}):
frappe.throw(_("You have already applied for the membership of this project."))

View File

@@ -0,0 +1,8 @@
// Copyright (c) 2021, Frappe and contributors
// For license information, please see license.txt
frappe.ui.form.on('Community Talk', {
// refresh: function(frm) {
// }
});

View File

@@ -0,0 +1,80 @@
{
"actions": [],
"autoname": "field:topic",
"creation": "2021-02-18 16:06:59.882799",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"speaker",
"topic",
"video_link",
"date_and_time",
"event_type",
"event"
],
"fields": [
{
"fieldname": "speaker",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Speaker",
"reqd": 1
},
{
"fieldname": "topic",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Topic",
"reqd": 1,
"unique": 1
},
{
"fieldname": "video_link",
"fieldtype": "Data",
"label": "Video Link"
},
{
"fieldname": "date_and_time",
"fieldtype": "Datetime",
"label": "Date and Time"
},
{
"fieldname": "event_type",
"fieldtype": "Link",
"label": "Event Type",
"options": "DocType"
},
{
"fieldname": "event",
"fieldtype": "Dynamic Link",
"label": "Event",
"options": "event_type"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-18 16:56:41.526184",
"modified_by": "Administrator",
"module": "Community",
"name": "Community Talk",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
}

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class CommunityTalk(Document):
pass

View File

@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2021, Frappe and Contributors
# See license.txt
from __future__ import unicode_literals
# import frappe
import unittest
class TestCommunityTalk(unittest.TestCase):
pass

View File

View File

@@ -0,0 +1,3 @@
frappe.ready(function() {
// bind events here
})

View File

@@ -0,0 +1,64 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 0,
"allow_incomplete": 0,
"allow_multiple": 0,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 0,
"button_label": "Send Request",
"client_script": "$('.page-header h2').html(`Request to Join \"${frappe.utils.get_url_arg('project_name')}\"`);",
"creation": "2021-02-17 13:20:08.548735",
"doc_type": "Community Project Member",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"is_standard": 1,
"login_required": 0,
"max_attachment_size": 0,
"modified": "2021-02-17 13:50:35.153793",
"modified_by": "Administrator",
"module": "Community",
"name": "join-request",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "join-request",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/join-request",
"title": "Join Request",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "project",
"fieldtype": "Link",
"hidden": 0,
"label": "Project",
"max_length": 0,
"max_value": 0,
"options": "Community Project",
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "intro",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Intro",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
}
]
}

View File

@@ -0,0 +1,7 @@
from __future__ import unicode_literals
import frappe
def get_context(context):
# do your magic here
pass

View File

@@ -0,0 +1,8 @@
frappe.ready(function () {
// bind events here
frappe.web_form.success_url = `hackathons/project?project=${frappe.utils.get_url_arg('project')}&hackathon=${frappe.utils.get_url_arg('hackathon')}`;
$('.breadcrumb-container')
.html(`<a href="${frappe.web_form.success_url}">Back to my project</a>`)
.addClass('py-4');
})

View File

@@ -0,0 +1,63 @@
{
"accept_payment": 0,
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 0,
"allow_incomplete": 0,
"allow_multiple": 0,
"allow_print": 0,
"amount": 0.0,
"amount_based_on_field": 0,
"apply_document_permissions": 0,
"button_label": "Submit",
"creation": "2021-02-18 13:15:09.464515",
"doc_type": "Community Project Update",
"docstatus": 0,
"doctype": "Web Form",
"idx": 0,
"is_standard": 1,
"login_required": 1,
"max_attachment_size": 0,
"modified": "2021-02-18 13:23:41.023545",
"modified_by": "Administrator",
"module": "Community",
"name": "project-update",
"owner": "Administrator",
"payment_button_label": "Buy Now",
"published": 1,
"route": "project-update",
"route_to_success_link": 0,
"show_attachments": 0,
"show_in_grid": 0,
"show_sidebar": 0,
"sidebar_items": [],
"success_url": "/project-update",
"title": "Project Update",
"web_form_fields": [
{
"allow_read_on_all_link_options": 0,
"fieldname": "project",
"fieldtype": "Link",
"hidden": 0,
"label": "Project",
"max_length": 0,
"max_value": 0,
"options": "Community Project",
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
},
{
"allow_read_on_all_link_options": 0,
"fieldname": "update",
"fieldtype": "Data",
"hidden": 0,
"label": "Update",
"max_length": 0,
"max_value": 0,
"read_only": 0,
"reqd": 1,
"show_in_filter": 0
}
]
}

View File

@@ -0,0 +1,7 @@
from __future__ import unicode_literals
import frappe
def get_context(context):
# do your magic here
pass

View File

@@ -2,6 +2,8 @@
{% block title %}{{ hackathon }}{% endblock %}
{% from "www/hackathons/macros/hero.html" import hero %}
{% from "www/hackathons/macros/card.html" import null_card %}
{% from "www/hackathons/macros/navbar.html" import navbar %}
{% from "www/hackathons/macros/user.html" import show_user %}
{% block head_include %}
<style>
@@ -50,19 +52,77 @@
</div>
{% endmacro %}
{% macro card_talk(talk) %}
<div class="col-sm-4 mb-4 text-left">
<a href="{{talk.video_link}}" class="no-decoration no-underline">
<div class="card h-100">
<div class='card-body'>
<h5 class='card-title'>{{ talk.topic }}</h5>
<div class="text-muted">{{ talk.speaker }}</div>
<div class="text-muted">{{ frappe.utils.format_datetime(talk.date_and_time, "medium") }}</div>
</div>
</div>
</a>
</div>
{% endmacro %}
{% macro card_update(update) %}
<div class="col-sm-4 mb-4 text-left">
<div class="card h-100">
<div class='card-body'>
<p>{{ frappe.utils.md_to_html(update.project_update) }}</p>
<div>
<a href="/hackathons/project?project={{update.project}}&hackathon={{hackathon}}">{{ update.project}}</a>
by {{ show_user(update.owner) }}
<div class="text-muted">{{ frappe.utils.format_datetime(update.creation, "medium") }}</div>
</div>
</div>
</div>
</div>
{% endmacro %}
{% block content %}
<section class="section">
{{ hero(hackathon, {'name': 'Home', 'url': '/hackathons'}) }}
<div class='container'>
<div class="row mt-5">
{% for project in projects %}
{{ card(project) }}
{% endfor %}
{% if projects %}
{% for n in range( (3 - (projects|length)) %3) %}
{{ null_card() }}
{% endfor %}
{% endif %}
{{ navbar(hackathon) }}
<div class="tab-content">
<div class="tab-pane fade py-4 show active" role="tabpanel" id="home">
<div class="row mt-5">
{% for project in projects %}
{{ card(project) }}
{% endfor %}
{% if projects %}
{% for n in range( (3 - (projects|length)) %3) %}
{{ null_card() }}
{% endfor %}
{% endif %}
</div>
</div>
<div class="tab-pane fade py-4" role="tabpanel" id="talks">
<div class="row mt-5">
{% for talk in talks %}
{{ card_talk(talk) }}
{% endfor %}
{% if talks %}
{% for n in range( (3 - (talks|length)) %3) %}
{{ null_card() }}
{% endfor %}
{% endif %}
</div>
</div>
<div class="tab-pane fade py-4" role="tabpanel" id="updates">
<div class="row mt-5">
{% for update in updates %}
{{ card_update(update) }}
{% endfor %}
{% if updates %}
{% for n in range( (3 - (updates|length)) %3) %}
{{ null_card() }}
{% endfor %}
{% endif %}
</div>
</div>
</div>
</div>
</section>

View File

@@ -11,6 +11,15 @@ def get_context(context):
raise frappe.Redirect
context.projects = get_hackathon_projects(hackathon)
context.hackathon = hackathon
context.talks = get_hackathon_talks(hackathon)
context.updates = get_hackathon_updates(context.projects)
def get_hackathon_projects(hackathon):
return frappe.get_all("Community Project", filters={"event":hackathon}, fields=["name", "project_short_intro"])
return frappe.get_all("Community Project", filters={"hackathon":hackathon}, fields=["name", "project_short_intro"])
def get_hackathon_talks(hackathon):
return frappe.get_all("Community Talk", {"event": hackathon}, ["topic", "speaker", "date_and_time", "video_link"])
def get_hackathon_updates(projects):
project_list = [project.name for project in projects]
return frappe.get_all("Community Project Update", {"project": ["in", project_list]}, ["project", "`update` as project_update", "owner", "creation"])

View File

@@ -41,11 +41,11 @@
<section class="top-section" style="padding: 6rem 0rem;">
<div class='container pb-5'>
<h1>{{ 'Hackathon' }}</h1>
<p class="mt-4">
<!-- <p class="mt-4">
{% if frappe.session.user == 'Guest' %}
<a class="btn btn-primary btn-lg" href="/login#signup">{{_('Sign Up')}}</a>
{% endif %}
</p>
</p> -->
</div>
<div class='container'>
<div class="row mt-5">

View File

@@ -5,4 +5,4 @@ def get_context(context):
context.hackathons = get_hackathons()
def get_hackathons():
return frappe.get_all("Community Event", filters={"is_hackathon": True})
return frappe.get_all("Community Hackathon")

View File

@@ -6,10 +6,10 @@
</a>
</div>
<h1>{{ title }}</h1>
<p class="mt-4">
<!-- <p class="mt-4">
{% if frappe.session.user == 'Guest' %}
<a id="signup" class="btn btn-primary btn-lg" href="/login#signup">{{_('Sign Up')}}</a>
{% endif %}
</p>
</p> -->
</div>
{% endmacro %}

View File

@@ -0,0 +1,16 @@
{% macro navbar(hackathon) %}
<ul class="nav nav-tabs mt-4" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home"
aria-selected="true">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link" id="talks-tab" data-toggle="tab" href="#talks" role="tab" aria-controls="talks"
aria-selected="false">Talks</a>
</li>
<li class="nav-item">
<a class="nav-link" id="updates-tab" data-toggle="tab" href="#updates" role="tab" aria-controls="updates"
aria-selected="false">Updates</a>
</li>
</ul>
{% endmacro %}

View File

@@ -0,0 +1,3 @@
{% macro show_user(user) %}
{{ frappe.db.get_value("User", user, "full_name") }}
{% endmacro %}

View File

@@ -2,6 +2,7 @@
{% block title %}{{ hackathon }}{% endblock %}
{% from "www/hackathons/macros/hero.html" import hero %}
{% from "www/hackathons/macros/card.html" import null_card %}
{% from "www/hackathons/macros/user.html" import show_user %}
{% block head_include %}
<meta name="description" content="{{ 'Hackathon' }}" />
<meta name="keywords" content="An app that supports Communities" />
@@ -37,9 +38,6 @@
</style>
{% endblock %}
{% macro show_user(user) %}
{{ frappe.db.get_value("User", user, "full_name") }}
{% endmacro %}
{% block content %}
<section class="section">
@@ -68,7 +66,7 @@
{% if project.video_link %}
<a href="{{ project.video_link }}" class="btn btn-default btn-sm" target="_blank">Video ▶️</a>
{% endif %}
<button class="btn btn-default btn-sm btn-like">👍</button>
<button class="btn btn-default btn-sm btn-like" data-project={{project.name}}>👍</button>
<ul class="nav nav-tabs mt-4" id="myTab" role="tablist">
<li class="nav-item">
@@ -108,7 +106,7 @@
<div class="list-group-item">
{{ show_user(member.owner) }}
{% if is_user %}
<button data-request-id="{{ m.name }}"
<button data-request-id="{{ member.name }}"
class="btn btn-sm btn-default btn-leave ml-4">Leave</button>
{% endif %}
</div>
@@ -144,13 +142,13 @@
{% macro add_update(update, date) %}
<div class='list-group-item'>
{{ frappe.utils.md_to_html(update or '') }}
<div class="small text-muted text-right">{{ frappe.format_date(date) }}</div>
<div class="small text-muted text-right">{{ frappe.utils.format_datetime(date, "medium") }}</div>
</div>
{% endmacro %}
{% if frappe.session.user != 'Guest' and (is_owner or is_member) %}
<p>
<a href="/add-update?new=1&project={{ project.name }}" class="btn btn-secondary btn-sm">Add
<a href="/project-update?new=1&project={{ project.name }}&hackathon={{ hackathon }}" class="btn btn-secondary btn-sm">Add
Update</a>
</p>
{% endif %}

View File

@@ -15,27 +15,27 @@ var set_likes = function(liked, likes) {
//set_likes(liked, likes);
// like - unlike
$('.btn-like').on('click', () => {
frappe.call('like', {project: project}, (data) => {
$('.btn-like').on('click', (e) => {
frappe.call('like', {project: $(e.target).attr("data-project")}, (data) => {
set_likes(data.message.action =="Liked", data.message.likes);
});
});
// accept / reject
$('.btn-accept').on('click', (ev) => {
frappe.call('join_request', {id: $(ev.target).attr('data-request-id'), action: 'Accept'}, (data) => {
$('.btn-accept').on('click', (e) => {
frappe.call('community.www.hackathons.project.join_request', {id: $(e.target).attr('data-request-id'), action: 'Accept'}, (data) => {
window.location.reload();
});
});
$('.btn-reject').on('click', (ev) => {
frappe.call('join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
frappe.call('community.www.hackathons.project.join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
window.location.reload();
});
});
$('.btn-leave').on('click', (ev) => {
frappe.call('join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
frappe.call('community.www.hackathons.project.join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
window.location.reload();
});
});

View File

@@ -39,7 +39,7 @@ def get_project_likes(project_name):
return frappe.get_all("Community Project Like", {"project": project_name})
def get_updates(project_name):
return frappe.get_all('Community Project Update', {"project": project_name}, ['owner', 'creation', 'update'])
return frappe.get_all('Community Project Update', {"project": project_name}, ['owner', 'creation', '`update` as project_update'])
def get_accepted_members(project_name):
return frappe.get_all("Community Project Member", {"project": project_name, "status": "Accepted" })
@@ -51,7 +51,18 @@ def get_my_projects():
return my_project
def check_is_member(project_name):
frappe.get_all("Community Project Member", {"project": project_name, "status": "Accepted", "owner": frappe.session.user })
return frappe.get_all("Community Project Member", {"project": project_name, "status": "Accepted", "owner": frappe.session.user })
def get_liked_project(project_name):
return frappe.db.get_value("Community Project Like", {"owner": frappe.session.user, "project": project_name})
return frappe.db.get_value("Community Project Like", {"owner": frappe.session.user, "project": project_name})
@frappe.whitelist()
def join_request(id, action):
if action == 'Accept':
project_member = frappe.get_doc('Community Project Member', id)
if len(frappe.db.get_all('Community Project Member',
dict(project = project_member.project, status = 'Accepted'))) > 2:
frappe.throw('A project cannot have more than 4 members')
frappe.db.set_value('Community Project Member', id, 'status', 'Accepted')
else:
frappe.db.set_value('Community Project Member', id, 'status', 'Rejected')