/
criteria.txt
119 lines (94 loc) · 3.01 KB
/
criteria.txt
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
Handle criteria
===============
Imports
-------
>>> from zope.component import getMultiAdapter
>>> from eea.facetednavigation.interfaces import ICriteria
Set up
------
>>> self.loginAsPortalOwner()
>>> sid = portal.invokeFactory('Folder', 'sandbox')
>>> sandbox = portal._getOb(sid)
>>> request = sandbox.REQUEST
>>> subtyper = getMultiAdapter((sandbox, request), name=u'faceted_subtyper')
>>> subtyper.can_enable
True
>>> subtyper.enable()
Cleanup default widgets
-----------------------
>>> cids = ICriteria(sandbox).keys()
>>> for cid in cids:
... ICriteria(sandbox).delete(cid)
>>> ICriteria(sandbox).keys()
[]
Add criteria
------------
>>> _ = ICriteria(sandbox).add('alphabetic', 'left')
>>> _ = ICriteria(sandbox).add('checkbox', 'left')
>>> _ = ICriteria(sandbox).add('criteria', 'right')
>>> _ = ICriteria(sandbox).add('daterange', 'right')
>>> _ = ICriteria(sandbox).add('radio', 'top')
>>> _ = ICriteria(sandbox).add('select', 'top')
>>> _ = ICriteria(sandbox).add('sorting', 'center')
>>> _ = ICriteria(sandbox).add('text', 'center')
Get criteria
------------
>>> ICriteria(sandbox).keys()
['c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7']
>>> ICriteria(sandbox).values()
[<eea.facetednavigation.widgets.storage.Criterion object at...>, ...]
>>> ICriteria(sandbox).items()
[('c0', <eea.facetednavigation.widgets.storage.Criterion object at...>), ...]
>>> ICriteria(sandbox).get('c0')
<eea.facetednavigation.widgets.storage.Criterion object at...>
Edit criterion
--------------
Alphabetic criterion
>>> ICriteria(sandbox).edit('c0', title='Alphabetic', index='Title', hidden='0')
>>> criterion = ICriteria(sandbox).get('c0')
>>> criterion.get('title')
u'Alphabetic'
>>> criterion.hidden
False
>>> criterion.get('index')
u'Title'
Checkbox criterion
>>> ICriteria(sandbox).edit('c1',
... title='Check boxes',
... index='portal_type',
... vocabulary='eea.faceted.vocabularies.FacetedPortalTypes',
... catalog='portal_catalog',
... maxitems=4, hidden='1'
... )
>>> criterion = ICriteria(sandbox).get('c1')
>>> criterion.get('title')
u'Check boxes'
>>> criterion.hidden
True
>>> criterion.get('maxitems')
4
Delete criteria
---------------
>>> ICriteria(sandbox).delete('c0')
>>> ICriteria(sandbox).delete('c1')
>>> ICriteria(sandbox).delete('c2')
>>> ICriteria(sandbox).keys()
['c3', 'c4', 'c5', 'c6', 'c7']
Move up/down
------------
>>> ICriteria(sandbox).down('c4')
>>> ICriteria(sandbox).up('c5')
>>> ICriteria(sandbox).keys()
['c5', 'c3', 'c4', 'c6', 'c7']
Change position
---------------
>>> ICriteria(sandbox).position(
... top=['c7', 'c6'],
... left=['c5', 'c4'],
... center=['c3'],
... right=[]
... )
>>> ICriteria(sandbox).keys()
['c7', 'c6', 'c5', 'c4', 'c3']
>>> ICriteria(sandbox).get('c4').get('position')
u'left'