mirror of
https://github.com/erpnext/foundation.git
synced 2026-10-16 18:00:47 +02:00
Add USD form, show backer names
This commit is contained in:
@@ -11,33 +11,42 @@ from frappe.website.utils import get_comment_list
|
||||
|
||||
class Bounty(WebsiteGenerator):
|
||||
def get_context(self, context):
|
||||
context.no_cache = True
|
||||
context.days_to_go = date_diff(self.end_date, nowdate())
|
||||
|
||||
no_of_backers = len(self.bounty_backer)
|
||||
paid_backers = [backer for backer in self.bounty_backer if backer.paid]
|
||||
no_of_backers = len(paid_backers)
|
||||
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.no_cache = True
|
||||
context.days_to_go = date_diff(self.end_date, nowdate())
|
||||
context.paid_backers = paid_backers
|
||||
context.no_of_backers = no_of_backers
|
||||
context.fmt_money = fmt_money
|
||||
context.bounty_left = bounty_left
|
||||
context.comment_list = get_comment_list(self.doctype, self.name)
|
||||
|
||||
def validate(self):
|
||||
from frappe.utils.user import get_user_fullname
|
||||
|
||||
self.bounty_collected = sum([backer.amount for backer in self.bounty_backer if backer.paid])
|
||||
if not self.route:
|
||||
self.published = 1
|
||||
self.route = 'bounties/' + self.feature_name.lower().replace(' ', '-')
|
||||
|
||||
bounty_backers = []
|
||||
for backer in self.bounty_backer:
|
||||
if backer.user and not backer.full_name:
|
||||
backer.full_name = get_user_fullname(backer.user)
|
||||
bounty_backers.append(backer)
|
||||
self.bounty_backer = bounty_backers
|
||||
|
||||
def get_list_context(context):
|
||||
context.allow_guest = True
|
||||
context.no_cache = True
|
||||
|
||||
@@ -6,11 +6,25 @@
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
input[type=number] {
|
||||
.bounty-amount {
|
||||
width: 200px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.bounty-amount .dropdown-menu {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.bounty-amount .dropdown-toggle {
|
||||
border: 1px solid #d1d8dd;
|
||||
}
|
||||
|
||||
input::-webkit-outer-spin-button,
|
||||
input::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
p.lead {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
@@ -26,35 +40,64 @@
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<p class="lead">{{ fmt_money(doc.bounty_collected, currency="INR") }}
|
||||
<span class="text-muted small"> of {{ fmt_money(doc.goal, currency="INR") }}</span>
|
||||
<p class="lead">{{ fmt_money(doc.bounty_collected, currency="USD") }}
|
||||
<span class="text-muted small"> of {{ fmt_money(doc.goal, currency="USD") }}</span>
|
||||
</p>
|
||||
<p class="lead">
|
||||
<span>{{ no_of_backers }}</span>
|
||||
(
|
||||
{% for backer in paid_backers %}
|
||||
<span class="small">{{ backer.full_name }}</span>,
|
||||
{% endfor %}
|
||||
)
|
||||
</p>
|
||||
{% if doc.github_issue %}
|
||||
<p>
|
||||
<a href="{{doc.github_issue}}" target="_blank">GitHub Issue</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
<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>
|
||||
|
||||
<div class="input-group bounty-amount">
|
||||
<input type="number" data-field="amount"
|
||||
class="form-control" aria-label="Bounty Amount"
|
||||
placeholder="{{fmt_money(bounty_left)}}">
|
||||
|
||||
<div class="input-group-btn">
|
||||
<button type="button" class="btn btn-default dropdown-toggle"
|
||||
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="bounty-currency">USD</span>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right">
|
||||
<li><a data-currency="USD">USD</a></li>
|
||||
<li><a data-currency="INR">INR</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<a data-action="primary" class="btn btn-primary">
|
||||
Back this bounty
|
||||
</a>
|
||||
</p>
|
||||
<script>
|
||||
frappe.ready(function() {
|
||||
const $bounty_amount = $('.bounty-amount');
|
||||
|
||||
$('[data-action="primary"]').click(function() {
|
||||
var url = "/back-this-bounty?bounty_name={{doc.name}}&user=" + frappe.session.user;
|
||||
var amount = $('[data-field="amount"]').val();
|
||||
const currency = $bounty_amount.find('.bounty-currency').text();
|
||||
let url = `/back-this-bounty-${currency.toLowerCase()}`;
|
||||
url += `?bounty_name={{doc.name}}&user=${frappe.session.user}¤cy=${currency}`;
|
||||
let amount = $('[data-field="amount"]').val();
|
||||
if(amount > 0) {
|
||||
url += '&amount=' + amount;
|
||||
}
|
||||
window.location.href = url;
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
$bounty_amount.on('click', '[data-currency]', function() {
|
||||
const currency = $(this).attr('data-currency');
|
||||
$bounty_amount.find('.bounty-currency').text(currency);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<span class="label">{{ fmt_money(doc.goal, currency="INR") }}</span>
|
||||
<span class="label">{{ fmt_money(doc.goal, currency="USD") }}</span>
|
||||
<span class="label">Ends on {{ doc.end_date }}</span>
|
||||
{% if doc.bounty_backer %}
|
||||
<span class="label">
|
||||
|
||||
@@ -163,6 +163,37 @@
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Currency",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Currency",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
@@ -175,8 +206,8 @@
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-08-17 17:26:35.968048",
|
||||
"modified_by": "faris@erpnext.com",
|
||||
"modified": "2017-08-25 18:41:22.187182",
|
||||
"modified_by": "Administrator",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "Bounty Backer",
|
||||
"name_case": "",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2017-08-23 18:21:28.733120",
|
||||
"modified": "2017-08-26 21:13:32.398765",
|
||||
"modified_by": "faris@erpnext.com",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "back-this-bounty",
|
||||
@@ -27,11 +27,11 @@
|
||||
"payment_button_label": "Pay now",
|
||||
"payment_gateway": "Razorpay",
|
||||
"published": 1,
|
||||
"route": "back-this-bounty",
|
||||
"show_sidebar": 1,
|
||||
"route": "back-this-bounty-inr",
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_url": "/bounties",
|
||||
"title": "Back this bounty",
|
||||
"title": "Back this bounty - INR",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"fieldname": "user",
|
||||
@@ -63,6 +63,17 @@
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Currency",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "Currency",
|
||||
"read_only": 1,
|
||||
"reqd": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
frappe.ready(function() {
|
||||
// bind events here
|
||||
})
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"accept_payment": 1,
|
||||
"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": 1,
|
||||
"amount_field": "amount",
|
||||
"creation": "2017-08-25 18:11:39.203816",
|
||||
"currency": "USD",
|
||||
"doc_type": "Bounty Backer",
|
||||
"docstatus": 0,
|
||||
"doctype": "Web Form",
|
||||
"idx": 0,
|
||||
"introduction_text": "",
|
||||
"is_standard": 1,
|
||||
"login_required": 1,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2017-08-26 21:13:42.065195",
|
||||
"modified_by": "faris@erpnext.com",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "back-this-bounty-usd",
|
||||
"owner": "Administrator",
|
||||
"payment_button_label": "Pay now",
|
||||
"payment_gateway": "PayPal",
|
||||
"published": 1,
|
||||
"route": "back-this-bounty-usd",
|
||||
"show_sidebar": 0,
|
||||
"sidebar_items": [],
|
||||
"success_url": "/bounties",
|
||||
"title": "Back this bounty - USD",
|
||||
"web_form_fields": [
|
||||
{
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"label": "User",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "User",
|
||||
"read_only": 1,
|
||||
"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",
|
||||
"fieldtype": "Int",
|
||||
"hidden": 0,
|
||||
"label": "Amount",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Currency",
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"options": "Currency",
|
||||
"read_only": 1,
|
||||
"reqd": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
# do your magic here
|
||||
pass
|
||||
Reference in New Issue
Block a user