File: forms.txt

package info (click to toggle)
zope-cmfplone 2.5.1-4etch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,752 kB
  • ctags: 5,237
  • sloc: python: 28,264; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (144 lines) | stat: -rw-r--r-- 4,861 bytes parent folder | download | duplicates (2)
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
This is a test suite to make sure that editing of objects works as expected:

Import the user's name and password:

  >>> from Products.PloneTestCase.PloneTestCase import default_user
  >>> from Products.PloneTestCase.PloneTestCase import default_password

Get the portal and the home paths:

  >>> portal_path = '/'.join(self.portal.getPhysicalPath())
  >>> folder_path = '/'.join(self.folder.getPhysicalPath())

Let's create a page to play with:

  >>> folder.invokeFactory('Document', 'test-page', title='My Title')
  'test-page'

Let's edit our test page, but leave off some required fields:

  >>> edit_path = folder_path + '/test-page/atct_edit'
  >>> print http(r"""
  ... POST %s HTTP/1.1
  ... Authorization: Basic %s:%s
  ... Content-Type: multipart/form-data; boundary=---------------------------6981500387474556631359179914
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="id"
  ...
  ... test-page
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="title"
  ...
  ...
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="description"
  ...
  ...
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="description_text_format"
  ...
  ... text/plain
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="text"
  ...
  ... <p>a</p>
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="allowDiscussion"
  ...
  ... None
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="fieldset"
  ...
  ... default
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="form.submitted"
  ...
  ... 1
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="form_submit"
  ...
  ... Save
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="text_text_format"
  ...
  ... text/html
  ... -----------------------------6981500387474556631359179914--
  ... """ % (edit_path, default_user, default_password),
  ...        handle_errors=False)
  HTTP/1.1 200 OK...
  <h1> Edit ...Page... </h1>...
  <div class="field error ArchetypesStringWidget"...
  <div>Title is required, please correct.</div>
  <input...type="text"...name="title"...value="My Title".../>...
  <input...type="submit"...name="form_submit"...value="Save".../>...

No changes should have been made:
  >>> obj = folder['test-page']
  >>> obj.Title()
  'My Title'
  >>> obj.Description()
  ''
  >>> obj.getText()
  ''

And let's edit it properly:

  >>> print http(r"""
  ... POST %s HTTP/1.1
  ... Authorization: Basic %s:%s
  ... Content-Type: multipart/form-data; boundary=---------------------------6981500387474556631359179914
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="id"
  ...
  ... test-page
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="title"
  ...
  ... My Title 2
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="description"
  ...
  ... A description
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="description_text_format"
  ...
  ... text/plain
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="text"
  ...
  ... <p>a</p>
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="allowDiscussion"
  ...
  ... None
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="fieldset"
  ...
  ... default
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="form.submitted"
  ...
  ... 1
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="form_submit"
  ...
  ... Save
  ... -----------------------------6981500387474556631359179914
  ... Content-Disposition: form-data; name="text_text_format"
  ...
  ... text/html
  ... -----------------------------6981500387474556631359179914--
  ... """ % (edit_path, default_user, default_password),
  ...        handle_errors=False)
  HTTP/1.1 302 Moved Temporarily
  ...
  Location: ...test-page?portal_status_message=Changes%20saved.

Let's make sure our changes were applied:

  >>> obj = folder['test-page']
  >>> obj.Title()
  'My Title 2'
  >>> obj.getText().strip()
  '<p>a</p>'