source: main/waeup.kofa/trunk/src/waeup/kofa/doctests/pages.txt @ 13606

Last change on this file since 13606 was 12966, checked in by Henrik Bettermann, 10 years ago

Fix typos.

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