def get(self, request, type_id, unit_id): """ Return a response containing information about the requested content unit. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param type_id: type of content contained in the repo :type type_id: str :param unit_id: unique id of a unit :type unit_id: str :return: response containing a dict with data about requested unit :rtype : django.http.HttpResponse """ cqm = factory.content_query_manager() try: unit = cqm.get_content_unit_by_id(type_id, unit_id) except MissingResource: msg = _('No content unit resource: %(r)s') % {'r': unit_id} return generate_json_response(msg, response_class=HttpResponseNotFound) resource = serial_content.content_unit_obj(unit) resource.update({ 'children': serial_content.content_unit_child_link_objs(resource) }) return generate_json_response_with_pulp_encoder(resource)
def _process_content_unit(content_unit, content_type): """ Adds an href to the content unit and hrefs for its children. :param content_unit: content unit to serialize :type content_unit: dict :param content_type: type of content_unit :type content_type: str :return: serialized unit :rtype: dict """ unit = serial_content.content_unit_obj(content_unit) unit["_href"] = reverse("content_unit_resource", kwargs={"type_id": content_type, "unit_id": content_unit["_id"]}) unit.update({"children": serial_content.content_unit_child_link_objs(unit)}) return unit
def _process_content_unit(content_unit, content_type): """ Adds an href to the content unit and hrefs for its children. :param content_unit: content unit to serialize :type content_unit: dict :param content_type: type of content_unit :type content_type: str :return: serialized unit :rtype: dict """ unit = serial_content.content_unit_obj(content_unit) unit['_href'] = reverse( 'content_unit_resource', kwargs={'type_id': content_type, 'unit_id': content_unit['_id']} ) unit.update({'children': serial_content.content_unit_child_link_objs(unit)}) return unit
def _process_content_unit(content_unit, content_type): """ Adds an href to the content unit and hrefs for its children. :param content_unit: content unit to serialize :type content_unit: dict :param content_type: type of content_unit :type content_type: str :return: serialized unit :rtype: dict """ unit = serial_content.content_unit_obj(content_unit) unit['_href'] = reverse('content_unit_resource', kwargs={ 'type_id': content_type, 'unit_id': content_unit['_id'] }) unit.update( {'children': serial_content.content_unit_child_link_objs(unit)}) return unit
def get(self, request, type_id, unit_id): """ Return a response containing information about the requested content unit. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param type_id: type of content contained in the repo :type type_id: str :param unit_id: unique id of a unit :type unit_id: str :return: response containing a dict with data about requested unit :rtype : django.http.HttpResponse """ cqm = factory.content_query_manager() try: unit = cqm.get_content_unit_by_id(type_id, unit_id) except MissingResource: msg = _("No content unit resource: %(r)s") % {"r": unit_id} return generate_json_response(msg, response_class=HttpResponseNotFound) resource = serial_content.content_unit_obj(unit) resource.update({"children": serial_content.content_unit_child_link_objs(resource)}) return generate_json_response_with_pulp_encoder(resource)