Commit cd55e725 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_panel: Render payment list as table

   Use a small page template to mimic the Listbox layout (minimally)
parent b9229561
Pipeline #35610 passed with stage
in 0 seconds
from zExceptions import Unauthorized from zExceptions import Unauthorized
from DateTime import DateTime
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
...@@ -10,12 +11,12 @@ ledger_uid = portal.portal_categories.ledger.automated.getUid() ...@@ -10,12 +11,12 @@ ledger_uid = portal.portal_categories.ledger.automated.getUid()
# This script will be used to generate the payment # This script will be used to generate the payment
# compatible with external providers # compatible with external providers
html_content = ''
entity = portal.portal_membership.getAuthenticatedMember().getUserValue() entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
if entity is None: if entity is None:
return '<p>Nothing to pay with your account</p>' return '<p>Nothing to pay with your account</p>'
payment_dict_list = []
for currency_uid, secure_service_relative_url in [ for currency_uid, secure_service_relative_url in [
(portal.currency_module.EUR.getUid(), portal.Base_getPayzenServiceRelativeUrl()), (portal.currency_module.EUR.getUid(), portal.Base_getPayzenServiceRelativeUrl()),
# (portal.currency_module.CNY.getUid(), portal.Base_getWechatServiceRelativeUrl()) # (portal.currency_module.CNY.getUid(), portal.Base_getWechatServiceRelativeUrl())
...@@ -32,15 +33,23 @@ for currency_uid, secure_service_relative_url in [ ...@@ -32,15 +33,23 @@ for currency_uid, secure_service_relative_url in [
if not is_payment_configured: if not is_payment_configured:
return '<p>Please contact us to handle your payment</p>' return '<p>Please contact us to handle your payment</p>'
html_content += """ reference = outstanding_amount.getReference()
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p> stop_date = outstanding_amount.getStopDate()
""" % { if outstanding_amount.getPortalType() == "Subscription Request":
'total_price': outstanding_amount.total_price, reference = "Subscriptions pre-payment"
'currency': outstanding_amount.getPriceCurrencyReference(), stop_date = DateTime()
'payment_url': '%s/Base_createExternalPaymentTransactionFromOutstandingAmountAndRedirect' % outstanding_amount.absolute_url() payment_dict_list.append({
} "reference": reference,
# Format by hand is not a good idea probably
if not html_content: "date": stop_date.strftime('%d/%m/%Y'),
html_content = '<p>Nothing to pay</p>' "url": '%s/Base_createExternalPaymentTransactionFromOutstandingAmountAndRedirect' % outstanding_amount.absolute_url(),
"total_price": outstanding_amount.total_price,
return html_content "currency": outstanding_amount.getPriceCurrencyReference()
})
if not payment_dict_list:
return '<p>Nothing to pay</p>'
# Pass argument via request.
context.REQUEST.set("payment_dict_list", payment_dict_list)
return context.Base_renderOutstandingAmountTable()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_renderOutstandingAmountTable</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<tal:block tal:define="payment_dict_list python: request.get('payment_dict_list', [])">
<tal:block tal:condition='payment_dict_list'>
<div class="document_table">
<div class="ui-table-header ui-header">
<h1>Pending Payments (<span tal:content="python: len(payment_dict_list)">0</span>)</h1>
</div>
<table>
<thead class="thead">
<tr>
<th>Reference</th>
<th>Date</th>
<th>Price</th>
<th>Currency</th>
</tr>
</thead>
<tbody>
<tal:block tal:repeat='payment_dict payment_dict_list'>
<tr tal:define="payment_url python: payment_dict['url']">
<td><a tal:attributes="href payment_url"
tal:content="python:payment_dict['reference']">Reference</a></td>
<td><a tal:attributes="href payment_url"
tal:content="python:payment_dict['date']">Date</a></td>
<td><a tal:attributes="href payment_url"
tal:content="python:payment_dict['total_price']">Price</a></td>
<td><a tal:attributes="href payment_url"
tal:content="python:payment_dict['currency']">Currency</a></td>
</tr>
</tal:block>
</tbody>
<tfoot></tfoot>
</table>
<nav>
<span class="ui-disabled" tal:content="python: '%s records' % len(payment_dict_list)">No records</span>
</nav>
</div>
</tal:block>
</tal:block>
\ No newline at end of file
from zExceptions import Unauthorized from zExceptions import Unauthorized
from DateTime import DateTime
if REQUEST is not None: if REQUEST is not None:
raise Unauthorized raise Unauthorized
...@@ -9,7 +10,8 @@ assert web_site is not None ...@@ -9,7 +10,8 @@ assert web_site is not None
# This script will be used to generate the payment # This script will be used to generate the payment
# compatible with external providers # compatible with external providers
html_content = '' payment_dict_list = []
entity = portal.portal_membership.getAuthenticatedMember().getUserValue() entity = portal.portal_membership.getAuthenticatedMember().getUserValue()
if entity is None: if entity is None:
return '<p>Nothing to pay with your account</p>' return '<p>Nothing to pay with your account</p>'
...@@ -70,6 +72,7 @@ if subscription_request is not None: ...@@ -70,6 +72,7 @@ if subscription_request is not None:
outstanting_total_price = sum([i.total_price for i in outstanding_amount_list]) outstanting_total_price = sum([i.total_price for i in outstanding_amount_list])
outstanting_total_price += price outstanting_total_price += price
if outstanting_total_price > 0: if outstanting_total_price > 0:
if not isPaymentConfigured(currency_uid): if not isPaymentConfigured(currency_uid):
return '<p>Please contact us to handle your payment</p>' return '<p>Please contact us to handle your payment</p>'
...@@ -78,15 +81,18 @@ if subscription_request is not None: ...@@ -78,15 +81,18 @@ if subscription_request is not None:
if subscription_request.isTempObject(): if subscription_request.isTempObject():
payment_url = context.absolute_url() + "/InstanceTree_redirectToManualDepositPayment" payment_url = context.absolute_url() + "/InstanceTree_redirectToManualDepositPayment"
html_content += """ payment_dict_list.append({
<p><a href="%(payment_url)s">%(total_price)s %(currency)s</a></p> "reference": "Subscriptions pre-payment",
""" % { # Format by hand is not a good idea probably
'total_price': outstanting_total_price, "date": DateTime().strftime('%d/%m/%Y'),
'currency': subscription_request.getPriceCurrencyReference(), "url": payment_url,
'payment_url': payment_url "total_price": outstanting_total_price,
} "currency": subscription_request.getPriceCurrencyReference()
})
if not html_content: if not payment_dict_list:
html_content = '<p>Nothing to pay</p>' return '<p>Nothing to pay</p>'
return html_content # Pass argument via request.
context.REQUEST.set("payment_dict_list", payment_dict_list)
return context.Base_renderOutstandingAmountTable()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment