Ignore:
Timestamp:
7 Nov 2011, 07:43:23 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement realocation page.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7009 r7015  
    2020from time import time
    2121from datetime import date, datetime
     22from zope.event import notify
    2223from zope.catalog.interfaces import ICatalog
    2324from zope.component import queryUtility
     
    10731074        return
    10741075
    1075     @grok.action('Book accommodation')
    1076     def addBedTicket(self, **data):
    1077         self.redirect(self.url(self.context, '@@add'))
    1078 
    10791076    def isStudent(self):
    10801077        prm = get_principal_role_manager()
     
    10901087        return sa
    10911088
     1089class AddBedTicketActionButton(ManageActionButton):
     1090    grok.order(1)
     1091    grok.context(IStudentAccommodation)
     1092    grok.view(AccommodationManageFormPage)
     1093    grok.require('waeup.handleStudent')
     1094    icon = 'actionicon_home.png'
     1095    text = 'Book accommodation'
     1096    target = 'add'
     1097
    10921098class BedTicketAddPage(WAeUPPage):
    10931099    """ Page to add an online payment ticket
     
    11091115
    11101116    # To be sepezified in customization packages
    1111     def selectBed(self, student):
    1112         return getAccommodationDetails(student)
     1117    def selectBed(self, available_beds):
     1118        return selectBed(available_beds)
    11131119
    11141120    def update(self, SUBMIT=None):
     
    11161122        acc_details  = self.getAccommodationDetails(student)
    11171123        if not student.state in acc_details['allowed_states']:
    1118             self.flash("Wrong state.")
     1124            self.flash("You are in the wrong registration state.")
    11191125            self.redirect(self.url(self.context))
    11201126            return
    11211127        if str(student['studycourse'].entry_session) in self.context.keys():
    1122             self.flash('Ticket for %d already created.'
    1123                 % student['studycourse'].entry_session)
     1128            self.flash('You already booked a bed space for the current accommodation session.')
    11241129            self.redirect(self.url(self.context))
    11251130            return
     
    11691174        bedticket.booking_session = acc_details['booking_session']
    11701175        bedticket.bed_type = acc_details['bt']
    1171         bed = selectBed(available_beds)
     1176        bed = self.selectBed(available_beds)
    11721177        bed.bookBed(student.student_id)
    11731178        bedticket.bed = bed
     
    12021207    def title(self):
    12031208        return 'Bed Ticket %s' % self.context.getSessionString()
     1209
     1210class RelocateStudentActionButton(ManageActionButton):
     1211    grok.order(1)
     1212    grok.context(IBedTicket)
     1213    grok.view(BedTicketDisplayFormPage)
     1214    grok.require('waeup.manageHostels')
     1215    icon = 'actionicon_reload.png'
     1216    text = 'Relocate student'
     1217    target = 'relocate'
     1218
     1219class BedTicketRelocationPage(grok.View):
     1220    """ Callback view
     1221    """
     1222    grok.context(IBedTicket)
     1223    grok.name('relocate')
     1224    grok.require('waeup.manageHostels')
     1225
     1226    # To be sepezified in customization packages
     1227    def getAccommodationDetails(self, student):
     1228        return getAccommodationDetails(student)
     1229
     1230    # To be sepezified in customization packages
     1231    def selectBed(self, available_beds):
     1232        return selectBed(available_beds)
     1233
     1234    # This update method simulates a valid callback und must be
     1235    # specified in the customization package. The parameters must be taken
     1236    # from the incoming request.
     1237    def update(self):
     1238        student = self.context.getStudent()
     1239        acc_details  = self.getAccommodationDetails(student)
     1240        if acc_details['bt'] == self.context.bed_type:
     1241            self.flash("Bed category hasn't changed. Student can't be relocated.")
     1242            return
     1243        # Search a bed and exit if no bed is found or if the student
     1244        # has already booked a bed
     1245        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
     1246        entries = cat.searchResults(
     1247            bed_type=(acc_details['bt'],acc_details['bt']))
     1248        available_beds = [
     1249            entry for entry in entries if entry.owner == NOT_OCCUPIED]
     1250        if not available_beds:
     1251            self.flash('There is no free bed in your category %s.'
     1252                        % acc_details['bt'])
     1253            return
     1254        entries = cat.searchResults(
     1255            owner=(student.student_id,student.student_id))
     1256        # Rlease old bed
     1257        allocated_bed = self.context.bed
     1258        allocated_bed.owner = NOT_OCCUPIED
     1259        notify(grok.ObjectModifiedEvent(allocated_bed))
     1260        # Alocate new bed
     1261        self.context.bed_type = acc_details['bt']
     1262        bed = self.selectBed(available_beds)
     1263        bed.bookBed(student.student_id)
     1264        self.context.bed = bed
     1265        hall_title = bed.__parent__.hostel_name
     1266        coordinates = bed.getBedCoordinates()[1:]
     1267        block, room_nr, bed_nr = coordinates
     1268        self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
     1269            hall_title, block, room_nr, bed_nr)
     1270        self.flash('Student relocated and new bed booked: %s'
     1271            % self.context.bed_coordinates)
     1272        self.redirect(self.url(self.context))
     1273        return
     1274
     1275    def render(self):
     1276        self.redirect(self.url(self.context, '@@index'))
     1277        return
    12041278
    12051279class StudentHistoryPage(WAeUPPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r7009 r7015  
    161161        self.app['configuration'].addSessionConfiguration(configuration)
    162162
    163         # Create a hostel with bed
     163        # Create a hostel with two beds
    164164        hostel = Hostel()
    165165        hostel.hostel_id = u'hall-1'
     
    171171        bed.owner = NOT_OCCUPIED
    172172        bed.bed_type = u'regular_male_fr'
     173        self.app['hostels'][hostel.hostel_id].addBed(bed)
     174        bed = Bed()
     175        bed.bed_id = u'hall-1_A_101_B'
     176        bed.bed_number = 2
     177        bed.owner = NOT_OCCUPIED
     178        bed.bed_type = u'regular_female_fr'
    173179        self.app['hostels'][hostel.hostel_id].addBed(bed)
    174180
     
    834840        self.assertMatches('...Course registration has been started...',
    835841                           self.browser.contents)
    836         self.assertTrue(self.student.state,'school fee paid')
     842        self.assertTrue(self.student.state == 'school fee paid')
    837843        return
    838844
     
    858864        # Managers can use HOS code and book a bed space with it
    859865        self.browser.open(self.acco_student_path)
    860         self.browser.getControl("Book accommodation").click()
    861         self.assertMatches('...Wrong state...',
     866        self.browser.getLink("Book accommodation").click()
     867        self.assertMatches('...You are in the wrong...',
    862868                           self.browser.contents)
    863869        IWorkflowInfo(self.student).fireTransition('admit')
    864         self.browser.getControl("Book accommodation").click()
     870        self.browser.getLink("Book accommodation").click()
    865871        self.assertMatches('...Activation Code:...',
    866872                           self.browser.contents)
     
    872878        # Bed has been allocated
    873879        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
    874         self.assertTrue(bed.owner,self.student_id)
     880        self.assertTrue(bed.owner == self.student_id)
    875881        # BedTicketAddPage is now blocked
    876         self.browser.getControl("Book accommodation").click()
    877         self.assertMatches('...Ticket for 2004 already created...',
     882        self.browser.getLink("Book accommodation").click()
     883        self.assertMatches('...You already booked a bed space...',
    878884            self.browser.contents)
    879885        # The bed ticket displays the data correctly
     
    884890        self.assertMatches('...regular_male_fr...', self.browser.contents)
    885891        self.assertMatches('...%s...' % pin, self.browser.contents)
    886         # Managers cab delete bed tickets
     892        # Managers can relocate students
     893        self.browser.getLink("Relocate student").click()
     894        self.assertMatches(
     895            "...Bed category hasn't changed...", self.browser.contents)
     896        self.student.sex = u'f'
     897        self.browser.getLink("Relocate student").click()
     898        self.assertMatches(
     899            "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents)
     900        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
     901        self.assertTrue(bed1.owner == NOT_OCCUPIED)
     902        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
     903        self.assertTrue(bed2.owner == self.student_id)
     904        # Managers can delete bed tickets
    887905        self.browser.open(self.acco_student_path)
    888906        ctrl = self.browser.getControl(name='val_id')
Note: See TracChangeset for help on using the changeset viewer.