Ignore:
Timestamp:
30 Oct 2011, 08:29:17 (13 years ago)
Author:
Henrik Bettermann
Message:

First version of bed creator (work in progress).

Location:
main/waeup.sirp/trunk/src/waeup/sirp/hostels
Files:
1 added
5 edited

Legend:

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

    r6966 r6970  
    142142    grok.require('waeup.manageHostels')
    143143    grok.name('addhostel')
    144     grok.template('hosteladdpage')
     144    #grok.template('hosteladdpage')
    145145    form_fields = grok.AutoFields(IHostel)
    146146    title = 'Hostels'
     
    186186    grok.require('waeup.manageHostels')
    187187    text = 'Manage'
    188     target = 'edit'
     188    target = 'manage'
    189189
    190190class HostelManageFormPage(WAeUPEditFormPage):
     
    192192    """
    193193    grok.context(IHostel)
    194     grok.name('edit')
     194    grok.name('manage')
    195195    grok.require('waeup.manageHostels')
    196196    form_fields = grok.AutoFields(IHostel).omit('hostel_id')
    197     #grok.template('hostelmanagepage')
     197    grok.template('hostelmanagepage')
    198198    label = 'Manage hostel'
    199199    pnav = 5
     200    taboneactions = ['Save']
     201    tabtwoactions = ['Update beds']
    200202
    201203    @property
     
    205207    def update(self):
    206208        datepicker.need() # Enable jQuery datepicker in date fields.
     209        tabs.need()
     210        datatable.need()
    207211        super(HostelManageFormPage, self).update()
    208212        return
     
    212216        msave(self, **data)
    213217        return
     218
     219    @grok.action('Update beds')
     220    def updateBeds(self, **data):
     221        added, modified = self.context.updateBeds()
     222        self.flash('%d added, %d modified' % (added, modified))
     223        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     224        return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r6963 r6970  
    2323from waeup.sirp.hostels.interfaces import IHostel, IBed
    2424
     25NOT_OCCUPIED = u'not occupied'
     26
    2527class Hostel(grok.Container):
    2628    """This is a hostel.
     
    3436
    3537    def addBed(self, bed):
    36         """Add a hostel.
     38        """Add a bed.
    3739        """
    3840        if not IBed.providedBy(bed):
    3941            raise TypeError(
    4042                'Hostels contain only IBed instances')
    41         self[hostel.bed_id] = bed
     43        self[bed.bed_id] = bed
    4244        return
     45
     46    # not yet tested nor used
     47    def updateBeds(self):
     48        """Fill hostel with beds or update beds.
     49        """
     50        added_counter = 0
     51        modified_counter = 0
     52        blocks_for_female = getattr(self,'blocks_for_female',[])
     53        blocks_for_male = getattr(self,'blocks_for_male',[])
     54        beds_for_fresh = getattr(self,'beds_for_fresh',[])
     55        beds_for_pre = getattr(self,'beds_for_pre',[])
     56        beds_for_returning = getattr(self,'beds_for_returning',[])
     57        beds_for_final = getattr(self,'beds_for_final',[])
     58        beds_reserved = [] #temporarily empty
     59        all_blocks = blocks_for_female + blocks_for_male
     60        all_beds = (beds_for_pre + beds_for_fresh +
     61            beds_for_returning + beds_for_final)
     62        #import pdb;pdb.set_trace()
     63        for block in all_blocks:
     64            sex = 'male'
     65            if block in blocks_for_female:
     66                sex = 'female'
     67            for floor in range(1,int(self.floors_per_block)+1):
     68                for room in range(1,int(self.rooms_per_floor)+1):
     69                    for bed in all_beds:
     70                        room_nr = floor*100 + room
     71                        bt = 'all'
     72                        if (block,room_nr) in beds_reserved:
     73                            bt = "reserved"
     74                        # Hostels with special handling and
     75                        # without bed categorisation
     76                        elif (self.special_handling != 'none' and not
     77                              self.special_handling.endswith("_withcat")):
     78                            bt = self.special_handling[3:]
     79                        elif bed in beds_for_fresh:
     80                            bt = 'fr'
     81                        elif bed in beds_for_pre:
     82                            bt = 'pr'
     83                        elif bed in beds_for_final:
     84                            bt = 'fi'
     85                        elif bed in beds_for_returning:
     86                            bt = 're'
     87                        # Hostels with special handling and
     88                        # with bed categorisation
     89                        if (self.special_handling != 'none' and
     90                            self.special_handling.endswith("_withcat")):
     91                            bt += "_" + self.special_handling
     92                        bt = u'%(sex)s_%(bt)s' % vars()
     93                        uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed)
     94                        if self.has_key(uid):
     95                            bed = self[uid]
     96                            if bed.bed_type != bt:
     97                                bed.bed_type = bt
     98                                bed.sort_id = getattr(self,'sort_id',0)
     99                                #modified.append('"%(uid)s","%(bt)s","%(bed.owner)s"' % vars())
     100                                modified_counter += 1
     101                        else:
     102                            bed = Bed()
     103                            bed.bed_id = uid
     104                            bed.bed_type = bt
     105                            bed.sort_id = getattr(self,'sort_id',0)
     106                            bed.owner = NOT_OCCUPIED
     107                            self.addBed(bed)
     108                            #generated.append('"%(uid)s","%(bt)s"' % vars())
     109                            added_counter +=1
     110        return added_counter, modified_counter
    43111
    44112Hostel = attrs_to_fields(Hostel)
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py

    r6963 r6970  
    11##
    22## interfaces.py
    3 from zope.interface import Attribute, invariant
     3from zope.interface import Attribute, invariant, Invalid
    44from zope import schema
    55from waeup.sirp.interfaces import IWAeUPObject
    6 from waeup.sirp.hostels.vocabularies import bed_letters, blocks
     6from waeup.sirp.hostels.vocabularies import (
     7    bed_letters, blocks, special_handling)
    78
    89class IHostelsContainer(IWAeUPObject):
     
    1819    def loggerInfo(ob_class, comment):
    1920        """Adds an INFO message to the log file
     21        """
     22
     23    def updateBeds():
     24        """Fill hostel with beds or update beds.
    2025        """
    2126
     
    3742        )
    3843
    39     nr_of_blocks = schema.Int(
    40         title = u'Number of Blocks',
    41         required = True,
    42         default = 3,
    43         )
    44 
    4544    floors_per_block = schema.Int(
    4645        title = u'Floors per Block',
     
    5554        )
    5655
    57     beds_per_room = schema.Int(
    58         title = u'Beds per Room',
    59         required = True,
    60         default = 6,
    61         )
     56    #beds_per_room = schema.Int(
     57    #    title = u'Beds per Room',
     58    #    required = True,
     59    #    default = 6,
     60    #    )
    6261
    6362    blocks_for_female = schema.List(
    6463        title = u'Blocks for Female Students',
     64        value_type = schema.Choice(
     65            vocabulary = blocks
     66            ),
     67        )
     68
     69    blocks_for_male = schema.List(
     70        title = u'Blocks for Male Students',
    6571        value_type = schema.Choice(
    6672            vocabulary = blocks
     
    7581        )
    7682
     83    beds_for_returning = schema.List(
     84        title = u'Beds for Returning Students',
     85        value_type = schema.Choice(
     86            vocabulary = bed_letters
     87            ),
     88        )
     89
    7790    beds_for_final = schema.List(
    7891        title = u'Beds for Final Year Students',
     
    8194            ),
    8295        )
     96
     97    special_handling = schema.Choice(
     98        title = u'Special Handling',
     99        vocabulary = special_handling,
     100        required = True,
     101        default = u'none',
     102        )
     103
     104    reserved = schema.TextLine(
     105        title = u'Reserved Rooms',
     106        required = False,
     107        default = u'',
     108        )
     109
     110    @invariant
     111    def blocksOverlap(hostel):
     112        bfe = hostel.blocks_for_female
     113        bma = hostel.blocks_for_male
     114        if set(bfe).intersection(set(bma)):
     115            raise Invalid('Female and male blocks overlap.')
     116
     117    @invariant
     118    def bedsOverlap(hostel):
     119        bfr = hostel.beds_for_fresh
     120        bre = hostel.beds_for_returning
     121        bfi = hostel.beds_for_final
     122        if (set(bfr).intersection(set(bre)) or
     123            set(bfr).intersection(set(bfi)) or
     124            set(bre).intersection(set(bfi))):
     125            raise Invalid('Bed categories overlap.')
     126
     127    #@invariant
     128    #def numberOfBeds(hostel):
     129    #    bfr = hostel.beds_for_fresh
     130    #    bre = hostel.beds_for_returning
     131    #    bfi = hostel.beds_for_final
     132    #    if len(bfr + bre + bfi) != hostel.beds_per_room:
     133    #        raise Invalid(
     134    #            'Bed categories and number of beds per room do not match.')
    83135
    84136class IBed(IWAeUPObject):
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r6963 r6970  
    133133<li>Block B</li></ul>...'''
    134134        self.assertMatches(expected,self.browser.contents)
    135         self.browser.open(self.container_path + '/hall_1/edit')
    136         self.browser.getControl(name="form.nr_of_blocks").value = '5'
     135        self.browser.open(self.container_path + '/hall_1/manage')
     136        self.browser.getControl(name="form.floors_per_block").value = '4'
    137137        self.browser.getControl("Save").click()
    138138        self.assertTrue('Form has been saved' in self.browser.contents)
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py

    r6958 r6970  
    3434    ('Block P','P'),
    3535    )
     36
     37special_handling = SimpleWAeUPVocabulary(
     38    ('No special handling','none'),
     39    ('Blocked','blocked'),
     40    ('Postgraduate Hostel','pg'),
     41    )
Note: See TracChangeset for help on using the changeset viewer.