Changeset 6996


Ignore:
Timestamp:
4 Nov 2011, 14:36:44 (15 years ago)
Author:
Henrik Bettermann
Message:

Implement bed booking algorithm (work in progress!).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
8 edited

Legend:

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

    r6988 r6996  
    3535from waeup.sirp.authentication import get_principal_role_manager
    3636from waeup.sirp.hostels.container import HostelsContainer
    37 from waeup.sirp.hostels.hostel import Hostel
     37from waeup.sirp.hostels.hostel import Hostel, NOT_OCCUPIED
    3838from waeup.sirp.hostels.interfaces import IHostelsContainer, IHostel
    3939
    … …  
    204204        'Switch reservation of selected beds',
    205205        'Release selected beds']
     206    not_occupied = NOT_OCCUPIED
    206207
    207208    @property
    208209    def title(self):
    209210        return self.context.hostel_name
     211
     212    @property
     213    def students_url(self):
     214        return self.url(grok.getSite(),'students')
    210215
    211216    def update(self):
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser_templates/hostelmanagepage.pt

    r6971 r6996  
    7979                  tal:attributes="value value/__name__" />
    8080          </td>
    81           <td> <a tal:attributes="href value/__name__">
    82           <span tal:content="value/bed_id">Id</span>
    83           </a></td>
     81          <td tal:content="value/bed_id">Id</td>
    8482          <td tal:content="value/bed_type">Type</td>
    8583          <td tal:content="value/bed_number">Number</td>
    86           <td tal:content="value/owner">Owner</td>
     84          <td>
     85            <a tal:condition="python: value.owner != view.not_occupied"
     86               tal:attributes="href python: '%s/%s' % (view.students_url,value.owner)">
     87              <span tal:content="value/owner">Owner</span>
     88            </a>
     89          </td>
    8790        </tr>
    8891      </tbody>
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r6991 r6996  
    121121        return self.bed_id.split('_')
    122122
     123    def bookBed(self, student_id):
     124        self.owner = student_id
     125        return
     126
    123127    def switchReservation(self):
    124128        """Reserves a bed or unreserve bed respectively.
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py

    r6981 r6996  
    142142        """Determine the coordinates from bed_id.
    143143        """
     144    def bookBed(student_id):
     145        """Book a bed for a student.
     146        """
    144147
    145148    def switchReservation():
  • main/waeup.sirp/trunk/src/waeup/sirp/students/accommodation.py

    r6994 r6996  
    6060        super(BedTicket, self).__init__()
    6161        self.booking_date = datetime.now()
     62        self.bed = None
    6263        return
    6364
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r6994 r6996  
    1919from time import time
    2020from datetime import date, datetime
     21from zope.catalog.interfaces import ICatalog
     22from zope.component import queryUtility
    2123from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2224from zope.component import createObject
    … …  
    4749from waeup.sirp.students.studylevel import StudentStudyLevel, CourseTicket
    4850from waeup.sirp.students.vocabularies import StudyLevelSource
    49 from waeup.sirp.students.utils import getPaymentDetails
    50 from waeup.sirp.students.utils import getAccommodationDetails
     51from waeup.sirp.students.utils import (
     52    getPaymentDetails, getAccommodationDetails,)
    5153from waeup.sirp.browser.resources import toggleall
    5254from waeup.sirp.authentication import get_principal_role_manager
    … …  
    10891091
    10901092    def update(self, SUBMIT=None):
    1091         acc_details  = self.getAccommodationDetails(self.context.__parent__)
    1092         if not self.context.getStudent().state in acc_details['allowed_states']:
     1093        student = self.context.getStudent()
     1094        acc_details  = self.getAccommodationDetails(student)
     1095        if not student.state in acc_details['allowed_states']:
    10931096            self.flash("Wrong state.")
    10941097            self.redirect(self.url(self.context))
    … …  
    11191122        bedticket.booking_code = pin
    11201123        bedticket.booking_session = acc_details['booking_session']
    1121         bedticket.bed = u'Test Bed'
    1122         self.context[str(acc_details['booking_session'])] = bedticket
    1123         self.flash('Bed ticket created.')
     1124        bedticket.bed_type = acc_details['bt']
     1125        # Search and book bed
     1126        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
     1127        entries = cat.searchResults(
     1128            bed_type=(bedticket.bed_type,bedticket.bed_type))
     1129        bed = [entry for entry in entries if entry.owner == NOT_OCCUPIED][0] # first bed found
     1130        bed.bookBed(student.student_id)
     1131        bedticket.bed = bed # maybe wo don't need the bed object itself
     1132        hall_title = bed.__parent__.hostel_name
     1133        coordinates = bed.getBedCoordinates()[1:]
     1134        block, room_nr, bed_nr = coordinates
     1135        bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
     1136            hall_title, block, room_nr, bed_nr)
     1137        key = str(acc_details['booking_session'])
     1138        self.context[key] = bedticket
     1139        self.flash('Bed ticket created and bed booked: %s'
     1140            % bedticket.bed_coordinates)
    11241141        self.redirect(self.url(self.context))
    11251142        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r6994 r6996  
    11##
    22## interfaces.py
     3from datetime import datetime
    34from zope.interface import Attribute, invariant
    45from zope.interface.exceptions import Invalid
    … …  
    910from waeup.sirp.students.vocabularies import (
    1011  CertificateSource, academic_sessions_vocab, verdicts, StudyLevelSource,
    11   contextual_reg_num_source, contextual_mat_num_source,
     12  contextual_reg_num_source, contextual_mat_num_source, GenderSource,
    1213  )
    1314from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment
    … …  
    110111        )
    111112
     113    sex = schema.Choice(
     114        title = u'Sex',
     115        source = GenderSource(),
     116        default = u'm',
     117        required = True,
     118        )
     119
    112120    reg_number = TextLineChoice(
    113121        title = u'Registration Number',
    … …  
    132140        readonly = True,
    133141        )
     142
     143class IStudentClearance(IWAeUPObject):
     144    """Representation of student clearance data.
     145    """
     146
     147    date_of_birth = schema.Date(
     148        title = u'Date of Birth',
     149        required = True,
     150        )
     151
     152    clearance_locked = schema.Bool(
     153        title = u'Clearance form locked',
     154        default = False,
     155        )
     156
     157    clr_code = schema.TextLine(
     158        title = u'CLR Activation Code',
     159        default = u'',
     160        required = False,
     161        readonly = True,
     162        )
     163
     164class IStudentPersonal(IWAeUPObject):
     165    """Representation of student personal data.
     166    """
     167
     168    perm_address = schema.Text(
     169        title = u'Permanent Address',
     170        required = False,
     171        )
     172
     173class IStudent(IStudentBase,IStudentClearance,IStudentPersonal):
     174    """Representation of a student.
     175    """
     176
     177class IStudentUpdateByRegNo(IStudent):
     178    """Representation of a student. Skip regular reg_number validation.
     179    """
     180
     181    reg_number = schema.TextLine(
     182        title = u'Registration Number',
     183        default = None,
     184        required = False,
     185        )
     186
     187class IStudentUpdateByMatricNo(IStudent):
     188    """Representation of a student. Skip regular matric_number validation.
     189    """
     190
     191    matric_number = schema.TextLine(
     192        title = u'Matriculation Number',
     193        default = None,
     194        required = False,
     195        )
     196
     197class IStudentStudyCourse(IWAeUPObject):
     198    """A container for student study levels.
     199
     200    """
     201
     202    certificate = schema.Choice(
     203        title = u'Certificate',
     204        source = CertificateSource(),
     205        default = None,
     206        required = True,
     207        )
     208
    134209
    135210    entry_mode = schema.Choice(
    … …  
    141216        )
    142217
    143 class IStudentClearance(IWAeUPObject):
    144     """Representation of student clearance data.
    145     """
    146 
    147     date_of_birth = schema.Date(
    148         title = u'Date of Birth',
    149         required = True,
    150         )
    151 
    152     clearance_locked = schema.Bool(
    153         title = u'Clearance form locked',
    154         default = False,
    155         )
    156 
    157     clr_code = schema.TextLine(
    158         title = u'CLR Activation Code',
    159         default = u'',
    160         required = False,
    161         readonly = True,
    162         )
    163 
    164 class IStudentPersonal(IWAeUPObject):
    165     """Representation of student personal data.
    166     """
    167 
    168     perm_address = schema.Text(
    169         title = u'Permanent Address',
    170         required = False,
    171         )
    172 
    173 class IStudent(IStudentBase,IStudentClearance,IStudentPersonal):
    174     """Representation of a student.
    175     """
    176 
    177 class IStudentUpdateByRegNo(IStudent):
    178     """Representation of a student. Skip regular reg_number validation.
    179     """
    180 
    181     reg_number = schema.TextLine(
    182         title = u'Registration Number',
    183         default = None,
    184         required = False,
    185         )
    186 
    187 class IStudentUpdateByMatricNo(IStudent):
    188     """Representation of a student. Skip regular matric_number validation.
    189     """
    190 
    191     matric_number = schema.TextLine(
    192         title = u'Matriculation Number',
    193         default = None,
    194         required = False,
    195         )
    196 
    197 class IStudentStudyCourse(IWAeUPObject):
    198     """A container for student study levels.
    199 
    200     """
    201 
    202     certificate = schema.Choice(
    203         title = u'Certificate',
    204         source = CertificateSource(),
    205         default = None,
    206         required = True,
     218    entry_session = schema.Choice(
     219        title = u'Entry Session',
     220        source = academic_sessions_vocab,
     221        default = datetime.now().year,
     222        required = True,
     223        readonly = False,
    207224        )
    208225
    … …  
    212229        default = None,
    213230        required = True,
     231        readonly = False,
    214232        )
    215233
    … …  
    219237        default = None,
    220238        required = False,
     239        readonly = False,
    221240        )
    222241
    … …  
    320339    """
    321340
    322     bed = schema.TextLine(
    323         title = u'Bed',
     341    bed = Attribute('The bed object.')
     342
     343    bed_coordinates = schema.TextLine(
     344        title = u'Bed Coordinates',
     345        default = None,
     346        required = False,
     347        )
     348
     349    bed_type = schema.TextLine(
     350        title = u'Bed Type',
    324351        default = None,
    325352        required = False,
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r6994 r6996  
    4545        d['amount'] = academic_session.fee_2
    4646    elif category == 'bed_allocation':
    47         #d['p_item'] = student['studycourse'].certificate.code
     47        d['p_item'] = getBedType(student)
    4848        d['amount'] = academic_session.booking_fee
    4949    return d
    … …  
    5353def getAccommodationDetails(student):
    5454    d = {}
    55     d['bookin_fee'] = d['maint_fee'] = 0
    5655    d['error'] = u''
    5756    site_confoguration = getSite()['configuration']
    … …  
    5958    d['allowed_states'] = site_confoguration.accommodation_states
    6059    session = str(d['booking_session'])
     60    # Determine bed type
     61    studycourse = student['studycourse']
     62    entry_session = studycourse.entry_session
     63    current_level = studycourse.current_level
     64    end_level = studycourse.certificate.end_level
     65    if entry_session == getSite()['configuration'].accommodation_session:
     66        bt = 'fr'
     67    elif current_level >= end_level:
     68        bt = 'fi'
     69    else:
     70        bt = 're'
     71    if student.sex == 'f':
     72        sex = 'female'
     73    else:
     74        sex = 'male'
     75    special_handling = 'regular'
     76    d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
    6177    return d
Note: See TracChangeset for help on using the changeset viewer.