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

Last change on this file was 12824, checked in by uli, 10 years ago

Find payment ids also if only the beginning is given.

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1## $Id: catalog.py 12824 2015-03-24 11:51:08Z 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 zope.catalog.interfaces import ICatalog
22from zope.component import queryUtility
23from waeup.ikoba.interfaces import ICompany
24from waeup.ikoba.payments.interfaces import IPayment
25
26
27def search(query=None, searchtype=None):
28    """Search payments catalog.
29
30    `query` gives a string we search for, `searchtype` the fieldname.
31
32    Query '*' returns all entries stored.
33
34    Fields containing strings are searched in a
35    'startswith'-manner. That means, we find all entries starting with
36    the given query string.
37
38    For other fields we only return exact matches. For instance for
39    `anount`, we require a decimal number (no string) and will find
40    all payments with that very amount given in `query`.
41
42    Returns a (possibly empty) catalog result set.
43    """
44    # Temporary solution to display all payments added
45    cat = queryUtility(ICatalog, name='payments_catalog')
46    if query == '*':
47        searchtype, query, upper_bound = 'payment_id', None, None
48    else:
49        if searchtype.endswith('_id'):
50            upper_bound = query + ('Z' * 48)
51        else:
52            upper_bound = query
53    search_params = {searchtype: (query, upper_bound)}
54    results = cat.searchResults(**search_params)
55    return results
56
57
58class PaymentIndexes(grok.Indexes):
59    """A catalog for all payments.
60    """
61    grok.site(ICompany)
62    grok.name('payments_catalog')
63    grok.context(IPayment)
64
65    payment_id = grok.index.Field(attribute='payment_id')
66    payer_id = grok.index.Field(attribute='payer_id')
67    payable_id = grok.index.Field(attribute='payable_id')
68    state = grok.index.Field(attribute='state')
69    amount = grok.index.Field(attribute='amount')
Note: See TracBrowser for help on using the repository browser.