119
122
missing = COMMASPACE.join(sorted(required_keys - value_keys))
120
123
raise ValueError('Missing parameters: {0}'.format(missing))
126
def update(self, obj, request):
127
"""Update the object with the values in the request.
129
This first validates and converts the attributes in the request, then
130
updates the given object with the newly converted values.
132
:param obj: The object to update.
134
:param request: The HTTP request.
135
:raises ValueError: if conversion failed for some attribute.
137
for key, value in self.__call__(request).items():
138
self._converters[key].put(obj, key, value)
142
class PatchValidator(Validator):
143
"""Create a special validator for PATCH requests.
145
PATCH is different than PUT because with the latter, you're changing the
146
entire resource, so all expected attributes must exist. With the former,
147
you're only changing a subset of the attributes, so you only validate the
148
ones that exist in the request.
150
def __init__(self, request, converters):
151
"""Create a validator for the PATCH request.
153
:param request: The request object, which must have a .PATCH
155
:param converters: A mapping of attribute names to the converter for
156
that attribute's type. Generally, this will be a GetterSetter
157
instance, but it might be something more specific for custom data
158
types (e.g. non-basic types like unicodes).
159
:raises UnknownPATCHRequestError: if the request contains an unknown
160
attribute, i.e. one that is not in the `attributes` mapping.
161
:raises ReadOnlyPATCHRequest: if the requests contains an attribute
162
that is defined as read-only.
165
for attribute in request.PATCH:
166
if attribute not in converters:
167
raise UnknownPATCHRequestError(attribute)
168
if converters[attribute].decoder is None:
169
raise ReadOnlyPATCHRequestError(attribute)
170
validationators[attribute] = converters[attribute]
171
super(PatchValidator, self).__init__(**validationators)