__init__.py
1.45 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
51
52
53
54
55
56
57
58
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.items():
if isinstance(v, str):
kwargs[k] = v.lower()
for item in self:
found = 0
for k, v in kwargs.items():
a = getattr(item, k)
if isinstance(a, str):
a = a.lower()
if a == v:
found += 1
if found == _matches:
return item
return None
def findall(self, **kwargs):
_matches = len(kwargs)
for k, v in kwargs.items():
if isinstance(v, str):
kwargs[k] = v.lower()
items = []
for item in self:
found = 0
for k, v in kwargs.items():
a = getattr(item, k)
if isinstance(a, str):
a = a.lower()
if a == 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)
})