Changeset 13457 for main/waeup.kofa/trunk
- Timestamp:
- 16 Nov 2015, 09:05:30 (9 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r13432 r13457 4 4 1.3.4.dev0 (unreleased) 5 5 ======================= 6 7 * Add option which allows students to select a desired hostel before 8 booking accommodation. 6 9 7 10 * Add BedProcessor. -
main/waeup.kofa/trunk/src/waeup/kofa/students/accommodation.py
r13455 r13457 133 133 entry for entry in entries if entry.owner == NOT_OCCUPIED] 134 134 if available_beds: 135 new_bed = students_utils.selectBed(available_beds) 135 new_bed = students_utils.selectBed( 136 available_beds, self.__parent__.desired_hostel) 137 if new_bed is None: 138 return False, _( 139 'There is no free bed in your desired hostel.') 136 140 new_bed.bookBed(student.student_id) 137 141 else: -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r13455 r13457 1928 1928 grok.template('accommodationmanagepage') 1929 1929 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')] 1931 1949 1932 1950 @property … … 1934 1952 return _('${a}: Accommodation', 1935 1953 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 1936 1977 1937 1978 @jsaction(_('Remove selected')) … … 1962 2003 self.redirect(self.url(self.context)) 1963 2004 return 1964 1965 @property1966 def selected_actions(self):1967 if getattr(self.request.principal, 'user_type', None) == 'student':1968 return [action for action in self.actions1969 if not action.label in self.officers_only_actions]1970 return self.actions1971 2005 1972 2006 class BedTicketAddPage(KofaPage): … … 2030 2064 if available_beds: 2031 2065 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 2033 2075 # Safety belt for paranoids: Does this bed really exist 2034 2076 # in portal? … … 2045 2087 self.flash(_('There is no free bed in your category ${a}.', 2046 2088 mapping = {'a':acc_details['bt']}), type="warning") 2089 self.redirect(self.url(self.context)) 2047 2090 return 2048 2091 if self.with_ac: -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/accommodationmanagepage.pt
r13455 r13457 1 1 <form action="." tal:attributes="action request/URL" method="POST" 2 2 i18n:domain="waeup.kofa" enctype="multipart/form-data"> 3 4 <tal:desired_hostel condition="view/actionsgroup1"> 5 <br /> 6 <p i18n:translate=""> 7 Select and save the <strong>desired hostel</strong> before booking acommodation. 8 Your choice cannot be changed afterwards. 9 </p> 10 <div class="form-inline"> 11 <br /> 12 <div class="form-group"> 13 <select class="form-control" id="hostel" name="hostel"> 14 <option tal:repeat="hostel view/getHostels" 15 tal:attributes="value hostel/name; selected hostel/selected"> 16 <span tal:replace="hostel/title">USERTITLE 17 </span> 18 </option> 19 </select> 20 </div> 21 <div class="form-group"> 22 <span tal:repeat="action view/actions" tal:omit-tag=""> 23 <input tal:condition="python:action.label in view.actionsgroup1" 24 tal:replace="structure action/render"/> 25 </span> 26 </div> 27 </div> 28 <br /> 29 </tal:desired_hostel> 30 31 <h3 i18n:domain="waeup.kofa" i18n:translate="">Bookings</h3> 32 <br /> 3 33 4 34 <table class="kofa-data-table dataTableManage"> … … 28 58 </table> 29 59 30 < div tal:condition="view/availableActions">31 <span tal:repeat="action view/selected_actions"32 tal:omit-tag="">33 <inputtal:replace="structure action/render"/>34 35 </div> 60 <span tal:repeat="action view/actions" 61 tal:omit-tag=""> 62 <input tal:condition="python:action.label in view.actionsgroup2" 63 tal:replace="structure action/render"/> 64 </span> 65 36 66 </form> -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r13345 r13457 251 251 phone = PhoneNumber( 252 252 title = _(u'Phone'), 253 description = u'',254 253 required = False, 255 254 ) … … 697 696 """ 698 697 698 desired_hostel = schema.TextLine( 699 title = _(u'Desired Hostel'), 700 required = False, 701 ) 702 699 703 def addBedTicket(bedticket): 700 704 """Add a bed ticket object. -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r13455 r13457 1203 1203 # Managers can use HOS code and book a bed space with it 1204 1204 self.browser.open(self.acco_path) 1205 self.browser.get Link("Book accommodation").click()1205 self.browser.getControl("Book accommodation").click() 1206 1206 self.assertMatches('...You are in the wrong...', 1207 1207 self.browser.contents) … … 1210 1210 # are in accommodation session 1211 1211 self.student['studycourse'].current_session = 2003 1212 self.browser.get Link("Book accommodation").click()1212 self.browser.getControl("Book accommodation").click() 1213 1213 self.assertMatches('...Your current session does not match...', 1214 1214 self.browser.contents) 1215 1215 self.student['studycourse'].current_session = 2004 1216 1216 # All requirements are met and ticket can be created 1217 self.browser.get Link("Book accommodation").click()1217 self.browser.getControl("Book accommodation").click() 1218 1218 self.assertMatches('...Activation Code:...', 1219 1219 self.browser.contents) … … 1227 1227 self.assertTrue(bed1.owner == self.student_id) 1228 1228 # BedTicketAddPage is now blocked 1229 self.browser.get Link("Book accommodation").click()1229 self.browser.getControl("Book accommodation").click() 1230 1230 self.assertMatches('...You already booked a bed space...', 1231 1231 self.browser.contents) … … 3008 3008 3009 3009 def test_student_accommodation(self): 3010 # Create a second hostel with one bed 3011 hostel = Hostel() 3012 hostel.hostel_id = u'hall-2' 3013 hostel.hostel_name = u'Hall 2' 3014 self.app['hostels'].addHostel(hostel) 3015 bed = Bed() 3016 bed.bed_id = u'hall-2_A_101_A' 3017 bed.bed_number = 1 3018 bed.owner = NOT_OCCUPIED 3019 bed.bed_type = u'regular_female_fr' 3020 self.app['hostels'][hostel.hostel_id].addBed(bed) 3021 3010 3022 self.browser.open(self.login_path) 3011 3023 self.browser.getControl(name="form.login").value = self.student_id … … 3032 3044 # ... but not if booking period has expired ... 3033 3045 self.app['hostels'].enddate = datetime.now(pytz.utc) 3034 self.browser.get Link("Book accommodation").click()3046 self.browser.getControl("Book accommodation").click() 3035 3047 self.assertMatches('...Outside booking period: ...', 3036 3048 self.browser.contents) … … 3038 3050 # ... or student data are incomplete ... 3039 3051 self.student['studycourse'].current_level = None 3040 self.browser.get Link("Book accommodation").click()3052 self.browser.getControl("Book accommodation").click() 3041 3053 self.assertMatches('...Your data are incomplete...', 3042 3054 self.browser.contents) 3043 3055 self.student['studycourse'].current_level = 100 3044 3056 # ... or student is not the an allowed state ... 3045 self.browser.get Link("Book accommodation").click()3057 self.browser.getControl("Book accommodation").click() 3046 3058 self.assertMatches('...You are in the wrong...', 3047 3059 self.browser.contents) 3060 # Students can still not see the disired hostel selector. 3061 self.assertFalse('desired hostel' in self.browser.contents) 3048 3062 IWorkflowInfo(self.student).fireTransition('admit') 3049 self.browser.getLink("Book accommodation").click() 3063 # Students can now see the disired hostel selector. 3064 self.browser.reload() 3065 self.browser.open(self.acco_path) 3066 self.assertTrue('desired hostel' in self.browser.contents) 3067 self.browser.getControl(name="hostel").value = ['hall-2'] 3068 self.browser.getControl("Save").click() 3069 self.assertTrue('selection has been saved' in self.browser.contents) 3070 self.assertTrue('<option selected="selected" value="hall-2">' 3071 in self.browser.contents) 3072 self.browser.getControl("Book accommodation").click() 3050 3073 self.assertMatches('...Activation Code:...', 3051 3074 self.browser.contents) … … 3058 3081 # ... or ACs owned by somebody else. 3059 3082 ac.owner = u'Anybody' 3083 self.browser.getControl(name="ac_series").value = sfeseries 3084 self.browser.getControl(name="ac_number").value = sfenumber 3085 self.browser.getControl("Create bed ticket").click() 3086 # Hostel 2 has only a bed for women. 3087 self.assertTrue('There is no free bed in your desired hostel' 3088 in self.browser.contents) 3089 self.browser.getControl(name="hostel").value = ['hall-1'] 3090 self.browser.getControl("Save").click() 3091 self.browser.getControl("Book accommodation").click() 3092 # Student can't use faked ACs ... 3060 3093 self.browser.getControl(name="ac_series").value = sfeseries 3061 3094 self.browser.getControl(name="ac_number").value = sfenumber … … 3075 3108 self.assertTrue(bed.owner == self.student_id) 3076 3109 # BedTicketAddPage is now blocked. 3077 self.browser.get Link("Book accommodation").click()3110 self.browser.getControl("Book accommodation").click() 3078 3111 self.assertMatches('...You already booked a bed space...', 3079 3112 self.browser.contents) -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r13304 r13457 627 627 return 628 628 629 def selectBed(self, available_beds): 630 """Select a bed from a list of available beds. 631 In the base configuration we select the first bed found, 632 but can also randomize the selection if we like. 633 """ 634 return available_beds[0] 629 def selectBed(self, available_beds, desired_hostel=None): 630 """Select a bed from a filtered list of available beds. 631 In the base configuration beds are sorted by the sort id 632 of the hostel and the bed number. The first bed found in 633 this sorted list is taken. 634 """ 635 sorted_beds = sorted(available_beds, 636 key=lambda bed: 1000 * bed.__parent__.sort_id + bed.bed_number) 637 if desired_hostel: 638 # Filter desired hostel beds 639 filtered_beds = [bed for bed in sorted_beds 640 if bed.bed_id.startswith(desired_hostel)] 641 if not filtered_beds: 642 return 643 return filtered_beds[0] 644 return sorted_beds[0] 635 645 636 646 def _admissionText(self, student, portal_language): -
main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py
r13129 r13457 501 501 return self.view.url(self.view.context, self.target) 502 502 503 class AddBedTicketActionButton(ManageActionButton):504 grok.order(1)505 grok.context(IStudentAccommodation)506 grok.view(AccommodationManageFormPage)507 grok.require('waeup.handleAccommodation')508 icon = 'actionicon_home.png'509 text = _('Book accommodation')510 target = 'add'511 512 503 class BedTicketSlipActionButton(ManageActionButton): 513 504 grok.order(1)
Note: See TracChangeset for help on using the changeset viewer.