source: main/waeup.ikoba/trunk/src/waeup/ikoba/payments/catalog.py @ 12821

Last change on this file since 12821 was 12775, checked in by uli, 10 years ago

pep8, pyflakes.

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1## $Id: catalog.py 12775 2015-03-16 12:53:09Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""Components to help cataloging and searching payments.
19"""
20import grok
21from hurry.query import Eq
22from hurry.query.query import Query
23from zope.catalog.interfaces import ICatalog
24from zope.component import queryUtility
25from waeup.ikoba.interfaces import ICompany
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
52
53
54class PaymentIndexes(grok.Indexes):
55    """A catalog for all payments.
56    """
57    grok.site(ICompany)
58    grok.name('payments_catalog')
59    grok.context(IPayment)
60
61    payment_id = grok.index.Field(attribute='payment_id')
62    payer_id = grok.index.Field(attribute='payer_id')
63    payable_id = grok.index.Field(attribute='payable_id')
64    state = grok.index.Field(attribute='state')
65    amount = grok.index.Field(attribute='amount')
Note: See TracBrowser for help on using the repository browser.