Changeset 4272 for waeup/branches
- Timestamp:
- 13 Jun 2009, 10:38:07 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/browser.txt
r4232 r4272 115 115 >>> browser.getLink('Data Center').click() 116 116 117 By default we have a directory in the sources for upload: 117 Setting the file path 118 --------------------- 119 120 A datacenter stores files in a path in filesystem. By default this is 121 a directory in the sources: 118 122 119 123 >>> print browser.contents … … 123 127 ... 124 128 129 Going to 'Settings` we can change the path: 130 131 >>> browser.getLink('Settings').click() 132 >>> pathsetting = browser.getControl(name='newpath') 133 134 We create a directory and set it as our upload path: 135 136 >>> import os 137 >>> cwd = os.getcwd() 138 >>> uploadpath = os.path.join(cwd, 'testfiles') 139 >>> os.mkdir(uploadpath) 140 >>> pathsetting.value = uploadpath 141 142 And submit the form: 143 144 >>> browser.getControl(name='save').click() 145 146 We clean up the set directory path, as there might be some files be 147 copied some files from installation: 148 149 >>> files = os.listdir(uploadpath) 150 >>> for filename in files: 151 ... os.unlink(os.path.join(uploadpath, filename)) 152 153 The new upload directory is now empty: 154 155 >>> os.listdir(uploadpath) 156 [] 157 158 Now we can upload files. Most interesting files might be CSV files, 159 that can be imported lateron. We create a CSV file containing faculty 160 descriptions: 161 162 >>> open('faculties.csv', 'wb').write( 163 ... """code,title,title_prefix 164 ... FA,Arts,Faculty 165 ... FS,Sciences,Faculty 166 ... """) 167 168 Now we can upload this file. To do this, we first go to the upload 169 page: 170 171 >>> browser.getLink('Upload data').click() 172 173 and enter the appropriate data in the form: 174 175 >>> filewidget = browser.getControl(name='uploadfile:file') 176 >>> filewidget 177 <Control name='uploadfile:file' type='file'> 178 179 A sidenote for developers: by marking the filewidget with the 180 ``:file`` extension, we tell Zope to handle this field as a file 181 widget. 182 183 >>> import cStringIO 184 >>> filecontents = cStringIO.StringIO( 185 ... open('faculties.csv', 'rb').read()) 186 >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv') 187 188 >>> browser.getControl(name='SUBMIT').click() 189 190 The file was indeed uploaded: 191 192 >>> os.listdir(uploadpath) 193 ['myfaculties.csv'] 194 195 Clean up: 196 197 >>> import os 198 >>> import shutil 199 >>> shutil.rmtree(uploadpath)
Note: See TracChangeset for help on using the changeset viewer.