Changeset 6978 for main


Ignore:
Timestamp:
1 Nov 2011, 08:12:36 (13 years ago)
Author:
Henrik Bettermann
Message:

Remove all empty beds when updating a hostel and then refill hostel again. Occupied beds remain in hostel even if they are not part of the new configuration. Tests will follow.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/hostels
Files:
2 edited

Legend:

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

    r6975 r6978  
    223223    @grok.action('Update all beds')
    224224    def updateBeds(self, **data):
    225         added, modified = self.context.updateBeds()
    226         self.flash('%d added, %d modified' % (added, modified))
     225        removed, added, modified = self.context.updateBeds()
     226        self.flash('%d empty beds removed, %d beds added, %d occupied beds modified' % (
     227            removed, added, modified))
    227228        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    228229        return
     
    250251                return
    251252        if len(switched):
    252             #import pdb; pdb.set_trace()
    253             self.flash('Successfully switched: %s' % ', '.join(switched))
     253            self.flash('Successfully switched beds: %s' % ', '.join(switched))
    254254            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    255255        return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r6976 r6978  
    4444        return
    4545
    46     # not yet tested nor used
    4746    def updateBeds(self):
    4847        """Fill hostel with beds or update beds.
     
    5049        added_counter = 0
    5150        modified_counter = 0
     51        removed_counter = 0
     52
     53        # Remove all empty beds. Occupied beds remain in hostel!
     54        keys = list(self.keys()) # create list copy
     55        for key in keys:
     56            if self[key].owner == NOT_OCCUPIED:
     57                del self[key]
     58                self._p_changed = True
     59                removed_counter += 1
     60
    5261        blocks_for_female = getattr(self,'blocks_for_female',[])
    5362        blocks_for_male = getattr(self,'blocks_for_male',[])
     
    8695                            if bed.bed_type != bt:
    8796                                bed.bed_type = bt
    88                                 #modified.append('"%(uid)s","%(bt)s","%(bed.owner)s"' % vars())
    8997                                modified_counter += 1
    9098                        else:
     
    95103                            bed.owner = NOT_OCCUPIED
    96104                            self.addBed(bed)
    97                             #generated.append('"%(uid)s","%(bt)s"' % vars())
    98105                            added_counter +=1
    99         return added_counter, modified_counter
     106        return removed_counter, added_counter, modified_counter
    100107
    101108Hostel = attrs_to_fields(Hostel)
Note: See TracChangeset for help on using the changeset viewer.