source: WAeUP_SRP/trunk/skins/waeup_student/add_student.py @ 10059

Last change on this file since 10059 was 2538, checked in by joachim, 17 years ago

redirect none SectionOfficers? to anonymous_view (in custom)

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1##parameters=REQUEST
2# $Id: add_student.py 2538 2007-11-05 16:19:18Z joachim $
3"""
4process the the accommodation reservation
5"""
6import DateTime
7current = DateTime.DateTime()
8pr = context.portal_registration
9wftool = context.portal_workflow
10lt = context.portal_layouts
11mtool = context.portal_membership
12member = mtool.getAuthenticatedMember()
13acco_cat = context.portal_accommodation
14import logging
15logger = logging.getLogger('Skins.add_student')
16
17if mtool.isAnonymousUser() or not context.isSectionOfficer():
18    return REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
19
20validate = REQUEST.has_key("cpsdocument_edit_button") and\
21           REQUEST.get("cpsdocument_edit_button").startswith('Add')
22d = {}
23mode = 'edit'
24rendered,psm,ds = lt.renderLayout(layout_id= 'add_student',
25                      schema_id= 'add_student',
26                      context=context,
27                      mapping=validate and REQUEST,
28                      ob=d,
29                      layout_mode=mode,
30                      commit = False
31                      )
32if psm == 'invalid':
33    psm = "Please correct your input."
34    return context.add_student_form(rendered = rendered,
35                                 psm = psm,
36                                 #psm = "%s, %s" % (psm,ds),
37                                 mode = mode,
38                                 formaction = "add_student",
39                                 button = "Add",
40                                 ds = ds,
41                                 )
42elif psm == '':
43    return context.add_student_form(rendered = rendered,
44                                 psm = psm,
45                                 mode = mode,
46                                 formaction = "add_student",
47                                 button = "Add",
48                                 ds = ds,
49                                 )
50elif psm == 'valid':
51    pass
52matric_no = ds.get('matric_no')
53if matric_no:
54    res = context.students_catalog(matric_no = matric_no)
55    if res:
56        psm = "Student with matric_no %s exists with Id: %s" % (matric_no,res[0].id)
57        return context.add_student_form(rendered = rendered,
58                                 psm = psm,
59                                 #psm = "%s, %s" % (psm,ds),
60                                 mode = mode,
61                                 formaction = "add_student",
62                                 button = "Add",
63                                 ds = ds,
64                                 )
65dict = {}
66dict.update(ds)
67sid,password = context.waeup_tool.addStudent(dict)
68dict['sid'] = sid
69dict['password'] = password
70student_rec = context.getFormattedStudentEntry(context.students_catalog(id = sid)[0])
71psm = "Student record with Id %s and Password %s has been created." % (sid,password)
72logger.info('%s created student %s' % (member,sid))
73return context.add_student_form(rendered = rendered,
74                                 mode = 'view',
75                                 psm = psm,
76                                 ds = dict,
77                                 student = student_rec,
78                                 )
79
80
Note: See TracBrowser for help on using the repository browser.