This commit is contained in:
Faris Ansari
2017-08-18 15:15:41 +05:30
parent c5540b5833
commit 91ffcac3cb
7 changed files with 89 additions and 37 deletions

View File

@@ -6,10 +6,31 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe.website.website_generator import WebsiteGenerator from frappe.website.website_generator import WebsiteGenerator
from frappe.website.utils import get_comment_list from frappe.website.utils import get_comment_list
from frappe.utils import date_diff, nowdate, fmt_money
from frappe.website.utils import get_comment_list
class Bounty(WebsiteGenerator): class Bounty(WebsiteGenerator):
def get_context(self, context): def get_context(self, context):
context.no_cache = True context.no_cache = True
context.days_to_go = date_diff(self.end_date, nowdate())
no_of_backers = len(self.bounty_backer)
if no_of_backers == 0:
no_of_backers = 'No backers yet'
elif no_of_backers == 1:
no_of_backers = str(no_of_backers) + ' backer'
else:
no_of_backers = str(no_of_backers) + ' backers'
context.no_of_backers = no_of_backers
context.fmt_money = fmt_money
bounty_left = self.goal - self.bounty_collected
if bounty_left > (self.goal * 0.1) or bounty_left < 0:
bounty_left = self.goal * 0.1
context.bounty_left = bounty_left
context.comment_list = get_comment_list(self.doctype, self.name)
def validate(self): def validate(self):
self.bounty_collected = sum([backer.amount for backer in self.bounty_backer if backer.paid]) self.bounty_collected = sum([backer.amount for backer in self.bounty_backer if backer.paid])
@@ -20,4 +41,5 @@ def get_list_context(context):
context.title = 'ERPNext Bounties' context.title = 'ERPNext Bounties'
context.no_breadcrumbs = True context.no_breadcrumbs = True
context.order_by = 'creation desc' context.order_by = 'creation desc'
context.introduction = '<p>ERPNext feature requests</p>' context.introduction = '<p>List of all ERPNext bounties</p>'
context.fmt_money = fmt_money

View File

@@ -1,24 +1,59 @@
{% extends "templates/web.html" %} {% extends "templates/web.html" %}
{% block page_content %} {% block page_content %}
<h1>{{ title }}</h1> <style>
.main {
margin-bottom: 50px;
}
input[type=number] {
width: 200px;
margin-bottom: 12px;
}
</style>
<div class="main">
<h1>{{ title }} <span style="font-size: 14px; line-height: 44px;" class="pull-right small">{{days_to_go}} days to go</span></h1>
{% set bounty_progress = ((doc.bounty_collected/doc.goal)*100) %} {% set bounty_progress = ((doc.bounty_collected/doc.goal)*100) %}
<div class="progress"> <div class="progress" style="height: 12px;">
<div class="progress-bar progress-bar-success" role="progressbar" <div class="progress-bar progress-bar-success" role="progressbar"
aria-valuenow="{{bounty_progress}}" aria-valuemin="0" aria-valuemax="100" style="width: {{bounty_progress}}%"> aria-valuenow="{{bounty_progress}}" aria-valuemin="0" aria-valuemax="100" style="width: {{bounty_progress}}%">
<span class="sr-only">{{ doc.bounty_collected }} of {{ doc.goal }}</span> <span class="sr-only">{{ doc.bounty_collected }} of {{ doc.goal }}</span>
</div> </div>
</div> </div>
<p> <p>
<p class="lead">{{ frappe.utils.fmt_money(doc.bounty_collected, currency="USD") }} <p class="lead">{{ fmt_money(doc.bounty_collected, currency="USD") }}
<span class="text-muted small"> of {{ frappe.utils.fmt_money(doc.goal, currency="USD") }}</span> <span class="text-muted small"> of {{ fmt_money(doc.goal, currency="USD") }}</span>
<span class="text-muted small"></span> </p>
<p class="lead">
<span>{{ no_of_backers }}</span>
</p>
<p>
<input type="number" data-field="amount" class="form-control" placeholder="{{fmt_money(bounty_left)}}">
<a data-action="primary" class="btn btn-primary">
Back this bounty
</a>
</p> </p>
</p> </p>
<p>{{ doc.end_date }}</p> <script>
frappe.ready(function() {
<a class="btn btn-primary" href="/bounty/back-this-bounty?bounty={{doc.name}}">Back this bounty</a> $('[data-action="primary"]').click(function() {
var url = "/bounty/back-this-bounty?bounty_name={{doc.name}}&user=" + frappe.session.user;
var amount = $('[data-field="amount"]').val();
if(amount > 0) {
url += '&amount=' + amount;
}
window.location.href = url;
})
})
</script>
</div>
<p>
<h4>About this feature</h4>
<p>{{doc.description}}</p>
</p>
<hr style="margin: 50px 0;">
<h3>Discuss</h3> <h3>Discuss</h3>
{% include 'templates/includes/comments/comments.html' %} {% include 'templates/includes/comments/comments.html' %}

