Advertisement
Guest User

ConsumerContentActionView.post

a guest
Jul 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1.     @auth_required(authorization.CREATE)
  2.     @parse_json_body(json_type=dict)
  3.     def post(self, request, consumer_id, action):
  4.         """
  5.       Install/update/uninstall content unit/s on the consumer.
  6.  
  7.       :param request: WSGI request object
  8.       :type request: django.core.handlers.wsgi.WSGIRequest
  9.       :param consumer_id: A consumer ID.
  10.       :type consumer_id: str
  11.       :param action: type of action to perform
  12.       :type action: str
  13.  
  14.       :raises MissingResource: if consumer id does not exist
  15.       :raises MissingValue: if some required values are missing
  16.       """
  17.  
  18.         method = getattr(self, action, None)
  19.         if method:
  20.             try:
  21.                 factory.consumer_manager().get_consumer(consumer_id)
  22.             except MissingResource:
  23.                 raise MissingResource(consumer_id=consumer_id)
  24.             else:
  25.                 body = request.body_as_json
  26.                 missing_params = []
  27.                 units = body.get('units')
  28.                 if units is None:
  29.                     missing_params.append('units')
  30.                 elif not isinstance(units, list):
  31.                     raise InvalidValue('Units must be a list of dictionaries')
  32.                 options = body.get('options')
  33.                 if options is None:
  34.                     missing_params.append('options')
  35.  
  36.                 if missing_params:
  37.                     raise MissingValue(missing_params)
  38.             return method(request, consumer_id, units, options)
  39.         else:
  40.             return HttpResponseBadRequest('bad request')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement