Changeset 3462 for framework

Show
Ignore:
Timestamp:
04/27/10 11:46:53 (2 years ago)
Author:
elemoine
Message:

allow providing a before_delete callback to Protocol, r=aabt (closes #566)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • framework/server/trunk/mapfish/lib/protocol.py

    r3368 r3462  
    188188          before_create 
    189189            a callback function called before a feature is inserted 
    190             in the database table, the function receives the request 
    191             and the feature about to be inserted. 
     190            in the database table, the function receives the request, 
     191            the feature read from the GeoJSON document sent in the 
     192            request, and the database object to be updated. The 
     193            latter is None if this is is an actual insertion. 
    192194 
    193195          before_update 
    194196            a callback function called before a feature is updated 
     197            in the database table, the function receives the request, 
     198            the feature read from the GeoJSON document sent in the 
     199            request, and the database object to be updated. 
     200 
     201          before_delete 
     202            a callback function called before a feature is deleted 
    195203            in the database table, the function receives the request 
    196             and the feature about to be updated. 
     204            and the database object about to be deleted. 
    197205    """ 
    198206 
     
    208216        if kwargs.has_key('before_update'): 
    209217            self.before_update = kwargs['before_update'] 
     218        self.before_delete = None 
     219        if kwargs.has_key('before_delete'): 
     220            self.before_delete = kwargs['before_delete'] 
    210221 
    211222    def _encode(self, objects, request, response): 
     
    343354            create = False 
    344355            obj = None 
    345             if self.before_create is not None: 
    346                 self.before_create(request, feature) 
    347356            if isinstance(feature.id, int): 
    348357                obj = self.Session.query(self.mapped_class).get(feature.id) 
     358            if self.before_create is not None: 
     359                self.before_create(request, feature, obj) 
    349360            if obj is None: 
    350361                obj = self.mapped_class() 
     
    377388            abort(400) 
    378389        if self.before_update is not None: 
    379             self.before_update(request, feature) 
     390            self.before_update(request, feature, obj) 
    380391        obj.geometry = asShape(feature.geometry) 
    381392        for key in feature.properties: 
     
    392403        if obj is None: 
    393404            abort(404) 
     405        if self.before_delete is not None: 
     406            self.before_delete(request, obj) 
    394407        self.Session.delete(obj) 
    395408        self.Session.commit()