# HG changeset patch # User Sverre Rabbelier # Date 1232900717 0 # Node ID e9611a2288ca03ae9c7d371a09e8addbeea4d743 # Parent f0b02777f403dbf5d19dc2629964bcfca0cf21ea Rename ModelProperties to EntityProperties We use 'model' when referring to the db.Model, the context in which 'ModelProperties' was used we really mean 'entity', which refers to an instantiation of the model. Patch by: Sverre Rabbelier diff -r f0b02777f403 -r e9611a2288ca app/soc/logic/helper/request.py --- a/app/soc/logic/helper/request.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/logic/helper/request.py Sun Jan 25 16:25:17 2009 +0000 @@ -49,5 +49,5 @@ # mark the request completed, if there is any if request_entity: - request_logic.updateModelProperties(request_entity, + request_logic.updateEntityProperties(request_entity, {'state': 'completed'}) diff -r f0b02777f403 -r e9611a2288ca app/soc/logic/models/base.py --- a/app/soc/logic/models/base.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/logic/models/base.py Sun Jan 25 16:25:17 2009 +0000 @@ -91,12 +91,17 @@ depth = self._scope_logic.logic.getScopeDepth() return None if (depth is None) else (depth + 1) - def _updateField(self, model, name, value): + def _updateField(self, entity, name, value): """Hook called when a field is updated. Base classes should override if any special actions need to be taken when a field is updated. The field is not updated if the method does not return a True value. + + Args: + entity: the unaltered entity + name: the name of the field to be changed + value: the new value """ return True @@ -338,64 +343,58 @@ return result - def updateModelProperties(self, model, model_properties): - """Update existing model entity using supplied model properties. + def updateEntityProperties(self, entity, entity_properties): + """Update existing entity using supplied properties. Args: model: a model entity - model_properties: keyword arguments that correspond to model entity + model_properties: keyword arguments that correspond to entity properties and their values Returns: - The original model entity with any supplied properties changed. + The original entity with any supplied properties changed. """ def update(): - return self._unsafeUpdateModelProperties(model, model_properties) + return self._unsafeUpdateEntityProperties(entity, entity_properties) - entity = db.run_in_transaction(update) - + entity = db.run_in_transaction(update) + # call the _onUpdate method self._onUpdate(entity) - + return entity - - def _silentUpdateModelProperties(self, model, model_properties): - """Update existing model entity without calling _onUpdate. - - Args: - model: a model entity - model_properties: keyword arguments that correspond to model entity - properties and their values - Returns: - The original model entity with any supplied properties changed. + def _silentUpdateEntityProperties(self, entity, entity_properties): + """See _unsafeUpdateEntityProperties. + + Does not call _onUpdate. """ def update(): - return self._unsafeUpdateModelProperties(model, model_properties) + return self._unsafeUpdateEntityProperties(entity, entity_properties) return db.run_in_transaction(update) - def _unsafeUpdateModelProperties(self, model, model_properties): - """See updateModelProperties. + def _unsafeUpdateEntityProperties(self, entity, entity_properties): + """See updateEntityProperties. - Like updateModelProperties(), but not run within a transaction. + Like updateEntityProperties(), but not run within a transaction. """ - properties = model.properties() + properties = entity.properties() for prop in properties.values(): name = prop.name - if not name in self._skip_properties and name in model_properties: - value = model_properties[prop.name] + if not name in self._skip_properties and name in entity_properties: + value = entity_properties[prop.name] - if self._updateField(model, name, value): - prop.__set__(model, value) + if self._updateField(entity, name, value): + prop.__set__(entity, value) - model.put() - return model + entity.put() + return entity def updateOrCreateFromKeyName(self, properties, key_name): """Update existing entity, or create new one with supplied properties. @@ -422,7 +421,7 @@ # there is no way to be sure if get_or_insert() returned a new entity or # got an existing one due to a race, so update with properties anyway, # in a transaction - entity = self._silentUpdateModelProperties(entity, properties) + entity = self._silentUpdateEntityProperties(entity, properties) if create_entity: # a new entity has been created call _onCreate diff -r f0b02777f403 -r e9611a2288ca app/soc/logic/models/club.py --- a/app/soc/logic/models/club.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/logic/models/club.py Sun Jan 25 16:25:17 2009 +0000 @@ -67,7 +67,7 @@ # set the application to completed fields = {'status' : 'completed'} - club_app_logic.logic.updateModelProperties(application, fields) + club_app_logic.logic.updateEntityProperties(application, fields) logic = Logic() diff -r f0b02777f403 -r e9611a2288ca app/soc/views/models/club_app.py --- a/app/soc/views/models/club_app.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/views/models/club_app.py Sun Jan 25 16:25:17 2009 +0000 @@ -259,7 +259,7 @@ # this application has been properly reviewed update the status fields = {'status' : status_value} - self._logic.updateModelProperties(entity, fields) + self._logic.updateEntityProperties(entity, fields) if status_value == 'accepted': # the application has been accepted send out a notification diff -r f0b02777f403 -r e9611a2288ca app/soc/views/models/notification.py --- a/app/soc/views/models/notification.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/views/models/notification.py Sun Jan 25 16:25:17 2009 +0000 @@ -194,7 +194,7 @@ # if the message is meant for the user that is reading it if entity.scope.key() == user.key(): # mark the entity as read - self._logic.updateModelProperties(entity, {'unread' : False} ) + self._logic.updateEntityProperties(entity, {'unread' : False} ) context['entity_type_url'] = self._params['url_name'] context['entity_suffix'] = self._logic.getKeySuffix(entity) diff -r f0b02777f403 -r e9611a2288ca app/soc/views/models/request.py --- a/app/soc/views/models/request.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/views/models/request.py Sun Jan 25 16:25:17 2009 +0000 @@ -165,7 +165,7 @@ if 'status' in get_dict.keys(): if get_dict['status'] == 'rejected': # this invite has been rejected mark as rejected - request_logic.updateModelProperties(request_entity, { + request_logic.updateEntityProperties(request_entity, { 'state': 'rejected'}) # redirect to user role overview diff -r f0b02777f403 -r e9611a2288ca app/soc/views/models/role.py --- a/app/soc/views/models/role.py Sun Jan 25 16:17:33 2009 +0000 +++ b/app/soc/views/models/role.py Sun Jan 25 16:25:17 2009 +0000 @@ -446,7 +446,7 @@ if get_dict['status'] in ['group_accepted', 'rejected', 'ignored']: # update the request_entity and redirect away from this page request_state = get_dict['status'] - request_logic.logic.updateModelProperties(request_entity, { + request_logic.logic.updateEntityProperties(request_entity, { 'state': get_dict['status']}) if request_state == 'group_accepted':