View File

@@ -2,9 +2,16 @@
<a href={{ route }}> <a href={{ route }}>
<h3>{{ doc.feature_name }}</h3> <h3>{{ doc.feature_name }}</h3>
<p> <p>
<span class="label">{{ frappe.format(doc.goal) }}</span> <span class="label">{{ fmt_money(doc.goal, currency="USD") }}</span>
<span class="label">{{ doc.end_date }}</span> <span class="label">{{ doc.end_date }}</span>
<span class="label">{{ doc.bounty_backer }} Backers</span> <span class="label">
{{ doc.bounty_backer|len }}
{% if doc.bounty_backer|len > 1 %}
Backers
{% else %}
Backer
{% endif %}
</span>
</p> </p>
<p>{{ html2text(doc.description[:200]) }}{% if doc.description|len > 200 %}...{% endif %}</p> <p>{{ html2text(doc.description[:200]) }}{% if doc.description|len > 200 %}...{% endif %}</p>
</a> </a>

View File

@@ -1,15 +1,3 @@
frappe.ready(function() { frappe.ready(function() {
var bounty_name = getParameterByName('bounty');
$('input[data-fieldname="bounty_name"]').val(bounty_name);
$('[data-fieldname="user"]').val(frappe.session.user);
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
}) })

View File

@@ -19,7 +19,7 @@
"is_standard": 1, "is_standard": 1,
"login_required": 1, "login_required": 1,
"max_attachment_size": 0, "max_attachment_size": 0,
"modified": "2017-08-18 08:18:03.166262", "modified": "2017-08-18 14:41:04.132808",
"modified_by": "faris@erpnext.com", "modified_by": "faris@erpnext.com",
"module": "ERPNext Foundation", "module": "ERPNext Foundation",
"name": "back-this-bounty", "name": "back-this-bounty",
@@ -33,16 +33,6 @@
"success_url": "/bounty", "success_url": "/bounty",
"title": "Back this bounty", "title": "Back this bounty",
"web_form_fields": [ "web_form_fields": [
{
"fieldname": "bounty_name",
"fieldtype": "Data",
"hidden": 0,
"label": "Bounty Name",
"max_length": 0,
"max_value": 0,
"read_only": 1,
"reqd": 0
},
{ {
"fieldname": "user", "fieldname": "user",
"fieldtype": "Link", "fieldtype": "Link",
@@ -54,6 +44,16 @@
"read_only": 1, "read_only": 1,
"reqd": 0 "reqd": 0
}, },
{
"fieldname": "bounty_name",
"fieldtype": "Data",
"hidden": 0,
"label": "Bounty Name",
"max_length": 0,
"max_value": 0,
"read_only": 1,
"reqd": 0
},
{ {
"fieldname": "amount", "fieldname": "amount",
"fieldtype": "Int", "fieldtype": "Int",

View File

@@ -3,6 +3,5 @@ from __future__ import unicode_literals
import frappe import frappe
def get_context(context): def get_context(context):
print(context) # do your magic here
context.no_breadcrumbs = 1 pass
context.user = 'faris@erpnext.com'

View File

@@ -47,6 +47,7 @@ website_context = {
{"label": "Services", "url": "/service-providers", "right": 1}, {"label": "Services", "url": "/service-providers", "right": 1},
{"label": "Jobs", "url": "/erpnext-jobs", "right": 1}, {"label": "Jobs", "url": "/erpnext-jobs", "right": 1},
{"label": "Chapters", "url": "/chapters", "right": 1}, {"label": "Chapters", "url": "/chapters", "right": 1},
{"label": "Bounties", "url": "/bounty", "right": 1},
{"label": '<span class="indicator blue">Conference</span>', "url": "/conf/2017", "right": 1}, {"label": '<span class="indicator blue">Conference</span>', "url": "/conf/2017", "right": 1},
{"label": "About", "url": "/about", "right": 1}, {"label": "About", "url": "/about", "right": 1},
], ],