Ignore:
Timestamp:
16 Nov 2015, 09:05:30 (9 years ago)
Author:
Henrik Bettermann
Message:

Add option which allows students to select a desired hostel before booking accommodation.

File:
1 edited

Legend:

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

    r13455 r13457  
    19281928    grok.template('accommodationmanagepage')
    19291929    pnav = 4
    1930     officers_only_actions = [_('Remove selected')]
     1930    with_hostel_selection = True
     1931
     1932    @property
     1933    def actionsgroup1(self):
     1934        if not self.with_hostel_selection:
     1935            return []
     1936        students_utils = getUtility(IStudentsUtils)
     1937        acc_details  = students_utils.getAccommodationDetails(self.context.student)
     1938        error_message = students_utils.checkAccommodationRequirements(
     1939            self.context.student, acc_details)
     1940        if error_message:
     1941            return []
     1942        return [_('Save')]
     1943
     1944    @property
     1945    def actionsgroup2(self):
     1946        if getattr(self.request.principal, 'user_type', None) == 'student':
     1947            return [_('Book accommodation')]
     1948        return [_('Book accommodation'), _('Remove selected')]
    19311949
    19321950    @property
     
    19341952        return _('${a}: Accommodation',
    19351953            mapping = {'a':self.context.__parent__.display_fullname})
     1954
     1955    def getHostels(self):
     1956        """Get a list of all stored hostels.
     1957        """
     1958        yield(dict(name=None, title='--', selected=''))
     1959        for val in grok.getSite()['hostels'].values():
     1960            selected = ''
     1961            if val.hostel_id == self.context.desired_hostel:
     1962                selected = 'selected'
     1963            yield(dict(name=val.hostel_id, title=val.hostel_name,
     1964                       selected=selected))
     1965
     1966    @action(_('Save'), style='primary')
     1967    def save(self):
     1968        hostel = self.request.form.get('hostel', None)
     1969        self.context.desired_hostel = hostel
     1970        self.flash(_('Your selection has been saved.'))
     1971        return
     1972
     1973    @jsaction(_('Book accommodation'), style='primary')
     1974    def bookAccommodation(self, **data):
     1975        self.redirect(self.url(self.context, 'add'))
     1976        return
    19361977
    19371978    @jsaction(_('Remove selected'))
     
    19622003        self.redirect(self.url(self.context))
    19632004        return
    1964 
    1965     @property
    1966     def selected_actions(self):
    1967         if getattr(self.request.principal, 'user_type', None) == 'student':
    1968             return [action for action in self.actions
    1969                     if not action.label in self.officers_only_actions]
    1970         return self.actions
    19712005
    19722006class BedTicketAddPage(KofaPage):
     
    20302064            if available_beds:
    20312065                students_utils = getUtility(IStudentsUtils)
    2032                 bed = students_utils.selectBed(available_beds)
     2066                bed = students_utils.selectBed(
     2067                    available_beds, self.context.desired_hostel)
     2068                if bed is None:
     2069                    self.flash(_(
     2070                        'There is no free bed in your desired hostel. '
     2071                        'Please try another hostel.'),
     2072                        type="warning")
     2073                    self.redirect(self.url(self.context))
     2074                    return
    20332075                # Safety belt for paranoids: Does this bed really exist
    20342076                # in portal?
     
    20452087                self.flash(_('There is no free bed in your category ${a}.',
    20462088                    mapping = {'a':acc_details['bt']}), type="warning")
     2089                self.redirect(self.url(self.context))
    20472090                return
    20482091        if self.with_ac:
Note: See TracChangeset for help on using the changeset viewer.