__init__.py
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from floraconcierge.client.types import Object
class Collection(Object, list):
def __init__(self, *args, **kwargs):
super(Collection, self).__init__(*args, **kwargs)
self.extend(self.items)
def find(self, **kwargs):
_matches = len(kwargs)
for k, v in kwargs.iteritems():
kwargs[k] = unicode(v).lower()
for item in self:
found = 0
for k, v in kwargs.iteritems():
if unicode(getattr(item, k)).lower() == v:
found += 1
if found == _matches:
return item
return None
def findall(self, **kwargs):
_matches = len(kwargs)
for k, v in kwargs.iteritems():
kwargs[k] = unicode(v).lower()
items = []
for item in self:
found = 0
for k, v in kwargs.iteritems():
if unicode(getattr(item, k)).lower() == v:
found += 1
if found == _matches:
items.append(item)
from floraconcierge.mapping import Collection as CollectionObj
return CollectionObj({
'count': len(items),
'items': items,
'offset': 0,
'total': len(items)
})