feat: project, talks, update pages and web forms
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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"])
|
||||
@@ -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">
|
||||
|
||||
@@ -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")
|
||||
@@ -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 %}
|
||||
16
community/www/hackathons/macros/navbar.html
Normal file
16
community/www/hackathons/macros/navbar.html
Normal 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 %}
|
||||
3
community/www/hackathons/macros/user.html
Normal file
3
community/www/hackathons/macros/user.html
Normal file
@@ -0,0 +1,3 @@
|
||||
{% macro show_user(user) %}
|
||||
{{ frappe.db.get_value("User", user, "full_name") }}
|
||||
{% endmacro %}
|
||||
@@ -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 %}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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')
|
||||
Reference in New Issue
Block a user