Ignore:
Timestamp:
5 Sep 2015, 10:15:24 (9 years ago)
Author:
Henrik Bettermann
Message:

Move accommodation requirements checking into StudentsUtils? to ease customization.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

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

    r13241 r13247  
    19881988        students_utils = getUtility(IStudentsUtils)
    19891989        acc_details  = students_utils.getAccommodationDetails(student)
    1990         if acc_details.get('expired', False):
    1991             startdate = acc_details.get('startdate')
    1992             enddate = acc_details.get('enddate')
    1993             if startdate and enddate:
    1994                 tz = getUtility(IKofaUtils).tzinfo
    1995                 startdate = to_timezone(
    1996                     startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
    1997                 enddate = to_timezone(
    1998                     enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
    1999                 self.flash(_("Outside booking period: ${a} - ${b}",
    2000                     mapping = {'a': startdate, 'b': enddate}), type="warning")
    2001             else:
    2002                 self.flash(_("Outside booking period."), type="warning")
    2003             self.redirect(self.url(self.context))
    2004             return
    2005         if not acc_details.get('bt'):
    2006             self.flash(_("Your data are incomplete."), type="warning")
    2007             self.redirect(self.url(self.context))
    2008             return
    2009         if not student.state in acc_details['allowed_states']:
    2010             self.flash(_("You are in the wrong registration state."),
    2011                        type="warning")
    2012             self.redirect(self.url(self.context))
    2013             return
    2014         if student['studycourse'].current_session != acc_details[
    2015             'booking_session']:
    2016             self.flash(
    2017                 _('Your current session does not match accommodation session.'),
    2018                 type="warning")
    2019             self.redirect(self.url(self.context))
    2020             return
    2021         if str(acc_details['booking_session']) in self.context.keys():
    2022             self.flash(
    2023                 _('You already booked a bed space in current ' \
    2024                     + 'accommodation session.'), type="warning")
     1990        error_message = students_utils.checkAccommodationRequirements(
     1991            student, acc_details)
     1992        if error_message:
     1993            self.flash(error_message, type="warning")
    20251994            self.redirect(self.url(self.context))
    20261995            return
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r13224 r13247  
    600600        return d
    601601
     602    def checkAccommodationRequirements(self, student, acc_details):
     603        if acc_details.get('expired', False):
     604            startdate = acc_details.get('startdate')
     605            enddate = acc_details.get('enddate')
     606            if startdate and enddate:
     607                tz = getUtility(IKofaUtils).tzinfo
     608                startdate = to_timezone(
     609                    startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
     610                enddate = to_timezone(
     611                    enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
     612                return _("Outside booking period: ${a} - ${b}",
     613                         mapping = {'a': startdate, 'b': enddate})
     614            else:
     615                return _("Outside booking period.")
     616        if not acc_details.get('bt'):
     617            return _("Your data are incomplete.")
     618        if not student.state in acc_details['allowed_states']:
     619            return _("You are in the wrong registration state.")
     620        if student['studycourse'].current_session != acc_details[
     621            'booking_session']:
     622            return _('Your current session does not '
     623                     'match accommodation session.')
     624        if str(acc_details['booking_session']) in student['accommodation'].keys():
     625            return _('You already booked a bed space in '
     626                     'current accommodation session.')
     627        return
     628
    602629    def selectBed(self, available_beds):
    603630        """Select a bed from a list of available beds.
Note: See TracChangeset for help on using the changeset viewer.