[7819] | 1 | Browsing Kofa |
---|
[7321] | 2 | ************* |
---|
[6607] | 3 | |
---|
[12912] | 4 | Here we visit parts of a Kofa portal using a browser. |
---|
[6607] | 5 | |
---|
| 6 | University |
---|
| 7 | ========== |
---|
| 8 | |
---|
| 9 | We can watch universities in the browser. |
---|
| 10 | |
---|
| 11 | We create an university object and put into the ZODB root:: |
---|
| 12 | |
---|
| 13 | >>> root = getRootFolder() |
---|
| 14 | >>> list(root) |
---|
| 15 | [] |
---|
| 16 | |
---|
[7811] | 17 | >>> from waeup.kofa.app import University |
---|
[6607] | 18 | >>> u = University() |
---|
| 19 | >>> root['myuniversity'] = u |
---|
| 20 | >>> list(root) |
---|
| 21 | [u'myuniversity'] |
---|
| 22 | |
---|
| 23 | >>> from zope.component.hooks import setSite |
---|
| 24 | >>> setSite(root['myuniversity']) |
---|
| 25 | |
---|
[6609] | 26 | To make sure, we can 'watch' pages, we first have to initialize out |
---|
| 27 | test browser:: |
---|
| 28 | |
---|
| 29 | >>> from zope.testbrowser.testing import Browser |
---|
| 30 | >>> browser = Browser() |
---|
| 31 | |
---|
[11254] | 32 | Let's get the default view of a university:: |
---|
[6607] | 33 | |
---|
| 34 | >>> browser.open('http://localhost/myuniversity') |
---|
| 35 | >>> print browser.contents |
---|
| 36 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7819] | 37 | ...Welcome to WAeUP.Kofa... |
---|
[6607] | 38 | ... |
---|
| 39 | |
---|
[7674] | 40 | We can change to German:: |
---|
[12912] | 41 | |
---|
[7674] | 42 | >>> browser.getLink('de').click() |
---|
| 43 | >>> print browser.contents |
---|
| 44 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 45 | ...Anfragen... |
---|
| 46 | ... |
---|
| 47 | |
---|
| 48 | And then change back to English by clicking on the third link containing 'en' |
---|
| 49 | behind 'Anfragen' and 'Einloggen':: |
---|
[12912] | 50 | |
---|
[7674] | 51 | >>> browser.getLink('en', index=2).click() |
---|
| 52 | >>> print browser.contents |
---|
| 53 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 54 | ...Enquiries... |
---|
| 55 | ... |
---|
| 56 | |
---|
[6609] | 57 | The contact form for anonymous users is called 'Enquiries':: |
---|
[6607] | 58 | |
---|
[6609] | 59 | >>> browser.open('http://localhost/myuniversity') |
---|
| 60 | >>> browser.getLink('Enquiries').click() |
---|
[7225] | 61 | >>> browser.getControl('Send').click() |
---|
[6609] | 62 | >>> print browser.contents |
---|
| 63 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7234] | 64 | ...Required input is missing... |
---|
[6609] | 65 | ... |
---|
| 66 | |
---|
[7225] | 67 | >>> browser.getControl(name='form.fullname').value = "Bob Tester" |
---|
| 68 | >>> browser.getControl(name='form.email_from').value = "xx@yy.zz" |
---|
[7401] | 69 | >>> browser.getControl(name='form.body').value = u'test message' |
---|
[7225] | 70 | >>> browser.getControl('Send').click() |
---|
[6611] | 71 | >>> print browser.contents |
---|
| 72 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 73 | ...Your message has been sent... |
---|
[6611] | 74 | ... |
---|
| 75 | |
---|
[8364] | 76 | Registered users with an email address can request a password change: |
---|
| 77 | |
---|
| 78 | >>> root['myuniversity']['users'].addUser('forgetful', 'secret',title='Bob Forgetful', |
---|
| 79 | ... description='A forgetful user', email='aa@aa.ng') |
---|
[8777] | 80 | >>> browser.open('http://localhost/myuniversity/changepw') |
---|
[8364] | 81 | >>> browser.getControl(name="form.identifier").value = 'forgetful' |
---|
| 82 | >>> browser.getControl(name="form.email").value = 'aa@aa.ng' |
---|
[9178] | 83 | >>> browser.getControl("Send login credentials").click() |
---|
[8364] | 84 | >>> print browser.contents |
---|
| 85 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 86 | ...An email with your user name and password has been sent to aa@aa.ng... |
---|
| 87 | |
---|
[6609] | 88 | Now we login as manager:: |
---|
| 89 | |
---|
| 90 | >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
| 91 | >>> browser.handleErrors = False |
---|
| 92 | |
---|
[6907] | 93 | We can then get an edit view of the configuration container:: |
---|
[6609] | 94 | |
---|
[6907] | 95 | >>> browser.open('http://localhost/myuniversity/configuration') |
---|
[6607] | 96 | >>> print browser.contents |
---|
| 97 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[6907] | 98 | ...<form action="http://localhost/myuniversity/configuration/@@index" |
---|
[6607] | 99 | ... |
---|
| 100 | |
---|
| 101 | The edit form contains the default value for the university name:: |
---|
| 102 | |
---|
| 103 | >>> 'Sample University' in browser.contents |
---|
| 104 | True |
---|
[7208] | 105 | |
---|
[6607] | 106 | We can perform several actions on the edit form:: |
---|
| 107 | |
---|
| 108 | >>> browser.getControl("Save", index=0).click() |
---|
| 109 | >>> print browser.contents |
---|
| 110 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[8739] | 111 | ...Form has been saved... |
---|
[6607] | 112 | ... |
---|
| 113 | |
---|
[6907] | 114 | >>> browser.open('http://localhost/myuniversity/configuration') |
---|
[6607] | 115 | >>> browser.getControl("Update plugins").click() |
---|
| 116 | >>> print browser.contents |
---|
| 117 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 118 | ...Plugins were updated. See log file for details... |
---|
[6607] | 119 | ... |
---|
| 120 | |
---|
[8364] | 121 | The default frontpage HTML has been saved in a dictionary |
---|
[7704] | 122 | and is properly rendered on the frontpage of the portal: |
---|
| 123 | |
---|
| 124 | >>> browser.open('http://localhost/myuniversity') |
---|
| 125 | >>> print browser.contents |
---|
| 126 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[8364] | 127 | ...<h1>Welcome to WAeUP.Kofa...</h1> |
---|
[7704] | 128 | ... |
---|
| 129 | |
---|
| 130 | The German part is really not being rendered: |
---|
| 131 | |
---|
| 132 | >>> 'Willkommen' in browser.contents |
---|
| 133 | False |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | If we change to German so that the German part of frontpage.rst is rendered: |
---|
| 137 | |
---|
| 138 | >>> browser.open('http://localhost/myuniversity//@@change_language?lang=de') |
---|
| 139 | >>> print browser.contents |
---|
| 140 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[8364] | 141 | ...<h1>Willkommen auf WAeUP.Kofa...</h1> |
---|
[7704] | 142 | ... |
---|
| 143 | |
---|
| 144 | The English part is really not being rendered: |
---|
| 145 | |
---|
| 146 | >>> 'Welcome' in browser.contents |
---|
| 147 | False |
---|
| 148 | |
---|
| 149 | Switch back to English: |
---|
| 150 | |
---|
| 151 | >>> browser.open('http://localhost/myuniversity//@@change_language?lang=en') |
---|
| 152 | |
---|
[6607] | 153 | We can export a university as XML:: |
---|
| 154 | |
---|
| 155 | >>> browser.open('http://localhost/myuniversity/export.xml') |
---|
| 156 | >>> print browser.contents |
---|
| 157 | <?xml version="1.0" encoding="utf-8" ?> |
---|
| 158 | <pickle> |
---|
| 159 | ... |
---|
| 160 | </pickle> |
---|
| 161 | |
---|
| 162 | >>> print browser.headers |
---|
| 163 | Status: 200 Ok |
---|
| 164 | Content-Length: ... |
---|
| 165 | Content-Type: text/xml; charset=UTF-8 |
---|
| 166 | X-Powered-By: Zope (www.zope.org), Python (www.python.org) |
---|
| 167 | |
---|
| 168 | |
---|
[12912] | 169 | Officers |
---|
| 170 | ======== |
---|
[6607] | 171 | |
---|
| 172 | >>> browser.open('http://localhost/myuniversity') |
---|
[12912] | 173 | >>> browser.getLink('Officers').click() |
---|
[6607] | 174 | >>> print browser.contents |
---|
| 175 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[12912] | 176 | ...Officers... |
---|
[6607] | 177 | ... |
---|
| 178 | |
---|
[12912] | 179 | We can add officers: |
---|
[6607] | 180 | |
---|
[12919] | 181 | >>> browser.getLink("Add officer").click() |
---|
[6607] | 182 | >>> browser.getControl(name="form.name").value = 'bob' |
---|
[8759] | 183 | >>> browser.getControl(name="form.title").value = 'Bob The User' |
---|
[7149] | 184 | >>> browser.getControl(name="password").value = 'secret' |
---|
| 185 | >>> browser.getControl(name="control_password").value = 'secret' |
---|
[7222] | 186 | >>> browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
[7869] | 187 | >>> browser.getControl(name="form.phone.country").value = ['+234'] |
---|
| 188 | >>> browser.getControl(name="form.phone.area").value = '123' |
---|
| 189 | >>> browser.getControl(name="form.phone.ext").value = '45678' |
---|
[12919] | 190 | >>> browser.getControl("Add officer").click() |
---|
[6607] | 191 | >>> print browser.contents |
---|
| 192 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 193 | ...<td>bob</td> |
---|
| 194 | ... |
---|
| 195 | |
---|
| 196 | We can edit user bob: |
---|
| 197 | |
---|
[7707] | 198 | >>> browser.getControl("Manage", index=0).click() |
---|
[6607] | 199 | >>> browser.getControl("Save", index=0).click() |
---|
| 200 | >>> browser.getControl("Cancel", index=0).click() |
---|
| 201 | |
---|
[7178] | 202 | We can add site roles which are then displayed on the user container page. |
---|
| 203 | Since the test browser does not use javascript, we have to add site roles |
---|
[6607] | 204 | manually by setting the roles attribute: |
---|
| 205 | |
---|
| 206 | >>> print root['myuniversity']['users']['bob'].roles |
---|
| 207 | [] |
---|
[7185] | 208 | >>> root['myuniversity']['users']['bob'].roles = ['waeup.ApplicationsOfficer'] |
---|
[6607] | 209 | >>> print root['myuniversity']['users']['bob'].roles |
---|
[7185] | 210 | ['waeup.ApplicationsOfficer'] |
---|
[6607] | 211 | >>> browser.open('http://localhost/myuniversity/users') |
---|
| 212 | >>> print browser.contents |
---|
| 213 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[10226] | 214 | ...<td nowrap>Applications Officer (view only) <br /></td> |
---|
[6607] | 215 | ... |
---|
| 216 | |
---|
[12912] | 217 | Officers can't be added twice: |
---|
[6607] | 218 | |
---|
[6608] | 219 | >>> browser.open('http://localhost/myuniversity/users/add') |
---|
| 220 | >>> browser.getControl(name="form.name").value = 'bob' |
---|
[8759] | 221 | >>> browser.getControl(name="form.title").value = 'Bob The User' |
---|
[7149] | 222 | >>> browser.getControl(name="password").value = 'secret' |
---|
| 223 | >>> browser.getControl(name="control_password").value = 'secret' |
---|
[7222] | 224 | >>> browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
[7869] | 225 | >>> browser.getControl(name="form.phone.country").value = ['+234'] |
---|
| 226 | >>> browser.getControl(name="form.phone.area").value = '123' |
---|
| 227 | >>> browser.getControl(name="form.phone.ext").value = '45678' |
---|
[12919] | 228 | >>> browser.getControl("Add officer").click() |
---|
[6608] | 229 | >>> 'The userid chosen already exists' in browser.contents |
---|
| 230 | True |
---|
| 231 | |
---|
[12912] | 232 | Officers can be deleted: |
---|
[6608] | 233 | |
---|
| 234 | >>> browser.open('http://localhost/myuniversity/users') |
---|
[8364] | 235 | >>> browser.getControl("Remove", index=0).click() |
---|
[7657] | 236 | >>> 'User account bob successfully deleted' in browser.contents |
---|
[6608] | 237 | True |
---|
| 238 | |
---|
| 239 | |
---|
[8364] | 240 | |
---|
[6607] | 241 | Contact Form |
---|
| 242 | ============ |
---|
| 243 | |
---|
| 244 | Let's enter the contact form:: |
---|
| 245 | |
---|
| 246 | >>> browser.open('http://localhost/myuniversity/contactadmin') |
---|
| 247 | >>> print browser.contents |
---|
| 248 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[6647] | 249 | ...Contact |
---|
[6607] | 250 | ... |
---|
| 251 | |
---|
[7234] | 252 | We fill the form (this will send a real message to |
---|
| 253 | contact@waeup.org):: |
---|
[6607] | 254 | |
---|
| 255 | >>> browser.open('http://localhost/myuniversity/contactadmin') |
---|
[7225] | 256 | >>> browser.getControl(name='form.body').value = "test message" |
---|
| 257 | >>> browser.getControl('Send').click() |
---|
[7208] | 258 | >>> print browser.contents |
---|
[6607] | 259 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 260 | ...Your message has been sent... |
---|
[6607] | 261 | ... |
---|
| 262 | |
---|
[7234] | 263 | If this test fails, chances are, that the local machine has no SMTP |
---|
| 264 | server installed. |
---|
[6607] | 265 | |
---|
| 266 | |
---|
[7234] | 267 | |
---|
[6607] | 268 | Faculties |
---|
| 269 | ========= |
---|
| 270 | |
---|
| 271 | Faculties are stored in a special container of `IUniversity` |
---|
| 272 | instances. The container is called ``faculties`` and provides an |
---|
| 273 | add-form to add new faculties:: |
---|
| 274 | |
---|
[6611] | 275 | >>> browser.open('http://localhost/myuniversity/faculties/manage') |
---|
| 276 | >>> browser.getControl('Add faculty').click() |
---|
[6607] | 277 | >>> print browser.contents |
---|
| 278 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 279 | ...*... |
---|
[6607] | 280 | ...<span>Name of faculty</span>: |
---|
| 281 | ... |
---|
[6611] | 282 | >>> browser.getControl('Cancel').click() |
---|
| 283 | >>> browser.open('http://localhost/myuniversity/faculties/add') |
---|
[7208] | 284 | |
---|
[6607] | 285 | We fill in a new name for our new faculty:: |
---|
| 286 | |
---|
| 287 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 288 | >>> ctrl.value = 'TestFac' |
---|
| 289 | |
---|
| 290 | Furthermore we add a prefix and a code (kind of abbreviation): |
---|
| 291 | |
---|
| 292 | >>> browser.getControl(name='form.code').value = 'TF' |
---|
| 293 | |
---|
| 294 | Finally we click on 'Add Faculty' to add the new thing:: |
---|
| 295 | |
---|
| 296 | >>> browser.getControl('Add faculty').click() |
---|
| 297 | |
---|
| 298 | We can view a faculty by browsing a URL like this:: |
---|
| 299 | |
---|
| 300 | >>> browser.open('http://localhost/myuniversity/faculties/TF') |
---|
| 301 | |
---|
| 302 | Afterwards, the faculty should be visible: |
---|
| 303 | |
---|
| 304 | >>> browser.open('http://localhost/myuniversity/faculties') |
---|
| 305 | >>> print browser.contents |
---|
| 306 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
[10207] | 307 | ...<h1 class="kofa-content-label">Academic Section</h1> |
---|
[11254] | 308 | ...<td> <a href="http://localhost/myuniversity/faculties/TF"> <span>TF</span></a></td> |
---|
[6607] | 309 | ... |
---|
| 310 | |
---|
| 311 | We can 'visit' each faculty by clicking on the appropriate link: |
---|
| 312 | |
---|
| 313 | >>> browser.getLink('TF').click() |
---|
| 314 | >>> print browser.contents |
---|
| 315 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[6647] | 316 | ...Faculty of TestFac (TF)... |
---|
[6607] | 317 | ... |
---|
| 318 | |
---|
[6611] | 319 | If we add the same faculty twice, an error message will occur: |
---|
| 320 | |
---|
| 321 | >>> browser.open('http://localhost/myuniversity/faculties/add') |
---|
| 322 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 323 | >>> ctrl.value = 'TestFac' |
---|
| 324 | >>> browser.getControl(name='form.code').value = 'TF' |
---|
| 325 | >>> browser.getControl('Add faculty').click() |
---|
| 326 | >>> 'The faculty code chosen already exists.' in browser.contents |
---|
| 327 | True |
---|
| 328 | |
---|
[6607] | 329 | Modifying faculties |
---|
| 330 | ------------------- |
---|
| 331 | |
---|
| 332 | A faculty can directly be reached by its code: |
---|
| 333 | |
---|
| 334 | >>> browser.open('http://localhost/myuniversity/faculties/TF') |
---|
| 335 | |
---|
| 336 | We can change the settings for a faculty by clicking on the |
---|
| 337 | provided 'Manage faculty' button: |
---|
| 338 | |
---|
| 339 | >>> browser.getLink('Manage faculty').click() |
---|
| 340 | |
---|
| 341 | Let's set a new title and save the form: |
---|
| 342 | |
---|
| 343 | >>> browser.getControl(name='form.title').value = "My renamed faculty" |
---|
| 344 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 345 | |
---|
| 346 | Our faculty was indeed renamed to ``My renamed faculty``: |
---|
| 347 | |
---|
| 348 | >>> browser.open('http://localhost/myuniversity/faculties') |
---|
| 349 | >>> print browser.contents |
---|
| 350 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[10207] | 351 | ...<h1 class="kofa-content-label">Academic Section</h1> |
---|
[11254] | 352 | ...<td> <a href="http://localhost/myuniversity/faculties/TF"> <span>TF</span></a></td> |
---|
[6607] | 353 | ...<td>Faculty of My renamed faculty (TF)</td> |
---|
| 354 | ... |
---|
| 355 | |
---|
[6608] | 356 | We can grant local roles: |
---|
[6607] | 357 | |
---|
[6608] | 358 | >>> root['myuniversity']['users'].addUser('bob', 'secret',title='Bob', |
---|
| 359 | ... description='A sample user') |
---|
| 360 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 361 | >>> browser.getControl(name="user").value = ['bob'] |
---|
[7208] | 362 | >>> browser.getControl( |
---|
| 363 | ... name="local_role").value = ['waeup.local.DepartmentManager'] |
---|
[6608] | 364 | >>> browser.getControl("Add local role").click() |
---|
| 365 | >>> print browser.contents |
---|
| 366 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 367 | ...<td>bob</td> |
---|
| 368 | ... |
---|
| 369 | |
---|
[12912] | 370 | On the officers page the new local role is displayed: |
---|
[6608] | 371 | |
---|
[12912] | 372 | >>> browser.getLink("Officers").click() |
---|
[6608] | 373 | >>> print browser.contents |
---|
| 374 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7185] | 375 | ...<td>Department Manager:... |
---|
[6608] | 376 | ... |
---|
| 377 | |
---|
| 378 | The local role can be removed again: |
---|
| 379 | |
---|
| 380 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 381 | >>> ctrl = browser.getControl(name='role_id') |
---|
| 382 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 383 | >>> print browser.contents |
---|
| 384 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 385 | ...No local role selected... |
---|
| 386 | ... |
---|
| 387 | |
---|
| 388 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 389 | >>> ctrl = browser.getControl(name='role_id') |
---|
[7185] | 390 | >>> ctrl.getControl(value='bob|waeup.local.DepartmentManager').selected = True |
---|
[6608] | 391 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 392 | >>> print browser.contents |
---|
| 393 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7700] | 394 | ...Local role successfully removed... |
---|
[6608] | 395 | ... |
---|
| 396 | |
---|
| 397 | Deleting faculties |
---|
| 398 | ------------------ |
---|
| 399 | |
---|
| 400 | >>> browser.open('http://localhost/myuniversity/faculties/manage') |
---|
| 401 | >>> browser.getControl('Cancel').click() |
---|
| 402 | >>> print browser.url |
---|
| 403 | http://localhost/myuniversity/faculties |
---|
| 404 | >>> browser.getLink('Manage academic section').click() |
---|
| 405 | >>> browser.getControl('Add faculty').click() |
---|
| 406 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 407 | >>> ctrl.value = 'Second Faculty' |
---|
| 408 | >>> browser.getControl(name='form.code').value = 'TF2' |
---|
| 409 | >>> browser.getControl('Add faculty').click() |
---|
| 410 | >>> browser.open('http://localhost/myuniversity/faculties/manage') |
---|
| 411 | >>> browser.getControl("Remove selected", index=0).click() |
---|
[6917] | 412 | >>> 'No item selected' in browser.contents |
---|
[6608] | 413 | True |
---|
| 414 | >>> browser.open('http://localhost/myuniversity/faculties/manage') |
---|
| 415 | >>> ctrl = browser.getControl(name='val_id') |
---|
| 416 | >>> ctrl.getControl(value='TF2').selected = True |
---|
| 417 | >>> browser.getControl("Remove selected", index=0).click() |
---|
| 418 | >>> print browser.contents |
---|
| 419 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 420 | ...Successfully removed:... |
---|
| 421 | ... |
---|
| 422 | |
---|
[6607] | 423 | Departments |
---|
| 424 | =========== |
---|
| 425 | |
---|
| 426 | Adding departments |
---|
| 427 | ------------------ |
---|
| 428 | |
---|
| 429 | Departments are stored in :class:`IFaculty` instances with their code |
---|
| 430 | as key. Faculties therefore are also department containers. Faculties |
---|
| 431 | provides an add-form to add new departments: |
---|
| 432 | |
---|
| 433 | >>> browser.open('http://localhost/myuniversity/faculties/TF/add') |
---|
| 434 | >>> print browser.contents |
---|
| 435 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 436 | ...*</span> |
---|
[6607] | 437 | ...<span>Name of department</span>: |
---|
| 438 | ... |
---|
[6611] | 439 | >>> browser.getControl('Cancel').click() |
---|
| 440 | >>> browser.open('http://localhost/myuniversity/faculties/TF/add') |
---|
[6607] | 441 | |
---|
| 442 | We fill in a new name for our new department: |
---|
| 443 | |
---|
| 444 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 445 | >>> ctrl.value = 'TestDept' |
---|
| 446 | |
---|
| 447 | Furthermore we add a code (kind of abbreviation): |
---|
| 448 | |
---|
| 449 | >>> browser.getControl(name='form.code').value = 'TD' |
---|
| 450 | |
---|
| 451 | Finally we click on 'Add Department' to add the new thing:: |
---|
| 452 | |
---|
| 453 | >>> browser.getControl('Add department').click() |
---|
| 454 | |
---|
| 455 | If we try to register a department under the same code twice we will |
---|
| 456 | get an error: |
---|
| 457 | |
---|
| 458 | >>> browser.open('http://localhost/myuniversity/faculties/TF/add') |
---|
| 459 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 460 | >>> ctrl.value = 'Another TestDept with same code' |
---|
| 461 | >>> browser.getControl(name='form.code').value = 'TD' |
---|
| 462 | >>> browser.getControl('Add department').click() |
---|
| 463 | >>> print browser.contents |
---|
| 464 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 465 | ...The code chosen already exists in this faculty... |
---|
[6607] | 466 | ... |
---|
| 467 | |
---|
[6609] | 468 | We can view a department by browsing a URL like this:: |
---|
[6607] | 469 | |
---|
| 470 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD') |
---|
| 471 | |
---|
[6609] | 472 | Afterwards, the department should be visible:: |
---|
[6607] | 473 | |
---|
| 474 | >>> browser.open('http://localhost/myuniversity/faculties/TF') |
---|
| 475 | >>> print browser.contents |
---|
| 476 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[10207] | 477 | ...<h1 class="kofa-content-label">Departments</h1> |
---|
[11254] | 478 | ...<td> <a href="http://localhost/myuniversity/faculties/TF/TD"> <span>TD</span></a></td> |
---|
[6607] | 479 | ...<td>Department of TestDept (TD)</td> |
---|
| 480 | ... |
---|
| 481 | |
---|
| 482 | |
---|
| 483 | Modifying departments |
---|
| 484 | --------------------- |
---|
| 485 | |
---|
| 486 | We can change the settings for a department by clicking on the |
---|
| 487 | provided 'Edit department' button: |
---|
| 488 | |
---|
| 489 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD') |
---|
| 490 | >>> browser.getLink('Manage department').click() |
---|
| 491 | |
---|
| 492 | Let's set a new title and save the form: |
---|
| 493 | |
---|
| 494 | >>> browser.getControl(name='form.title').value = "My test dept" |
---|
| 495 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 496 | |
---|
| 497 | Clicking 'Save' we will stay on the settings form. So we can change |
---|
[7208] | 498 | the department again. |
---|
[6607] | 499 | |
---|
| 500 | >>> browser.getControl(name='form.title').value = "My renamed dept" |
---|
| 501 | >>> ctrl = browser.getControl("Save") |
---|
| 502 | >>> ctrl.click() |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | Our department was indeed renamed to ``My renamed dept``: |
---|
| 506 | |
---|
| 507 | >>> browser.open('http://localhost/myuniversity/faculties/TF') |
---|
| 508 | >>> print browser.contents |
---|
| 509 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
[10207] | 510 | ...<h1 class="kofa-content-label">Departments</h1> |
---|
[11254] | 511 | ...<td> <a href="http://localhost/myuniversity/faculties/TF/TD"> <span>TD</span></a></td> |
---|
[6607] | 512 | ...<td>Department of My renamed dept (TD)</td> |
---|
| 513 | ... |
---|
| 514 | |
---|
[6613] | 515 | We can grant local roles: |
---|
| 516 | |
---|
| 517 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage') |
---|
| 518 | >>> browser.getControl(name="user").value = ['bob'] |
---|
[7208] | 519 | >>> browser.getControl( |
---|
| 520 | ... name="local_role").value = ['waeup.local.DepartmentManager'] |
---|
[6613] | 521 | >>> browser.getControl("Add local role").click() |
---|
| 522 | >>> print browser.contents |
---|
| 523 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 524 | ...<td>bob</td> |
---|
| 525 | ... |
---|
| 526 | |
---|
| 527 | The local role can be removed again: |
---|
| 528 | |
---|
| 529 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage') |
---|
| 530 | >>> ctrl = browser.getControl(name='role_id') |
---|
| 531 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 532 | >>> print browser.contents |
---|
| 533 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 534 | ...No local role selected... |
---|
| 535 | ... |
---|
| 536 | |
---|
| 537 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage') |
---|
| 538 | >>> ctrl = browser.getControl(name='role_id') |
---|
[7208] | 539 | >>> ctrl.getControl( |
---|
| 540 | ... value='bob|waeup.local.DepartmentManager').selected = True |
---|
[6613] | 541 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 542 | >>> print browser.contents |
---|
| 543 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7700] | 544 | ...Local role successfully removed... |
---|
[6613] | 545 | ... |
---|
| 546 | |
---|
[6608] | 547 | Deleting departments |
---|
| 548 | -------------------- |
---|
[6607] | 549 | |
---|
[6608] | 550 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 551 | >>> browser.getControl('Cancel', index=0).click() |
---|
| 552 | >>> print browser.url |
---|
| 553 | http://localhost/myuniversity/faculties/TF |
---|
| 554 | >>> browser.getLink('Manage faculty').click() |
---|
| 555 | >>> browser.getControl('Add department').click() |
---|
| 556 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 557 | >>> ctrl.value = 'Second Department' |
---|
| 558 | >>> browser.getControl(name='form.code').value = 'TD2' |
---|
| 559 | >>> browser.getControl('Add department').click() |
---|
| 560 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 561 | >>> browser.getControl("Remove selected", index=0).click() |
---|
[6917] | 562 | >>> 'No item selected' in browser.contents |
---|
[6608] | 563 | True |
---|
| 564 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 565 | >>> ctrl = browser.getControl(name='val_id') |
---|
| 566 | >>> ctrl.getControl(value='TD2').selected = True |
---|
| 567 | >>> browser.getControl("Remove selected", index=0).click() |
---|
| 568 | >>> print browser.contents |
---|
| 569 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 570 | ...Successfully removed:... |
---|
| 571 | ... |
---|
| 572 | |
---|
| 573 | |
---|
[6607] | 574 | Courses |
---|
| 575 | ======= |
---|
| 576 | |
---|
| 577 | Once we have a department, we can add courses. |
---|
| 578 | |
---|
| 579 | Adding courses |
---|
| 580 | -------------- |
---|
| 581 | |
---|
[7333] | 582 | Courses are stored in :class:`ICoursesContainer` instances with their |
---|
| 583 | code as key. CoursesContainers are normally availabe as `course` |
---|
[7811] | 584 | attribute of :class:`waeup.kofa.university.department.Department` |
---|
[6607] | 585 | instances. |
---|
| 586 | |
---|
[12912] | 587 | To ease the life of officers we do not require to browse the |
---|
[7333] | 588 | coursescontainers (which have a rather flat user interface), but |
---|
[6607] | 589 | provide adding of courses in department views. |
---|
| 590 | |
---|
| 591 | Each department provides a ``Add course`` action button near top. |
---|
| 592 | |
---|
| 593 | Departments provide an add-form to add new courses: |
---|
| 594 | |
---|
| 595 | >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD' |
---|
[6613] | 596 | >>> browser.open(dept_url + '/manage') |
---|
| 597 | >>> browser.getControl('Add course').click() |
---|
[6607] | 598 | >>> print browser.contents |
---|
| 599 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 600 | ...*</span> |
---|
[6607] | 601 | ...<span>Title of course</span>: |
---|
| 602 | ... |
---|
| 603 | |
---|
| 604 | We fill in a name for our new course: |
---|
| 605 | |
---|
| 606 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 607 | >>> ctrl.value = 'My Course 1' |
---|
| 608 | |
---|
| 609 | Furthermore we add a code (kind of abbreviation): |
---|
| 610 | |
---|
| 611 | >>> browser.getControl(name='form.code').value = 'COURSE1' |
---|
| 612 | |
---|
| 613 | This course will take place in the the first semester, so we set the |
---|
| 614 | `semester` value to 1: |
---|
| 615 | |
---|
| 616 | >>> ctrl = browser.getControl(name='form.semester') |
---|
| 617 | >>> ctrl.options |
---|
[7681] | 618 | ['1', '2', '3', '9'] |
---|
[6607] | 619 | |
---|
| 620 | >>> ctrl.displayOptions |
---|
[10438] | 621 | ['1st Semester', '2nd Semester', 'Combined', 'N/A'] |
---|
[6607] | 622 | |
---|
| 623 | >>> ctrl.value = ['1'] |
---|
| 624 | |
---|
| 625 | Finally, we create the course: |
---|
| 626 | |
---|
| 627 | >>> browser.getControl('Add course').click() |
---|
| 628 | |
---|
| 629 | If we try to register a course under the same code twice we will |
---|
| 630 | get an error: |
---|
| 631 | |
---|
| 632 | >>> browser.open(dept_url + '/addcourse') |
---|
| 633 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 634 | >>> ctrl.value = 'Another course with same code' |
---|
| 635 | >>> browser.getControl(name='form.code').value = 'COURSE1' |
---|
| 636 | >>> browser.getControl('Add course').click() |
---|
| 637 | >>> print browser.contents |
---|
| 638 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 639 | ...A course with same code already exists:... |
---|
[6607] | 640 | ... |
---|
| 641 | |
---|
| 642 | Our course will be linked under the code on the department page: |
---|
| 643 | |
---|
| 644 | >>> browser.open(dept_url) |
---|
| 645 | >>> browser.getLink('COURSE1').click() |
---|
| 646 | >>> browser.url |
---|
| 647 | 'http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1' |
---|
| 648 | |
---|
| 649 | Before we really add a course we can cancel the action and will be |
---|
| 650 | redirected to the department page: |
---|
| 651 | |
---|
| 652 | >>> browser.open(dept_url + '/addcourse') |
---|
| 653 | >>> browser.getControl('Cancel').click() |
---|
| 654 | >>> browser.url |
---|
| 655 | 'http://localhost/myuniversity/faculties/TF/TD' |
---|
| 656 | |
---|
| 657 | |
---|
| 658 | Modifying courses |
---|
| 659 | ----------------- |
---|
| 660 | |
---|
| 661 | We can change the settings for a course by clicking on the provided |
---|
| 662 | 'Edit settings' link: |
---|
| 663 | |
---|
| 664 | >>> browser.open(dept_url + '/courses/COURSE1') |
---|
| 665 | >>> browser.getLink('Edit course').click() |
---|
| 666 | |
---|
| 667 | When modifying a course, we cannot change the code any more: |
---|
| 668 | |
---|
| 669 | >>> browser.getControl(name='form.code') |
---|
| 670 | Traceback (most recent call last): |
---|
| 671 | ... |
---|
| 672 | LookupError: name 'form.code' |
---|
| 673 | |
---|
| 674 | Let's set a new title and save the form: |
---|
| 675 | |
---|
| 676 | >>> browser.getControl(name='form.title').value = "My test course" |
---|
| 677 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 678 | |
---|
| 679 | Clicking 'Save' we will stay on the settings form. So we can change |
---|
[7490] | 680 | the course again. If we click ``Cancel`` nothing will be |
---|
[6607] | 681 | changed: |
---|
| 682 | |
---|
| 683 | >>> browser.getControl(name='form.title').value = "Blah" |
---|
| 684 | >>> browser.getControl('Cancel').click() |
---|
| 685 | |
---|
[7490] | 686 | Our course was not renamed to ``Blah``: |
---|
[6607] | 687 | |
---|
| 688 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD') |
---|
| 689 | >>> print browser.contents |
---|
| 690 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7490] | 691 | ...<td>My test course</td>... |
---|
[6607] | 692 | ... |
---|
| 693 | |
---|
[6608] | 694 | Searching courses |
---|
| 695 | ----------------- |
---|
[6607] | 696 | |
---|
[6608] | 697 | >>> browser.open('http://localhost/myuniversity/faculties/search') |
---|
[7490] | 698 | >>> browser.getControl(name='query').value = "My test course" |
---|
[6608] | 699 | >>> browser.getControl('Search').click() |
---|
| 700 | >>> print browser.contents |
---|
| 701 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 702 | ...faculties/TF/TD/courses/COURSE1">COURSE1</a> |
---|
| 703 | ... |
---|
| 704 | |
---|
[7076] | 705 | >>> browser.open('http://localhost/myuniversity/faculties/search') |
---|
| 706 | >>> browser.getControl(name='query').value = "COURSE1" |
---|
| 707 | >>> browser.getControl('Search').click() |
---|
| 708 | >>> print browser.contents |
---|
| 709 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 710 | ...faculties/TF/TD/courses/COURSE1">COURSE1</a> |
---|
| 711 | ... |
---|
| 712 | |
---|
[6608] | 713 | >>> browser.getControl(name='query').value = "Nonsense" |
---|
| 714 | >>> browser.getControl('Search').click() |
---|
| 715 | >>> 'Search Results' in browser.contents |
---|
| 716 | False |
---|
[11794] | 717 | >>> '<div class="alert alert-warning">No object found.</div>' in browser.contents |
---|
| 718 | True |
---|
[6608] | 719 | |
---|
[7076] | 720 | >>> browser.getControl(name='query').value = "" |
---|
| 721 | >>> browser.getControl('Search').click() |
---|
| 722 | >>> 'Empty search string' in browser.contents |
---|
| 723 | True |
---|
| 724 | |
---|
[10540] | 725 | We can grant local roles: |
---|
| 726 | |
---|
| 727 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1/manage') |
---|
| 728 | >>> browser.getControl(name="user").value = ['bob'] |
---|
| 729 | >>> browser.getControl( |
---|
| 730 | ... name="local_role").value = ['waeup.local.Lecturer'] |
---|
| 731 | >>> browser.getControl("Add local role").click() |
---|
| 732 | >>> print browser.contents |
---|
| 733 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 734 | ...<td>bob</td> |
---|
| 735 | ... |
---|
| 736 | |
---|
| 737 | On the portal user page the new local role is displayed: |
---|
| 738 | |
---|
[12912] | 739 | >>> browser.getLink("Officers").click() |
---|
[10540] | 740 | >>> print browser.contents |
---|
| 741 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 742 | ...<td>Lecturer:... |
---|
| 743 | ... |
---|
| 744 | |
---|
| 745 | The local role can be removed again: |
---|
| 746 | |
---|
| 747 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1/manage') |
---|
| 748 | >>> ctrl = browser.getControl(name='role_id') |
---|
| 749 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 750 | >>> print browser.contents |
---|
| 751 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 752 | ...No local role selected... |
---|
| 753 | ... |
---|
| 754 | |
---|
| 755 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/courses/COURSE1/manage') |
---|
| 756 | >>> ctrl = browser.getControl(name='role_id') |
---|
| 757 | >>> ctrl.getControl(value='bob|waeup.local.Lecturer').selected = True |
---|
| 758 | >>> browser.getControl("Remove selected local roles").click() |
---|
| 759 | >>> print browser.contents |
---|
| 760 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 761 | ...Local role successfully removed... |
---|
| 762 | ... |
---|
| 763 | |
---|
[6607] | 764 | Deleting courses |
---|
| 765 | ---------------- |
---|
| 766 | |
---|
[7208] | 767 | We can delete courses by browsing the manage page of the containing |
---|
| 768 | department and checking the appropriate select box and clicking the |
---|
| 769 | ´´Remove selected´´ button. |
---|
[6607] | 770 | |
---|
[7208] | 771 | >>> browser.open( |
---|
| 772 | ... 'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-2') |
---|
[7490] | 773 | >>> 'My test course' in browser.contents |
---|
[6607] | 774 | True |
---|
| 775 | |
---|
[6613] | 776 | >>> browser.getControl('Cancel', index=0).click() |
---|
| 777 | >>> browser.getLink('Manage department').click() |
---|
| 778 | >>> browser.getControl('Remove selected courses').click() |
---|
[6917] | 779 | >>> 'No item selected' in browser.contents |
---|
[6613] | 780 | True |
---|
| 781 | |
---|
[7208] | 782 | >>> browser.getControl( |
---|
| 783 | ... name='val_id').getControl(value='COURSE1').selected = True |
---|
[6607] | 784 | >>> browser.getControl('Remove selected courses').click() |
---|
| 785 | |
---|
| 786 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD') |
---|
| 787 | >>> 'My renamed course' in browser.contents |
---|
| 788 | False |
---|
| 789 | |
---|
| 790 | |
---|
[7204] | 791 | Deleting departments with courses |
---|
| 792 | --------------------------------- |
---|
| 793 | |
---|
| 794 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 795 | >>> browser.getControl('Cancel', index=0).click() |
---|
| 796 | >>> browser.getLink('Manage faculty').click() |
---|
| 797 | >>> browser.getControl('Add department').click() |
---|
| 798 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 799 | >>> ctrl.value = 'Third Department' |
---|
| 800 | >>> browser.getControl(name='form.code').value = 'TD3' |
---|
| 801 | >>> browser.getControl('Add department').click() |
---|
| 802 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD3/manage') |
---|
| 803 | >>> browser.getControl('Add course').click() |
---|
| 804 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 805 | >>> ctrl.value = 'My Course 5' |
---|
| 806 | >>> browser.getControl(name='form.code').value = 'COURSE5' |
---|
| 807 | >>> browser.getControl('Add course').click() |
---|
| 808 | >>> browser.open('http://localhost/myuniversity/faculties/TF/manage') |
---|
| 809 | >>> ctrl = browser.getControl(name='val_id') |
---|
| 810 | >>> ctrl.getControl(value='TD3').selected = True |
---|
| 811 | >>> browser.getControl("Remove selected", index=0).click() |
---|
| 812 | >>> print browser.contents |
---|
| 813 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 814 | ...Successfully removed:... |
---|
| 815 | ... |
---|
| 816 | |
---|
[6607] | 817 | Certificates |
---|
| 818 | ============ |
---|
| 819 | |
---|
| 820 | Once we have a department, we can add also certificats. |
---|
| 821 | |
---|
| 822 | Adding certificates |
---|
| 823 | ------------------- |
---|
| 824 | |
---|
[7333] | 825 | Certificates are stored in :class:`ICertificatesContainer` instances |
---|
| 826 | with their code as key. CertificatesContainers are normally availabe as |
---|
[6607] | 827 | `certificates` attribute of |
---|
[7811] | 828 | :class:`waeup.kofa.university.department.Department` instances. |
---|
[6607] | 829 | |
---|
[12912] | 830 | To ease the life of officers we do not require to browse the |
---|
[7333] | 831 | certificatescontainers (which have in fact no user interface), but |
---|
[6607] | 832 | provide adding of certificates in department views. |
---|
| 833 | |
---|
| 834 | Each department provides a ``Add certificate`` action button near top. |
---|
| 835 | |
---|
| 836 | Departments provide an add-form to add new certificates: |
---|
| 837 | |
---|
| 838 | >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD' |
---|
[6613] | 839 | >>> browser.open(dept_url + '/manage') |
---|
| 840 | >>> browser.getControl('Add certificate').click() |
---|
[6607] | 841 | >>> print browser.contents |
---|
| 842 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 843 | ...*</span> |
---|
[6607] | 844 | ...<span>Title</span>: |
---|
| 845 | ... |
---|
| 846 | |
---|
| 847 | We fill in a name for our new cert: |
---|
| 848 | |
---|
| 849 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 850 | >>> ctrl.value = 'My Certificate 1' |
---|
| 851 | |
---|
| 852 | Furthermore we add a code (kind of abbreviation): |
---|
| 853 | |
---|
| 854 | >>> browser.getControl(name='form.code').value = 'CERT1' |
---|
| 855 | |
---|
| 856 | Set the remaining required fields: |
---|
| 857 | |
---|
[7843] | 858 | >>> browser.getControl(name='form.study_mode').value = ['ug_ft'] |
---|
[6607] | 859 | >>> browser.getControl(name='form.start_level').value = ['100'] |
---|
| 860 | >>> browser.getControl(name='form.end_level').value = ['400'] |
---|
| 861 | >>> browser.getControl(name='form.application_category').value = ['basic'] |
---|
| 862 | |
---|
| 863 | Finally, we create the certificate: |
---|
| 864 | |
---|
| 865 | >>> browser.getControl('Add certificate').click() |
---|
| 866 | |
---|
| 867 | If we try to register a certificate under the same code twice we will |
---|
| 868 | get an error: |
---|
| 869 | |
---|
| 870 | >>> browser.open(dept_url + '/addcertificate') |
---|
| 871 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 872 | >>> ctrl.value = 'Another cert with same code' |
---|
| 873 | >>> browser.getControl(name='form.code').value = 'CERT1' |
---|
[7843] | 874 | >>> browser.getControl(name='form.study_mode').value = ['ug_ft'] |
---|
[6607] | 875 | >>> browser.getControl(name='form.start_level').value = ['100'] |
---|
| 876 | >>> browser.getControl(name='form.end_level').value = ['400'] |
---|
| 877 | >>> browser.getControl(name='form.application_category').value = ['basic'] |
---|
| 878 | |
---|
| 879 | >>> browser.getControl('Add certificate').click() |
---|
| 880 | >>> print browser.contents |
---|
| 881 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 882 | ...A certificate with same code already exists:... |
---|
[6607] | 883 | ... |
---|
| 884 | |
---|
| 885 | Our certificate will be linked under the code on the department page: |
---|
| 886 | |
---|
| 887 | >>> browser.open(dept_url) |
---|
| 888 | >>> browser.getLink('CERT1').click() |
---|
| 889 | >>> browser.url |
---|
| 890 | 'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1' |
---|
| 891 | |
---|
| 892 | Before we really add a certificate we can cancel the action and will be |
---|
| 893 | redirected to the department page: |
---|
| 894 | |
---|
| 895 | >>> browser.open(dept_url + '/addcertificate') |
---|
| 896 | >>> browser.getControl('Cancel').click() |
---|
| 897 | >>> browser.url |
---|
| 898 | 'http://localhost/myuniversity/faculties/TF/TD' |
---|
| 899 | |
---|
| 900 | |
---|
| 901 | Modifying certificates |
---|
| 902 | ---------------------- |
---|
| 903 | |
---|
| 904 | We can change the settings for a cert by clicking on the provided |
---|
| 905 | 'Edit certificate' link: |
---|
| 906 | |
---|
| 907 | >>> browser.open(dept_url + '/certificates/CERT1') |
---|
| 908 | >>> browser.getLink('Manage certificate').click() |
---|
| 909 | |
---|
| 910 | When modifying a certificate, we cannot change the code any more: |
---|
| 911 | |
---|
| 912 | >>> browser.getControl(name='form.code') |
---|
| 913 | Traceback (most recent call last): |
---|
| 914 | ... |
---|
| 915 | LookupError: name 'form.code' |
---|
| 916 | |
---|
| 917 | Let's set a new title and save the form: |
---|
| 918 | |
---|
| 919 | >>> browser.getControl(name='form.title').value = "My test cert" |
---|
| 920 | >>> browser.getControl(name='form.actions.save').click() |
---|
| 921 | |
---|
| 922 | Clicking 'Save' we will stay on the settings form. So we can change |
---|
[7208] | 923 | the cert again. |
---|
[6607] | 924 | |
---|
[7208] | 925 | >>> browser.getControl(name='form.title').value = "My renamed cert" |
---|
[6607] | 926 | >>> ctrl = browser.getControl("Save",index=0) |
---|
| 927 | >>> ctrl.click() |
---|
| 928 | |
---|
| 929 | If we go to the settings page and click ``Cancel`` nothing will be |
---|
| 930 | changed: |
---|
| 931 | |
---|
| 932 | >>> browser.getControl(name='form.title').value = "Blah" |
---|
| 933 | >>> browser.getControl('Cancel',index=0).click() |
---|
| 934 | |
---|
| 935 | Our certificate was indeed renamed to ``My renamed cert`` and not to |
---|
| 936 | ``Blah``: |
---|
| 937 | |
---|
| 938 | >>> browser.open('http://localhost/myuniversity/faculties/TF/TD') |
---|
| 939 | >>> print browser.contents |
---|
| 940 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 941 | ...<td>My renamed cert</td>... |
---|
| 942 | ... |
---|
| 943 | |
---|
[7076] | 944 | Searching certificates |
---|
| 945 | ---------------------- |
---|
[6607] | 946 | |
---|
[7076] | 947 | >>> browser.open('http://localhost/myuniversity/faculties/search') |
---|
| 948 | >>> browser.getControl(name='query').value = "My renamed cert" |
---|
| 949 | >>> browser.getControl('Search').click() |
---|
| 950 | >>> print browser.contents |
---|
| 951 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 952 | ...faculties/TF/TD/certificates/CERT1">CERT1</a> |
---|
| 953 | ... |
---|
| 954 | |
---|
| 955 | >>> browser.open('http://localhost/myuniversity/faculties/search') |
---|
| 956 | >>> browser.getControl(name='query').value = "CERT1" |
---|
| 957 | >>> browser.getControl('Search').click() |
---|
| 958 | >>> print browser.contents |
---|
| 959 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 960 | ...faculties/TF/TD/certificates/CERT1">CERT1</a> |
---|
| 961 | ... |
---|
| 962 | |
---|
[6607] | 963 | Deleting certificates |
---|
| 964 | --------------------- |
---|
| 965 | |
---|
[7208] | 966 | We can delete certificates by browsing the manage page of the |
---|
| 967 | containing department and checking the appropriate select box and |
---|
| 968 | clicking the ´´Remove selected´´ button. |
---|
[6607] | 969 | |
---|
[7208] | 970 | >>> browser.open( |
---|
| 971 | ... 'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-3') |
---|
[6607] | 972 | >>> 'My renamed cert' in browser.contents |
---|
| 973 | True |
---|
| 974 | |
---|
[6613] | 975 | >>> browser.getControl('Remove selected certificates').click() |
---|
[6917] | 976 | >>> 'No item selected' in browser.contents |
---|
[6613] | 977 | True |
---|
| 978 | |
---|
[7208] | 979 | >>> browser.getControl(name='val_id').getControl( |
---|
| 980 | ... value='CERT1').selected = True |
---|
[6607] | 981 | >>> browser.getControl('Remove selected certificates').click() |
---|
| 982 | >>> 'My renamed cert' in browser.contents |
---|
| 983 | False |
---|
| 984 | |
---|
| 985 | |
---|
[12920] | 986 | Certificate Courses |
---|
| 987 | =================== |
---|
[6607] | 988 | |
---|
| 989 | Once we have a certificate, we can add also certificate courses. These |
---|
| 990 | are referrers of courses with some extra data. |
---|
| 991 | |
---|
| 992 | Before we can work with certificate courses, we need some certificates |
---|
| 993 | and courses to be available. |
---|
| 994 | |
---|
| 995 | >>> browser.open(dept_url + '/addcourse') |
---|
| 996 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 997 | >>> ctrl.value = 'Another course with same code' |
---|
| 998 | >>> browser.getControl(name='form.code').value = 'COURSE1' |
---|
[7208] | 999 | >>> browser.getControl(name='form.title').value = 'Course 1' |
---|
[6607] | 1000 | >>> browser.getControl('Add course').click() |
---|
| 1001 | |
---|
| 1002 | >>> browser.open(dept_url + '/addcourse') |
---|
| 1003 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 1004 | >>> ctrl.value = 'Another course with same code' |
---|
| 1005 | >>> browser.getControl(name='form.code').value = 'COURSE2' |
---|
| 1006 | >>> browser.getControl(name='form.title').value = 'Course 2' |
---|
| 1007 | >>> browser.getControl('Add course').click() |
---|
| 1008 | |
---|
| 1009 | >>> browser.open(dept_url + '/addcertificate') |
---|
| 1010 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 1011 | >>> ctrl.value = 'Another cert with same code' |
---|
| 1012 | >>> browser.getControl(name='form.code').value = 'CERT1' |
---|
| 1013 | >>> browser.getControl(name='form.title').value = 'Certificate 1' |
---|
[7843] | 1014 | >>> browser.getControl(name='form.study_mode').value = ['ug_ft'] |
---|
[6607] | 1015 | >>> browser.getControl(name='form.start_level').value = ['100'] |
---|
| 1016 | >>> browser.getControl(name='form.end_level').value = ['400'] |
---|
| 1017 | >>> browser.getControl(name='form.application_category').value = ['basic'] |
---|
| 1018 | >>> browser.getControl('Add certificate').click() |
---|
| 1019 | |
---|
| 1020 | >>> browser.open(dept_url + '/addcertificate') |
---|
| 1021 | >>> ctrl = browser.getControl(name='form.title') |
---|
| 1022 | >>> ctrl.value = 'Another cert with same code' |
---|
| 1023 | >>> browser.getControl(name='form.code').value = 'CERT2' |
---|
| 1024 | >>> browser.getControl(name='form.title').value = 'Certificate 2' |
---|
[7843] | 1025 | >>> browser.getControl(name='form.study_mode').value = ['ug_ft'] |
---|
[6607] | 1026 | >>> browser.getControl(name='form.start_level').value = ['100'] |
---|
| 1027 | >>> browser.getControl(name='form.end_level').value = ['400'] |
---|
| 1028 | >>> browser.getControl(name='form.application_category').value = ['basic'] |
---|
| 1029 | >>> browser.getControl('Add certificate').click() |
---|
| 1030 | |
---|
[7208] | 1031 | |
---|
[12920] | 1032 | Adding certificate courses |
---|
| 1033 | -------------------------- |
---|
[6607] | 1034 | |
---|
| 1035 | Certcourses are stored in :class:`ICertificate` instances |
---|
| 1036 | with their code as key. |
---|
| 1037 | |
---|
[8920] | 1038 | Each certificate provides a ``Add certificate course`` action button near top. |
---|
[6607] | 1039 | |
---|
| 1040 | Certificates provide an add-form to add new certcourses: |
---|
| 1041 | |
---|
| 1042 | >>> cert_url = dept_url + '/certificates/CERT1' |
---|
[6613] | 1043 | >>> browser.open(cert_url + '/manage') |
---|
[8920] | 1044 | >>> browser.getControl('Add certificate course').click() |
---|
[6607] | 1045 | >>> print browser.contents |
---|
| 1046 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
[7459] | 1047 | ...*</span> |
---|
[6607] | 1048 | ...<span>Level</span>: |
---|
| 1049 | ... |
---|
| 1050 | |
---|
| 1051 | In the add-form we will get a list of available courses to select |
---|
| 1052 | from. This list will contain all courses stored in the site, not only |
---|
| 1053 | the ones from local department: |
---|
| 1054 | |
---|
| 1055 | >>> ctrl = browser.getControl(name='form.course') |
---|
| 1056 | >>> ctrl.displayOptions |
---|
[8032] | 1057 | ['--', 'COURSE1 - Course 1', 'COURSE2 - Course 2'] |
---|
[6607] | 1058 | |
---|
[12920] | 1059 | We select the first course and create our certificate course: |
---|
[6607] | 1060 | |
---|
| 1061 | >>> ctrl.getControl('COURSE1').selected = True |
---|
[7208] | 1062 | >>> browser.getControl(name='form.level').value = ['100'] |
---|
[8920] | 1063 | >>> browser.getControl('Add certificate course').click() |
---|
[6607] | 1064 | |
---|
[12920] | 1065 | Our certificate course will be linked on the parent certificate page: |
---|
[6607] | 1066 | |
---|
| 1067 | >>> browser.open(cert_url) |
---|
| 1068 | >>> browser.getLink('COURSE1_100').click() |
---|
| 1069 | >>> browser.url |
---|
| 1070 | 'http://localhost/my...sity/faculties/TF/TD/certificates/CERT1/COURSE1_100' |
---|
| 1071 | |
---|
[12920] | 1072 | We can't add the same certificate course twice: |
---|
[6613] | 1073 | |
---|
| 1074 | >>> cert_url = dept_url + '/certificates/CERT1' |
---|
| 1075 | >>> browser.open(cert_url + '/manage') |
---|
[8920] | 1076 | >>> browser.getControl('Add certificate course').click() |
---|
[6613] | 1077 | >>> ctrl = browser.getControl(name='form.course') |
---|
| 1078 | >>> ctrl.getControl('COURSE1').selected = True |
---|
| 1079 | >>> browser.getControl(name='form.level').value = ['100'] |
---|
[8920] | 1080 | >>> browser.getControl('Add certificate course').click() |
---|
| 1081 | >>> 'The chosen certificate course is already' in browser.contents |
---|
[6613] | 1082 | True |
---|
| 1083 | |
---|
[12920] | 1084 | When we started to add a new certificate course, we can also cancel the |
---|
[6607] | 1085 | process before submitting. This will bring us back to the certificate |
---|
| 1086 | page: |
---|
| 1087 | |
---|
| 1088 | >>> browser.open(cert_url + '/addcertificatecourse') |
---|
| 1089 | >>> browser.getControl('Cancel').click() |
---|
| 1090 | >>> browser.url |
---|
| 1091 | 'http://localhost/myuniversity/faculties/TF/TD/certificates/CERT1' |
---|
| 1092 | |
---|
| 1093 | |
---|
[12920] | 1094 | Modifying certificate courses |
---|
| 1095 | ----------------------------- |
---|
[6607] | 1096 | |
---|
| 1097 | We can change the settings for a certcourse by clicking on the |
---|
| 1098 | provided 'Edit certificate course' link: |
---|
| 1099 | |
---|
| 1100 | >>> browser.open(cert_url + '/COURSE1_100') |
---|
[8920] | 1101 | >>> browser.getLink('Edit certificate course').click() |
---|
[6607] | 1102 | |
---|
[6613] | 1103 | If we just click 'Save and return' nothing will change: |
---|
| 1104 | |
---|
| 1105 | >>> browser.getControl("Save and return").click() |
---|
| 1106 | >>> browser.getLink('COURSE1_100').click() |
---|
| 1107 | >>> browser.url |
---|
| 1108 | 'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_100' |
---|
| 1109 | |
---|
[6607] | 1110 | Let's set a new level (it was 100 before) and save the form. This will |
---|
| 1111 | bring us to the certificate index page afterwards: |
---|
| 1112 | |
---|
[6613] | 1113 | >>> browser.open(cert_url + '/COURSE1_100/manage') |
---|
[7208] | 1114 | >>> browser.getControl(name='form.level').value = ['200'] |
---|
[6613] | 1115 | >>> browser.getControl("Save and return").click() |
---|
[6607] | 1116 | |
---|
| 1117 | As we changed the level, also the URL will change: |
---|
| 1118 | |
---|
| 1119 | >>> browser.getLink('COURSE1_200').click() |
---|
| 1120 | >>> browser.url |
---|
| 1121 | 'http://localhost/myun.../TF/TD/certificates/CERT1/COURSE1_200' |
---|
| 1122 | |
---|
| 1123 | If we go to the settings page and click ``Cancel`` nothing will be |
---|
| 1124 | changed: |
---|
| 1125 | |
---|
[8920] | 1126 | >>> browser.getLink('Edit certificate course').click() |
---|
[6607] | 1127 | >>> browser.getControl(name='form.level').value = ['400'] |
---|
| 1128 | >>> browser.getControl('Cancel').click() |
---|
| 1129 | |
---|
| 1130 | Our certcourse provides a new level of 200 and not 400: |
---|
| 1131 | |
---|
| 1132 | >>> browser.open(cert_url + '/COURSE1_200') |
---|
| 1133 | >>> print browser.contents |
---|
| 1134 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 1135 | ...<td>Level:</td> |
---|
| 1136 | ...<td>200 (Year 2)</td> |
---|
| 1137 | ... |
---|
| 1138 | |
---|
[12920] | 1139 | Searching certificate courses |
---|
| 1140 | ----------------------------- |
---|
[6607] | 1141 | |
---|
[7076] | 1142 | >>> browser.open('http://localhost/myuniversity/faculties/search') |
---|
| 1143 | >>> browser.getControl(name='query').value = "COURSE1" |
---|
| 1144 | >>> browser.getControl('Search').click() |
---|
| 1145 | >>> print browser.contents |
---|
| 1146 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"... |
---|
| 1147 | ...faculties/TF/TD/certificates/CERT1/COURSE1_200">COURSE1</a> |
---|
| 1148 | ... |
---|
| 1149 | |
---|
| 1150 | >>> browser.getControl(name='query').value = "*" |
---|
| 1151 | >>> browser.getControl('Search').click() |
---|
| 1152 | >>> 'Search string not allowed' in browser.contents |
---|
| 1153 | True |
---|
| 1154 | |
---|
[12920] | 1155 | Deleting certificate courses |
---|
| 1156 | ---------------------------- |
---|
[6607] | 1157 | |
---|
| 1158 | We can delete certcourses by browsing the containing certificate manage page: |
---|
| 1159 | |
---|
| 1160 | >>> browser.open(cert_url + '/manage#tab-2') |
---|
| 1161 | >>> 'COURSE1_200</a>' in browser.contents |
---|
| 1162 | True |
---|
[8920] | 1163 | >>> browser.getControl('Remove selected certificate courses').click() |
---|
[6917] | 1164 | >>> 'No item selected' in browser.contents |
---|
[6613] | 1165 | True |
---|
[7208] | 1166 | >>> browser.getControl(name='val_id').getControl( |
---|
| 1167 | ... value='COURSE1_200').selected = True |
---|
[8920] | 1168 | >>> browser.getControl('Remove selected certificate courses').click() |
---|
[6607] | 1169 | >>> 'Successfully removed: COURSE1_200' in browser.contents |
---|
| 1170 | True |
---|
[7208] | 1171 | |
---|
[6607] | 1172 | >>> 'COURSE1_200</a>' in browser.contents |
---|
| 1173 | False |
---|
| 1174 | |
---|
| 1175 | |
---|
| 1176 | |
---|
| 1177 | Data Center |
---|
| 1178 | =========== |
---|
| 1179 | |
---|
| 1180 | The data center helps us uploading files for later import or similar. |
---|
| 1181 | |
---|
| 1182 | >>> browser.open('http://localhost/myuniversity') |
---|
| 1183 | >>> browser.getLink('Data Center').click() |
---|
| 1184 | |
---|
| 1185 | Setting the file path |
---|
| 1186 | --------------------- |
---|
| 1187 | |
---|
| 1188 | A datacenter stores files in a path in filesystem. By default this is |
---|
| 1189 | a directory in the sources: |
---|
| 1190 | |
---|
| 1191 | >>> print browser.contents |
---|
| 1192 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
| 1193 | ... |
---|
[7584] | 1194 | <b>Storage path:</b> <span>.../parts/test/datacenter</span> |
---|
[6607] | 1195 | ... |
---|
| 1196 | |
---|
| 1197 | Going to 'Settings` we can change the path: |
---|
| 1198 | |
---|
| 1199 | >>> browser.getLink('Edit settings').click() |
---|
| 1200 | >>> pathsetting = browser.getControl(name='newpath') |
---|
| 1201 | |
---|
| 1202 | We create a directory and set it as our upload path: |
---|
| 1203 | |
---|
| 1204 | >>> import os |
---|
| 1205 | >>> cwd = os.getcwd() |
---|
| 1206 | >>> uploadpath = os.path.join(cwd, 'testfiles') |
---|
| 1207 | >>> os.mkdir(uploadpath) |
---|
| 1208 | >>> pathsetting.value = uploadpath |
---|
| 1209 | |
---|
| 1210 | And submit the form: |
---|
| 1211 | |
---|
| 1212 | >>> browser.getControl(name='save').click() |
---|
| 1213 | |
---|
| 1214 | We clean up the set directory path, as there might be some files be |
---|
| 1215 | copied some files from installation: |
---|
| 1216 | |
---|
| 1217 | >>> files = os.listdir(uploadpath) |
---|
| 1218 | >>> for filename in files: |
---|
| 1219 | ... if os.path.isdir(os.path.join(uploadpath, filename)): |
---|
| 1220 | ... continue |
---|
| 1221 | ... os.unlink(os.path.join(uploadpath, filename)) |
---|
| 1222 | |
---|
| 1223 | We also remove any existing 'accesscodes' subdir: |
---|
| 1224 | |
---|
| 1225 | >>> import shutil |
---|
| 1226 | >>> for filename in files: |
---|
| 1227 | ... if not os.path.isdir(os.path.join(uploadpath, filename)): |
---|
| 1228 | ... continue |
---|
| 1229 | ... if filename != 'accesscodes': |
---|
| 1230 | ... continue |
---|
| 1231 | ... shutil.rmtree(os.path.join(uploadpath, filename)) |
---|
| 1232 | |
---|
| 1233 | The new upload directory is now empty, except from the logs and other |
---|
| 1234 | standard dirs, which are created automatically: |
---|
| 1235 | |
---|
| 1236 | >>> sorted(os.listdir(uploadpath)) |
---|
[8372] | 1237 | ['deleted', 'finished', 'logs', 'unfinished'] |
---|
[6607] | 1238 | |
---|
| 1239 | |
---|
| 1240 | Uploading files |
---|
| 1241 | --------------- |
---|
| 1242 | |
---|
| 1243 | Now we can upload files. Most interesting files might be CSV files, |
---|
| 1244 | that can be imported lateron. We create a CSV file containing faculty |
---|
| 1245 | descriptions: |
---|
| 1246 | |
---|
| 1247 | >>> open('faculties.csv', 'wb').write( |
---|
| 1248 | ... """code,title,title_prefix |
---|
| 1249 | ... FA,Arts,faculty |
---|
| 1250 | ... FS,Sciences,faculty |
---|
| 1251 | ... """) |
---|
| 1252 | |
---|
| 1253 | Now we can upload this file. To do this, we first go to the upload |
---|
| 1254 | page: |
---|
| 1255 | |
---|
[9024] | 1256 | >>> browser.getLink('Upload data').click() |
---|
[6607] | 1257 | |
---|
| 1258 | and enter the appropriate data in the form: |
---|
| 1259 | |
---|
| 1260 | >>> filewidget = browser.getControl(name='uploadfile:file') |
---|
| 1261 | >>> filewidget |
---|
| 1262 | <Control name='uploadfile:file' type='file'> |
---|
[7208] | 1263 | |
---|
[6607] | 1264 | A sidenote for developers: by marking the filewidget with the |
---|
| 1265 | ``:file`` extension, we tell Zope to handle this field as a file |
---|
| 1266 | widget. |
---|
| 1267 | |
---|
| 1268 | >>> import cStringIO |
---|
| 1269 | >>> filecontents = cStringIO.StringIO( |
---|
| 1270 | ... open('faculties.csv', 'rb').read()) |
---|
| 1271 | >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv') |
---|
[7208] | 1272 | |
---|
[6607] | 1273 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 1274 | |
---|
| 1275 | The file was indeed uploaded, with the current userid inserted: |
---|
| 1276 | |
---|
| 1277 | >>> sorted(os.listdir(uploadpath)) |
---|
[8372] | 1278 | ['deleted', 'finished', 'logs', 'myfaculties_zope.mgr.csv', 'unfinished'] |
---|
[6607] | 1279 | |
---|
| 1280 | We create and upload also a CSV file containing departments: |
---|
| 1281 | |
---|
| 1282 | >>> open('departments.csv', 'wb').write( |
---|
| 1283 | ... """code,title,title_prefix,faculty_code |
---|
| 1284 | ... LIT,Literature,department,FA |
---|
| 1285 | ... SOC,Sociology,department,FA |
---|
| 1286 | ... PHY,Physics,department,FS |
---|
| 1287 | ... INF,Informatics,department,FS |
---|
| 1288 | ... MAT,Math,department,FS |
---|
| 1289 | ... """) |
---|
| 1290 | |
---|
| 1291 | >>> browser.open('http://localhost/myuniversity/datacenter/upload') |
---|
| 1292 | >>> browser.getControl(name='uploadfile:file').add_file( |
---|
| 1293 | ... cStringIO.StringIO(open('departments.csv', 'rb').read()), |
---|
| 1294 | ... 'text/plain', 'mydepartments.csv') |
---|
| 1295 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 1296 | |
---|
| 1297 | We create and upload also a CSV file containing courses: |
---|
| 1298 | |
---|
| 1299 | >>> open('courses.csv', 'wb').write( |
---|
| 1300 | ... """code,level,title,passmark,credits,semester,faculty,department |
---|
| 1301 | ... LI1,,Introduction to Literature I,40,2,1,FA,LIT |
---|
| 1302 | ... LI2,,Introduction to Literature II,40,2,2,FA,LIT |
---|
| 1303 | ... AN1,000,Analysis I,40,2,1,FS,MAT |
---|
| 1304 | ... AN2,000,Analysis II,40,2,2,FS,MAT |
---|
| 1305 | ... """) |
---|
| 1306 | |
---|
| 1307 | >>> browser.open('http://localhost/myuniversity/datacenter/upload') |
---|
| 1308 | >>> browser.getControl(name='uploadfile:file').add_file( |
---|
| 1309 | ... cStringIO.StringIO(open('courses.csv', 'rb').read()), |
---|
| 1310 | ... 'text/plain', 'mycourses.csv') |
---|
| 1311 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 1312 | |
---|
| 1313 | We create and upload also a CSV file containing certificates: |
---|
| 1314 | |
---|
| 1315 | >>> open('certificates.csv', 'wb').write( |
---|
| 1316 | ... """code,title,faculty_code,department_code,study_mode,end_level,m_prefix,start_level,application_category |
---|
| 1317 | ... LBA,BACHELOR OF LITERATURE,FA,LIT,UG,ug_ft,500,LIT,100,basic |
---|
| 1318 | ... LMA,MASTER OF LITERATURE,FA,LIT,UG,ug_pt,500,LIT,100,cest |
---|
| 1319 | ... DME,DIPLOMA OF MATH,FS,MAT,DP,dp_ft,200,DME,100,cest |
---|
| 1320 | ... """) |
---|
| 1321 | |
---|
| 1322 | >>> browser.open('http://localhost/myuniversity/datacenter/upload') |
---|
| 1323 | >>> browser.getControl(name='uploadfile:file').add_file( |
---|
| 1324 | ... cStringIO.StringIO(open('certificates.csv', 'rb').read()), |
---|
| 1325 | ... 'text/plain', 'mycertificates.csv') |
---|
| 1326 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 1327 | |
---|
| 1328 | We create and upload also a CSV file containing certificate courses: |
---|
| 1329 | |
---|
| 1330 | >>> open('certcourses.csv', 'wb').write( |
---|
[7665] | 1331 | ... """code,faculty_code,department_code,certificate_code,level,mandatory |
---|
[6607] | 1332 | ... LI1,FA,LIT,LBA,100,True |
---|
| 1333 | ... LI2,FA,LIT,LBA,200,True |
---|
| 1334 | ... """) |
---|
| 1335 | |
---|
| 1336 | >>> browser.open('http://localhost/myuniversity/datacenter/upload') |
---|
| 1337 | >>> browser.getControl(name='uploadfile:file').add_file( |
---|
| 1338 | ... cStringIO.StringIO(open('certcourses.csv', 'rb').read()), |
---|
| 1339 | ... 'text/plain', 'mycertcourses.csv') |
---|
| 1340 | >>> browser.getControl(name='SUBMIT').click() |
---|
| 1341 | |
---|
| 1342 | |
---|
| 1343 | Importing a CSV file |
---|
| 1344 | -------------------- |
---|
| 1345 | |
---|
| 1346 | The import of CSV files is described in batchprocessing.txt. |
---|
| 1347 | |
---|
| 1348 | |
---|
| 1349 | Clean up: |
---|
| 1350 | |
---|
| 1351 | >>> import os |
---|
| 1352 | >>> import shutil |
---|
| 1353 | >>> shutil.rmtree(uploadpath) |
---|
| 1354 | |
---|