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

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

Rename doctest.

File size: 44.6 KB
Line 
1Browsing Kofa
2*************
3
4Here we visit parts of a Kofa portal using a browser.
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
17  >>> from waeup.kofa.app import University
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
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
32Let's get the default view of a university::
33
34  >>> browser.open('http://localhost/myuniversity')
35  >>> print browser.contents
36  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
37  ...Welcome to WAeUP.Kofa...
38  ...
39
40We can change to German::
41
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'::
50
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
57The contact form for anonymous users is called 'Enquiries'::
58
59  >>> browser.open('http://localhost/myuniversity')
60  >>> browser.getLink('Enquiries').click()
61  >>> browser.getControl('Send').click()
62  >>> print browser.contents
63  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
64  ...Required input is missing...
65  ...
66
67  >>> browser.getControl(name='form.fullname').value = "Bob Tester"
68  >>> browser.getControl(name='form.email_from').value = "xx@yy.zz"
69  >>> browser.getControl(name='form.body').value = u'test message'
70  >>> browser.getControl('Send').click()
71  >>> print browser.contents
72  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
73  ...Your message has been sent...
74  ...
75
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')
80  >>> browser.open('http://localhost/myuniversity/changepw')
81  >>> browser.getControl(name="form.identifier").value = 'forgetful'
82  >>> browser.getControl(name="form.email").value = 'aa@aa.ng'
83  >>> browser.getControl("Send login credentials").click()
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
88Now we login as manager::
89
90  >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
91  >>> browser.handleErrors = False
92
93We can then get an edit view of the configuration container::
94
95  >>> browser.open('http://localhost/myuniversity/configuration')
96  >>> print browser.contents
97  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
98  ...<form action="http://localhost/myuniversity/configuration/@@index"
99  ...
100
101The edit form contains the default value for the university name::
102
103  >>> 'Sample University' in browser.contents
104  True
105
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"...
111  ...Form has been saved...
112  ...
113
114  >>> browser.open('http://localhost/myuniversity/configuration')
115  >>> browser.getControl("Update plugins").click()
116  >>> print browser.contents
117  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
118  ...Plugins were updated. See log file for details...
119  ...
120
121The default frontpage HTML has been saved in a dictionary
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"...
127  ...<h1>Welcome to WAeUP.Kofa...</h1>
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"...
141  ...<h1>Willkommen auf WAeUP.Kofa...</h1>
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
153We 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
169Officers
170========
171
172  >>> browser.open('http://localhost/myuniversity')
173  >>> browser.getLink('Officers').click()
174  >>> print browser.contents
175  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
176  ...Officers...
177  ...
178
179We can add officers:
180
181  >>> browser.getLink("Add officer").click()
182  >>> browser.getControl(name="form.name").value = 'bob'
183  >>> browser.getControl(name="form.title").value = 'Bob The User'
184  >>> browser.getControl(name="password").value = 'secret'
185  >>> browser.getControl(name="control_password").value = 'secret'
186  >>> browser.getControl(name="form.email").value = 'xx@yy.zz'
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'
190  >>> browser.getControl("Add officer").click()
191  >>> print browser.contents
192  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
193  ...<td>bob</td>
194  ...
195
196We can edit user bob:
197
198  >>> browser.getControl("Manage", index=0).click()
199  >>> browser.getControl("Save", index=0).click()
200  >>> browser.getControl("Cancel", index=0).click()
201
202We can add site roles which are then displayed on the user container page.
203Since the test browser does not use javascript, we have to add site roles
204manually by setting the roles attribute:
205
206  >>> print root['myuniversity']['users']['bob'].roles
207  []
208  >>> root['myuniversity']['users']['bob'].roles = ['waeup.ApplicationsOfficer']
209  >>> print root['myuniversity']['users']['bob'].roles
210  ['waeup.ApplicationsOfficer']
211  >>> browser.open('http://localhost/myuniversity/users')
212  >>> print browser.contents
213  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
214  ...<td nowrap>Applications Officer (view only) <br /></td>
215  ...
216
217Officers can't be added twice:
218
219  >>> browser.open('http://localhost/myuniversity/users/add')
220  >>> browser.getControl(name="form.name").value = 'bob'
221  >>> browser.getControl(name="form.title").value = 'Bob The User'
222  >>> browser.getControl(name="password").value = 'secret'
223  >>> browser.getControl(name="control_password").value = 'secret'
224  >>> browser.getControl(name="form.email").value = 'xx@yy.zz'
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'
228  >>> browser.getControl("Add officer").click()
229  >>> 'The userid chosen already exists' in browser.contents
230  True
231
232Officers can be deleted:
233
234  >>> browser.open('http://localhost/myuniversity/users')
235  >>> browser.getControl("Remove", index=0).click()
236  >>> 'User account bob successfully deleted' in browser.contents
237  True
238
239
240
241Contact Form
242============
243
244Let'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"...
249  ...Contact
250  ...
251
252We fill the form  (this will send a real message to
253contact@waeup.org)::
254
255  >>> browser.open('http://localhost/myuniversity/contactadmin')
256  >>> browser.getControl(name='form.body').value = "test message"
257  >>> browser.getControl('Send').click()
258  >>> print browser.contents
259  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
260  ...Your message has been sent...
261  ...
262
263If this test fails, chances are, that the local machine has no SMTP
264server installed.
265
266
267
268Faculties
269=========
270
271Faculties are stored in a special container of `IUniversity`
272instances. The container is called ``faculties`` and provides an
273add-form to add new faculties::
274
275  >>> browser.open('http://localhost/myuniversity/faculties/manage')
276  >>> browser.getControl('Add faculty').click()
277  >>> print browser.contents
278  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
279  ...*...
280  ...<span>Name of faculty</span>:
281  ...
282  >>> browser.getControl('Cancel').click()
283  >>> browser.open('http://localhost/myuniversity/faculties/add')
284
285We fill in a new name for our new faculty::
286
287  >>> ctrl = browser.getControl(name='form.title')
288  >>> ctrl.value = 'TestFac'
289
290Furthermore we add a prefix and a code (kind of abbreviation):
291
292  >>> browser.getControl(name='form.code').value = 'TF'
293
294Finally we click on 'Add Faculty' to add the new thing::
295
296  >>> browser.getControl('Add faculty').click()
297
298We can view a faculty by browsing a URL like this::
299
300  >>> browser.open('http://localhost/myuniversity/faculties/TF')
301
302Afterwards, 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"
307  ...<h1 class="kofa-content-label">Academic Section</h1>
308  ...<td> <a href="http://localhost/myuniversity/faculties/TF"> <span>TF</span></a></td>
309  ...
310
311We 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"...
316  ...Faculty of TestFac (TF)...
317  ...
318
319If 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
329Modifying faculties
330-------------------
331
332A faculty can directly be reached by its code:
333
334  >>> browser.open('http://localhost/myuniversity/faculties/TF')
335
336We can change the settings for a faculty by clicking on the
337provided 'Manage  faculty' button:
338
339  >>> browser.getLink('Manage faculty').click()
340
341Let'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
346Our 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"...
351  ...<h1 class="kofa-content-label">Academic Section</h1>
352  ...<td> <a href="http://localhost/myuniversity/faculties/TF"> <span>TF</span></a></td>
353  ...<td>Faculty of My renamed faculty (TF)</td>
354  ...
355
356We can grant local roles:
357
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']
362  >>> browser.getControl(
363  ...     name="local_role").value = ['waeup.local.DepartmentManager']
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
370On the officers page the new local role is displayed:
371
372  >>> browser.getLink("Officers").click()
373  >>> print browser.contents
374  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
375  ...<td>Department Manager:...
376  ...
377
378The 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')
390  >>> ctrl.getControl(value='bob|waeup.local.DepartmentManager').selected = True
391  >>> browser.getControl("Remove selected local roles").click()
392  >>> print browser.contents
393  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
394  ...Local role successfully removed...
395  ...
396
397Deleting 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()
412  >>> 'No item selected' in browser.contents
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
423Departments
424===========
425
426Adding departments
427------------------
428
429Departments are stored in :class:`IFaculty` instances with their code
430as key. Faculties therefore are also department containers. Faculties
431provides 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"...
436  ...*</span>
437  ...<span>Name of department</span>:
438  ...
439  >>> browser.getControl('Cancel').click()
440  >>> browser.open('http://localhost/myuniversity/faculties/TF/add')
441
442We fill in a new name for our new department:
443
444  >>> ctrl = browser.getControl(name='form.title')
445  >>> ctrl.value = 'TestDept'
446
447Furthermore we add a code (kind of abbreviation):
448
449  >>> browser.getControl(name='form.code').value = 'TD'
450
451Finally we click on 'Add Department' to add the new thing::
452
453  >>> browser.getControl('Add department').click()
454
455If we try to register a department under the same code twice we will
456get 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"...
465  ...The code chosen already exists in this faculty...
466  ...
467
468We can view a department by browsing a URL like this::
469
470  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
471
472Afterwards, the department should be visible::
473
474  >>> browser.open('http://localhost/myuniversity/faculties/TF')
475  >>> print browser.contents
476  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
477  ...<h1 class="kofa-content-label">Departments</h1>
478  ...<td> <a href="http://localhost/myuniversity/faculties/TF/TD"> <span>TD</span></a></td>
479  ...<td>Department of TestDept (TD)</td>
480  ...
481
482
483Modifying departments
484---------------------
485
486We can change the settings for a department by clicking on the
487provided 'Edit department' button:
488
489  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD')
490  >>> browser.getLink('Manage department').click()
491
492Let'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
497Clicking 'Save' we will stay on the settings form. So we can change
498the department again.
499
500  >>> browser.getControl(name='form.title').value = "My renamed dept"
501  >>> ctrl = browser.getControl("Save")
502  >>> ctrl.click()
503
504
505Our 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"
510  ...<h1 class="kofa-content-label">Departments</h1>
511  ...<td> <a href="http://localhost/myuniversity/faculties/TF/TD"> <span>TD</span></a></td>
512  ...<td>Department of My renamed dept (TD)</td>
513  ...
514
515We can grant local roles:
516
517  >>> browser.open('http://localhost/myuniversity/faculties/TF/TD/manage')
518  >>> browser.getControl(name="user").value = ['bob']
519  >>> browser.getControl(
520  ...     name="local_role").value = ['waeup.local.DepartmentManager']
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
527The 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')
539  >>> ctrl.getControl(
540  ...     value='bob|waeup.local.DepartmentManager').selected = True
541  >>> browser.getControl("Remove selected local roles").click()
542  >>> print browser.contents
543  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
544  ...Local role successfully removed...
545  ...
546
547Deleting departments
548--------------------
549
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()
562  >>> 'No item selected' in browser.contents
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
574Courses
575=======
576
577Once we have a department, we can add courses.
578
579Adding courses
580--------------
581
582Courses are stored in :class:`ICoursesContainer` instances with their
583code as key. CoursesContainers are normally availabe as `course`
584attribute of :class:`waeup.kofa.university.department.Department`
585instances.
586
587To ease the life of officers we do not require to browse the
588coursescontainers (which have a rather flat user interface), but
589provide adding of courses in department views.
590
591Each department provides a ``Add course`` action button near top.
592
593Departments provide an add-form to add new courses:
594
595  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
596  >>> browser.open(dept_url + '/manage')
597  >>> browser.getControl('Add course').click()
598  >>> print browser.contents
599  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
600  ...*</span>
601  ...<span>Title of course</span>:
602  ...
603
604We fill in a name for our new course:
605
606  >>> ctrl = browser.getControl(name='form.title')
607  >>> ctrl.value = 'My Course 1'
608
609Furthermore we add a code (kind of abbreviation):
610
611  >>> browser.getControl(name='form.code').value = 'COURSE1'
612
613This 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
618  ['1', '2', '3', '9']
619
620  >>> ctrl.displayOptions
621  ['1st Semester', '2nd Semester', 'Combined', 'N/A']
622
623  >>> ctrl.value = ['1']
624
625Finally, we create the course:
626
627  >>> browser.getControl('Add course').click()
628
629If we try to register a course under the same code twice we will
630get 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"...
639  ...A course with same code already exists:...
640  ...
641
642Our 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
649Before we really add a course we can cancel the action and will be
650redirected 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
658Modifying courses
659-----------------
660
661We 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
667When 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
674Let'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
679Clicking 'Save' we will stay on the settings form. So we can change
680the course again. If we click ``Cancel`` nothing will be
681changed:
682
683  >>> browser.getControl(name='form.title').value = "Blah"
684  >>> browser.getControl('Cancel').click()
685
686Our course was not renamed to ``Blah``:
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"...
691  ...<td>My test course</td>...
692  ...
693
694Searching courses
695-----------------
696
697  >>> browser.open('http://localhost/myuniversity/faculties/search')
698  >>> browser.getControl(name='query').value = "My test course"
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
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
713  >>> browser.getControl(name='query').value = "Nonsense"
714  >>> browser.getControl('Search').click()
715  >>> 'Search Results' in browser.contents
716  False
717  >>> '<div class="alert alert-warning">No object found.</div>' in browser.contents
718  True
719
720  >>> browser.getControl(name='query').value = ""
721  >>> browser.getControl('Search').click()
722  >>> 'Empty search string' in browser.contents
723  True
724
725We 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
737On the portal user page the new local role is displayed:
738
739  >>> browser.getLink("Officers").click()
740  >>> print browser.contents
741  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
742  ...<td>Lecturer:...
743  ...
744
745The 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
764Deleting courses
765----------------
766
767We can delete courses by browsing the manage page of the containing
768department and checking the appropriate select box and clicking the
769´´Remove selected´´ button.
770
771  >>> browser.open(
772  ...     'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-2')
773  >>> 'My test course' in browser.contents
774  True
775
776  >>> browser.getControl('Cancel', index=0).click()
777  >>> browser.getLink('Manage department').click()
778  >>> browser.getControl('Remove selected courses').click()
779  >>> 'No item selected' in browser.contents
780  True
781
782  >>> browser.getControl(
783  ...    name='val_id').getControl(value='COURSE1').selected = True
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
791Deleting 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
817Certificates
818============
819
820Once we have a department, we can add also certificats.
821
822Adding certificates
823-------------------
824
825Certificates are stored in :class:`ICertificatesContainer` instances
826with their code as key. CertificatesContainers are normally availabe as
827`certificates` attribute of
828:class:`waeup.kofa.university.department.Department` instances.
829
830To ease the life of officers we do not require to browse the
831certificatescontainers (which have in fact no user interface), but
832provide adding of certificates in department views.
833
834Each department provides a ``Add certificate`` action button near top.
835
836Departments provide an add-form to add new certificates:
837
838  >>> dept_url = 'http://localhost/myuniversity/faculties/TF/TD'
839  >>> browser.open(dept_url + '/manage')
840  >>> browser.getControl('Add certificate').click()
841  >>> print browser.contents
842  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
843  ...*</span>
844  ...<span>Title</span>:
845  ...
846
847We fill in a name for our new cert:
848
849  >>> ctrl = browser.getControl(name='form.title')
850  >>> ctrl.value = 'My Certificate 1'
851
852Furthermore we add a code (kind of abbreviation):
853
854  >>> browser.getControl(name='form.code').value = 'CERT1'
855
856Set the remaining required fields:
857
858  >>> browser.getControl(name='form.study_mode').value = ['ug_ft']
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
863Finally, we create the certificate:
864
865  >>> browser.getControl('Add certificate').click()
866
867If we try to register a certificate under the same code twice we will
868get 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'
874  >>> browser.getControl(name='form.study_mode').value = ['ug_ft']
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"...
882  ...A certificate with same code already exists:...
883  ...
884
885Our 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
892Before we really add a certificate we can cancel the action and will be
893redirected 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
901Modifying certificates
902----------------------
903
904We 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
910When 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
917Let'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
922Clicking 'Save' we will stay on the settings form. So we can change
923the cert again.
924
925  >>> browser.getControl(name='form.title').value = "My renamed cert"
926  >>> ctrl = browser.getControl("Save",index=0)
927  >>> ctrl.click()
928
929If we go to the settings page and click ``Cancel`` nothing will be
930changed:
931
932  >>> browser.getControl(name='form.title').value = "Blah"
933  >>> browser.getControl('Cancel',index=0).click()
934
935Our 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
944Searching certificates
945----------------------
946
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
963Deleting certificates
964---------------------
965
966We can delete certificates by browsing the manage page of the
967containing department and checking the appropriate select box and
968clicking the ´´Remove selected´´ button.
969
970  >>> browser.open(
971  ...    'http://localhost/myuniversity/faculties/TF/TD/@@manage#tab-3')
972  >>> 'My renamed cert' in browser.contents
973  True
974
975  >>> browser.getControl('Remove selected certificates').click()
976  >>> 'No item selected' in browser.contents
977  True
978
979  >>> browser.getControl(name='val_id').getControl(
980  ...    value='CERT1').selected = True
981  >>> browser.getControl('Remove selected certificates').click()
982  >>> 'My renamed cert' in browser.contents
983  False
984
985
986Certificate Courses
987===================
988
989Once we have a certificate, we can add also certificate courses. These
990are referrers of courses with some extra data.
991
992Before we can work with certificate courses, we need some certificates
993and 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'
999  >>> browser.getControl(name='form.title').value = 'Course 1'
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'
1014  >>> browser.getControl(name='form.study_mode').value = ['ug_ft']
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'
1025  >>> browser.getControl(name='form.study_mode').value = ['ug_ft']
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
1031
1032Adding certificate courses
1033--------------------------
1034
1035Certcourses are stored in :class:`ICertificate` instances
1036with their code as key.
1037
1038Each certificate provides a ``Add certificate course`` action button near top.
1039
1040Certificates provide an add-form to add new certcourses:
1041
1042  >>> cert_url = dept_url + '/certificates/CERT1'
1043  >>> browser.open(cert_url + '/manage')
1044  >>> browser.getControl('Add certificate course').click()
1045  >>> print browser.contents
1046  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
1047  ...*</span>
1048  ...<span>Level</span>:
1049  ...
1050
1051In the add-form we will get a list of available courses to select
1052from. This list will contain all courses stored in the site, not only
1053the ones from local department:
1054
1055  >>> ctrl = browser.getControl(name='form.course')
1056  >>> ctrl.displayOptions
1057  ['--', 'COURSE1 - Course 1', 'COURSE2 - Course 2']
1058
1059We select the first course and create our certificate course:
1060
1061  >>> ctrl.getControl('COURSE1').selected = True
1062  >>> browser.getControl(name='form.level').value = ['100']
1063  >>> browser.getControl('Add certificate course').click()
1064
1065Our certificate course will be linked on the parent certificate page:
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
1072We can't add the same certificate course twice:
1073
1074  >>> cert_url = dept_url + '/certificates/CERT1'
1075  >>> browser.open(cert_url + '/manage')
1076  >>> browser.getControl('Add certificate course').click()
1077  >>> ctrl = browser.getControl(name='form.course')
1078  >>> ctrl.getControl('COURSE1').selected = True
1079  >>> browser.getControl(name='form.level').value = ['100']
1080  >>> browser.getControl('Add certificate course').click()
1081  >>> 'The chosen certificate course is already' in browser.contents
1082  True
1083
1084When we started to add a new certificate course, we can also cancel the
1085process before submitting. This will bring us back to the certificate
1086page:
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
1094Modifying certificate courses
1095-----------------------------
1096
1097We can change the settings for a certcourse by clicking on the
1098provided 'Edit certificate course' link:
1099
1100  >>> browser.open(cert_url + '/COURSE1_100')
1101  >>> browser.getLink('Edit certificate course').click()
1102
1103If 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
1110Let's set a new level (it was 100 before) and save the form. This will
1111bring us to the certificate index page afterwards:
1112
1113  >>> browser.open(cert_url + '/COURSE1_100/manage')
1114  >>> browser.getControl(name='form.level').value = ['200']
1115  >>> browser.getControl("Save and return").click()
1116
1117As 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
1123If we go to the settings page and click ``Cancel`` nothing will be
1124changed:
1125
1126  >>> browser.getLink('Edit certificate course').click()
1127  >>> browser.getControl(name='form.level').value = ['400']
1128  >>> browser.getControl('Cancel').click()
1129
1130Our 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
1139Searching certificate courses
1140-----------------------------
1141
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
1155Deleting certificate courses
1156----------------------------
1157
1158We 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
1163  >>> browser.getControl('Remove selected certificate courses').click()
1164  >>> 'No item selected' in browser.contents
1165  True
1166  >>> browser.getControl(name='val_id').getControl(
1167  ...    value='COURSE1_200').selected = True
1168  >>> browser.getControl('Remove selected certificate courses').click()
1169  >>> 'Successfully removed: COURSE1_200' in browser.contents
1170  True
1171
1172  >>> 'COURSE1_200</a>' in browser.contents
1173  False
1174
1175
1176
1177Data Center
1178===========
1179
1180The 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
1185Setting the file path
1186---------------------
1187
1188A datacenter stores files in a path in filesystem. By default this is
1189a directory in the sources:
1190
1191  >>> print browser.contents
1192  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1193  ...
1194  <b>Storage path:</b> <span>.../parts/test/datacenter</span>
1195  ...
1196
1197Going to 'Settings` we can change the path:
1198
1199  >>> browser.getLink('Edit settings').click()
1200  >>> pathsetting = browser.getControl(name='newpath')
1201
1202We 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
1210And submit the form:
1211
1212  >>> browser.getControl(name='save').click()
1213
1214We clean up the set directory path, as there might be some files be
1215copied 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
1223We 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
1233The new upload directory is now empty, except from the logs and other
1234standard dirs, which are created automatically:
1235
1236  >>> sorted(os.listdir(uploadpath))
1237  ['deleted', 'finished', 'logs', 'unfinished']
1238
1239
1240Uploading files
1241---------------
1242
1243Now we can upload files. Most interesting files might be CSV files,
1244that can be imported lateron. We create a CSV file containing faculty
1245descriptions:
1246
1247  >>> open('faculties.csv', 'wb').write(
1248  ... """code,title,title_prefix
1249  ... FA,Arts,faculty
1250  ... FS,Sciences,faculty
1251  ... """)
1252
1253Now we can upload this file. To do this, we first go to the upload
1254page:
1255
1256  >>> browser.getLink('Upload data').click()
1257
1258and enter the appropriate data in the form:
1259
1260  >>> filewidget = browser.getControl(name='uploadfile:file')
1261  >>> filewidget
1262  <Control name='uploadfile:file' type='file'>
1263
1264A sidenote for developers: by marking the filewidget with the
1265``:file`` extension, we tell Zope to handle this field as a file
1266widget.
1267
1268  >>> import cStringIO
1269  >>> filecontents = cStringIO.StringIO(
1270  ...   open('faculties.csv', 'rb').read())
1271  >>> filewidget.add_file(filecontents, 'text/plain', 'myfaculties.csv')
1272
1273  >>> browser.getControl(name='SUBMIT').click()
1274
1275The file was indeed uploaded, with the current userid inserted:
1276
1277  >>> sorted(os.listdir(uploadpath))
1278  ['deleted', 'finished', 'logs', 'myfaculties_zope.mgr.csv', 'unfinished']
1279
1280We 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
1297We 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
1313We 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
1328We create and upload also a CSV file containing certificate courses:
1329
1330  >>> open('certcourses.csv', 'wb').write(
1331  ... """code,faculty_code,department_code,certificate_code,level,mandatory
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
1343Importing a CSV file
1344--------------------
1345
1346The import of CSV files is described in batchprocessing.txt.
1347
1348
1349Clean up:
1350
1351  >>> import os
1352  >>> import shutil
1353  >>> shutil.rmtree(uploadpath)
1354
Note: See TracBrowser for help on using the repository browser.