source: WAeUP_SRP/branches/srpp_branch/skins/waeup_student/book_accommodation.py @ 13440

Last change on this file since 13440 was 166, checked in by joachim, 19 years ago

=more enhancements

  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1##parameters=REQUEST
2# $Id: book_accommodation.py 166 2005-11-12 14:45:08Z joachim $
3"""
4book an accomodation
5"""
6import DateTime
7current = DateTime.DateTime()
8
9type_name = 'Student'
10ti = context.portal_types[type_name]
11pm = context.portal_membership
12REQUEST.set('type_name',type_name)
13
14validate = REQUEST.has_key("cpsdocument_edit_button")
15
16
17lt = context.portal_layouts
18pr = context.portal_registration
19
20res,psm,ds = lt.renderLayout(layout_id= 'accobook',
21                      schema_id= 'student_accommodation',
22                      context=context,
23                      mapping=validate and REQUEST,
24                      ob={},
25                      layout_mode='create',
26                      submit = "book",
27                      action = 'book_accommodation',
28                      )
29if psm == 'invalid':
30    return context.book_accommodation_form(rendered = res,
31                                 psm = "Please correct your input",
32                                 ds = ds,
33                                 )
34elif psm == '':
35    return context.book_accommodation_form(rendered = res,
36                                 psm = None,
37                                 ds = ds,
38                                 )
39elif psm == 'valid':
40    sf = context.getContent()
41    halls = getattr(context,'accommodation').contentValues()
42    beds = []
43    student = context.PERSONAL.getContent()
44    sf = context.getContent()
45    for hall in halls:
46        h = hall.getContent()
47        ba = int(getattr(h,'beds_assigned',0))
48        bal = getattr(h,'beds_assigned_list',[])
49        nr_of_beds = int(h.nr_of_blocks) * int(h.nr_of_floors) * int(h.rooms_per_floor) * int(h.beds_per_room)
50        if h.which_sex == student.sex and nr_of_beds > len(bal):
51            break
52    dict = {'heading': h.heading,
53            'text': h.text,
54            'which_sex': h.which_sex,
55            'nr_of_blocks': h.nr_of_blocks,
56            'nr_of_floors': h.nr_of_floors,
57            'rooms_per_floor': h.rooms_per_floor,
58            'beds_per_room': h.beds_per_room,
59            'nr_of_free': nr_of_beds,
60            'beds_assigned': ba,
61             }
62    ba += 1
63    dict['beds_assigned'] = ba
64    bal.append(('%s:%d' % (pm.getAuthenticatedMember(),ba)))
65    dict['beds_assigned_list'] = bal
66    h.edit(mapping = dict)
67    ds.set('accommodation', "Bed # %(beds_assigned)s in %(heading)s" % dict)
68    sf.edit(mapping = ds)
69    #psm = "Your not admitted"
70    psm = "h:%(heading)s free:%(nr_of_free)s %(beds_assigned)s" % dict
71
72    ds.set('sc_date',current)
73    sf.setScratchCardData('accommodation',ds)
74
75    return context.booked_accommodation(v=dict)
Note: See TracBrowser for help on using the repository browser.