This repository was archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.txt
More file actions
198 lines (151 loc) · 5.82 KB
/
Copy pathREADME.txt
File metadata and controls
198 lines (151 loc) · 5.82 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
===============================
Checkin/Checkout User-Interface
===============================
Create a browser first:
>>> from zope.testbrowser.testing import Browser
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic user:userpw')
Checkout
========
Checkout is possible for Repository content. Let's open a dockument in the
repository and look at its `metadata_preview` page. We do have a checkout link
but no checkin link:
>>> browser.open('http://localhost/++skin++cms/repository/online/'
... '2007/01/rauchen-verbessert-die-welt/metadata_preview')
>>> checkout = browser.getLink('Checkout')
>>> checkout
<Link text='[IMG] Checkout...>
The url has information about the view where the link was generated from:
>>> checkout.url
'http://localhost/.../rauchen-verbessert-die-welt/@@checkout?came_from=metadata_preview'
>>> browser.getLink('Checkin')
Traceback (most recent call last):
...
LinkNotFoundError
Check the document out by clicking on the link:
>>> checkout.click()
>>> print browser.contents
<?xml version...
<!DOCTYPE ...
<li class="message">"rauchen-verbessert-die-welt" has been checked out.</li>
...
Unbekannte Resource...
Checkin
=======
After checking out we see the checked out document and can check it in again.
There is of course no checkout button any more:
>>> checkout = browser.getLink('Checkout')
Traceback (most recent call last):
...
LinkNotFoundError
The checkin link also indicates the ``came_from`` view:
>>> browser.getLink('Checkin').url
'http://localhost/++skin++cms/workingcopy/zope.user/rauchen-verbessert-die-welt/@@checkin?came_from=view.html&semantic_change=None'
>>> browser.getLink('Checkin').click()
>>> browser.url
'http://localhost/++skin++cms/repository/online/2007/01/rauchen-verbessert-die-welt/@@view.html'
>>> print browser.contents
<?xml version...
<!DOCTYPE ...
<li class="message">"rauchen-verbessert-die-welt" has been checked in.</li>
...
The checkin default action does not update the "last semantic change" setting:
>>> import zope.app.component.hooks
>>> old_site = zope.app.component.hooks.getSite()
>>> zope.app.component.hooks.setSite(getRootFolder())
>>> import zope.component
>>> import zeit.cms.repository.interfaces
>>> repository = zope.component.getUtility(
... zeit.cms.repository.interfaces.IRepository)
>>> import zeit.cms.content.interfaces
>>> sc = zeit.cms.content.interfaces.ISemanticChange(
... repository['online']['2007']['01']['rauchen-verbessert-die-welt'])
>>> last_change = sc.last_semantic_change
>>> print last_change
None
>>> zope.app.component.hooks.setSite(old_site)
Getting the right tab after checkout and checkin
================================================
Checkout and checkin try to redirect to a meaningful view after the
checkout/checkin has happend.
Checkout adapts the context to IEditViewName and uses the resulting view name
as new view. If there is no adapter, 'edit.html' is used; we've seen this
above.
Register an adapter from 'view.html' to 'foobar.html':
>>> import zope.component
>>> import zeit.cms.browser.interfaces
>>> gsm = zope.component.getGlobalSiteManager()
>>> def view_foobar(context):
... return 'foobar.html'
>>> gsm.registerAdapter(
... view_foobar,
... (zope.interface.Interface,),
... zeit.cms.browser.interfaces.IEditViewName,
... name='view.html')
Since the foobar view doesn't actually exist we'll get an error:
>>> browser.open(browser.url)
>>> browser.handleErrors = False
>>> browser.getLink('Checkout').click()
Traceback (most recent call last):
...
NotFound:
Object: <zeit.cms.repository.unknown.PersistentUnknownResource...>,
name: u'@@foobar.html'
Clean up the adpater:
>>> gsm.unregisterAdapter(
... view_foobar,
... (zope.interface.Interface,),
... zeit.cms.browser.interfaces.IEditViewName,
... name='view.html')
True
The checkin view adapts the context to IDisplayViewName instead of
IEditViewName.
>>> def edit_foobar(context):
... return 'foobar.html'
>>> gsm.registerAdapter(
... edit_foobar,
... (zope.interface.Interface,),
... zeit.cms.browser.interfaces.IDisplayViewName,
... name='view.html')
Open the object checked out before and check it in. Checking in also results in
an error because the foobar view still doesn't exist:
>>> browser.open(
... 'http://localhost/++skin++cms/workingcopy/zope.user/'
... 'rauchen-verbessert-die-welt/@@view.html')
>>> browser.getLink('Checkin').click()
Traceback (most recent call last):
...
NotFound:
Object: <zeit.cms.repository.unknown.PersistentUnknownResource...>,
name: u'@@foobar.html'
Clean up the adapter:
>>> gsm.unregisterAdapter(
... edit_foobar,
... (zope.interface.Interface,),
... zeit.cms.browser.interfaces.IDisplayViewName,
... name='view.html')
True
>>> browser.handleErrors = True
Faking redirects
================
For javascript, we provide a variant that does not redirect but instead returns
the URL. It also does not do any view calculation but returns the base URL of
the freshly checked-out/-in object:
>>> browser.open('http://localhost/++skin++cms/repository/online/'
... '2007/01/Somalia/@@checkout?redirect=False')
>>> url = browser.contents
>>> url
'http://localhost/++skin++cms/workingcopy/zope.user/Somalia'
>>> browser.open(url + '/@@checkin?redirect=False&event=')
>>> browser.contents
'http://localhost/++skin++cms/repository/online/2007/01/Somalia'
Checking out already checked-out objects
========================================
Instead of throwing an error, the @@checkout view just redirects to the already
checked-out object:
>>> browser.open('http://localhost/++skin++cms/repository/online/'
... '2007/01/Somalia/@@checkout')
>>> browser.open('http://localhost/++skin++cms/repository/online/'
... '2007/01/Somalia/@@checkout')
>>> print browser.url
http://localhost/++skin++cms/workingcopy/zope.user/Somalia/@@view.html