Ignore:
Timestamp:
14 Mar 2015, 13:49:29 (10 years ago)
Author:
Henrik Bettermann
Message:

Add PaymentsContainerPage? to search for and list payments (work in progress, completely untested).

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/payments
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/browser.py

    r12761 r12762  
    2020import grok
    2121from waeup.ikoba.browser.breadcrumbs import Breadcrumb
     22from waeup.ikoba.interfaces import IIkobaObject
    2223from waeup.ikoba.interfaces import MessageFactory as _
    23 from waeup.ikoba.payments.interfaces import IPayment
    24 from waeup.ikoba.payments.payment import find_payable_from_payable_id
     24from waeup.ikoba.browser.viewlets import PrimaryNavTab
     25from waeup.ikoba.browser.layout import (
     26    IkobaPage, IkobaEditFormPage, IkobaDisplayFormPage,
     27    NullValidator, jsaction, action, UtilityView)
     28from waeup.ikoba.utils.helpers import get_current_principal
     29
     30from waeup.ikoba.payments.interfaces import (
     31    IPaymentsContainer, IPayment, payment_states
     32    )
     33from waeup.ikoba.payments.payment import (
     34    find_payable_from_payable_id,
     35    get_payment_providers
     36    )
     37from waeup.ikoba.payments.catalog import search
     38
     39
     40grok.context(IIkobaObject)  # Make IIkobaObject the default context
     41grok.templatedir('templates')
     42
     43
     44class PaymentsTab(PrimaryNavTab):
     45    """Payments tab in primary navigation.
     46    """
     47
     48    grok.context(IIkobaObject)
     49    grok.order(3)
     50    grok.require('waeup.Public')
     51    grok.name('paymentstab')
     52
     53    pnav = 5
     54    tab_title = _(u'Payments')
     55
     56    @property
     57    def link_target(self):
     58        return self.view.application_url('payments')
     59
     60
     61class PaymentsBreadcrumb(Breadcrumb):
     62    """A breadcrumb for the payments container.
     63    """
     64    grok.context(IPaymentsContainer)
     65    title = _('Payments')
     66
    2567
    2668class PaymentBreadcrumb(Breadcrumb):
     
    4688            return (grok.getSite(), 'index')
    4789        return (payable, 'index')
     90
     91
     92class PaymentsContainerPage(IkobaPage):
     93    """The standard view for payment containers.
     94    """
     95    grok.context(IPaymentsContainer)
     96    grok.name('index')
     97    grok.require('waeup.managePortal')
     98    grok.template('containerpage')
     99    label = _('Find payments')
     100    search_button = _('Find payment(s)')
     101    pnav = 5
     102
     103    @property
     104    def gateway_services(self):
     105        return get_payment_providers()
     106
     107    @property
     108    def payment_states(self):
     109        return payment_states
     110
     111    def update(self, *args, **kw):
     112        form = self.request.form
     113        self.hitlist = []
     114        if 'searchterm' in form and form['searchterm']:
     115            self.searchterm = form['searchterm']
     116            self.searchtype = form['searchtype']
     117        elif 'old_searchterm' in form:
     118            self.searchterm = form['old_searchterm']
     119            self.searchtype = form['old_searchtype']
     120        else:
     121            if 'search' in form:
     122                self.flash(_('Empty search string'), type="warning")
     123            return
     124        self.hitlist = search(query=self.searchterm,
     125            searchtype=self.searchtype)
     126        if not self.hitlist:
     127            self.flash(_('No payment found.'), type="warning")
     128        return
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/catalog.py

    r12671 r12762  
    1919"""
    2020import grok
     21from hurry.query import Eq, Text
     22from hurry.query.query import Query
     23from zope.catalog.interfaces import ICatalog
     24from zope.component import queryUtility
    2125from waeup.ikoba.interfaces import ICompany
    22 from waeup.ikoba.payments.interfaces import IPayment
     26from waeup.ikoba.payments.interfaces import (
     27    IPayment, IPayable
     28    )
     29from waeup.ikoba.payments.payment import (
     30    find_payable_from_payable_id
     31    )
     32
     33
     34def search(query=None, searchtype=None):
     35    hitlist = []
     36    # Temporary solution to display all payments added
     37    if query == '*':
     38        cat = queryUtility(ICatalog, name='payments_catalog')
     39        results = cat.searchResults(payment_id=(None, None))
     40    else:
     41        results = Query().searchResults(
     42            Eq(('payments_catalog', searchtype), query))
     43    hitlist = []
     44    for payment in results:
     45        payable_object = find_payable_from_payable_id(payment.payable_id)
     46        if payable_object is not None:
     47            payable = IPayable(payable_object)
     48        else:
     49            payable = None
     50        hitlist.append((payment, payable, payable_object))
     51    return hitlist
    2352
    2453
     
    3261    payment_id = grok.index.Field(attribute='payment_id')
    3362    payer_id = grok.index.Field(attribute='payer_id')
     63    payable_id = grok.index.Field(attribute='payable_id')
    3464    state = grok.index.Field(attribute='state')
    3565    amount = grok.index.Field(attribute='amount')
Note: See TracChangeset for help on using the changeset viewer.