Skip to content

Commit

Permalink
support for new niw method (utility method for new without apply)
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Mar 10, 2015
1 parent 2ebced2 commit d27e7ed
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions mvc/src/mvc_utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,13 @@ def _class_new(cls, request = None, map = None, permissive = False, apply = True
@type permissive: bool
@param permissive: If the apply operation should be done using
a permissive approach ignoring the undefined values.
@type apply: bool
@param apply: If the current data in the request should be
"automatically" applied to the current model using the various
strategies defined in the model associated with the current request.
@rtype: Model
@return: The newly created model with the attributes
already "populated" with the map contents.
@return: The newly created model with the attributes already
"populated" with the map contents.
"""

# checks if the provided map (reference) is in fact a sequence
Expand All @@ -182,9 +186,10 @@ def _class_new(cls, request = None, map = None, permissive = False, apply = True
# session variables information
model.set_request(request)

# in case a map is provided, must apply
# the contents of it to the model
map and model.apply(map, permissive = permissive)
# in case a map is provided, must apply the contents of it
# to the model, note that this is performed event if the (auto)
# apply flag is not set (required operation if defined)
if map: model.apply(map, permissive = permissive)

# in case the apply flag is currently not set, nothing
# else should be done in the new model and it should be
Expand All @@ -208,6 +213,30 @@ def _class_new(cls, request = None, map = None, permissive = False, apply = True
# field from the request applied to it
return model

def _class_niw(cls, request = None, map = None, permissive = False):
"""
Utility method to be used instead of the typical new method for
situations where the apply operation is not required/needed/wanted.
This ensures a direct usage without the explicit setting of the apply
flag, so that a minimal usage is allowed (less coder).
@type request: Request
@param request: The request to be used in the context
of the current model, it should enable access to session attributes.
@type map: Dictionary
@param map: The map of "form" options to be used to create
the new model instance.
@type permissive: bool
@param permissive: If the apply operation should be done using
a permissive approach ignoring the undefined values.
@rtype: Model
@return: The newly created model with the attributes already
"populated" with the map contents.
"""

return cls.new(request = request, map = map, permissive = permissive, apply = False)

def _class_get_system(cls):
"""
Class method that retrieves the system instance associated
Expand Down

0 comments on commit d27e7ed

Please sign in to comment.