Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @auth_required(authorization.CREATE)
- @parse_json_body(json_type=dict)
- def post(self, request, consumer_id, action):
- """
- Install/update/uninstall content unit/s on the consumer.
- :param request: WSGI request object
- :type request: django.core.handlers.wsgi.WSGIRequest
- :param consumer_id: A consumer ID.
- :type consumer_id: str
- :param action: type of action to perform
- :type action: str
- :raises MissingResource: if consumer id does not exist
- :raises MissingValue: if some required values are missing
- """
- method = getattr(self, action, None)
- if method:
- try:
- factory.consumer_manager().get_consumer(consumer_id)
- except MissingResource:
- raise MissingResource(consumer_id=consumer_id)
- else:
- body = request.body_as_json
- missing_params = []
- units = body.get('units')
- if units is None:
- missing_params.append('units')
- elif not isinstance(units, list):
- raise InvalidValue('Units must be a list of dictionaries')
- options = body.get('options')
- if options is None:
- missing_params.append('options')
- if missing_params:
- raise MissingValue(missing_params)
- return method(request, consumer_id, units, options)
- else:
- return HttpResponseBadRequest('bad request')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement