def POST(self): orphans = self.params() orphan_manager = factory.content_orphan_manager() tags = [action_tag('delete_orphans'), resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')] call_request = CallRequest(orphan_manager.delete_orphans_by_id, [orphans], tags=tags, archive=True) return execution.execute_async(self, call_request)
def DELETE(self, content_type, content_id): orphan_manager = factory.content_orphan_manager() orphan_manager.get_orphan(content_type, content_id) ids = [{'content_type_id': content_type, 'unit_id': content_id}] tags = [resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')] call_request = CallRequest(orphan_manager.delete_orphans_by_id, [ids], tags=tags, archive=True) return execution.execute_async(self, call_request)
def clean_orphans(self): """ Exposes the ability to clean up this unit as an orphan. """ orphan_manger = factory.content_orphan_manager() orphan_manger.delete_orphan_content_units_by_type( self._content_type_id, self.id)
def GET(self, content_type): orphan_manager = factory.content_orphan_manager() # NOTE this can still potentially stomp on memory, but hopefully the # _with_unit_keys methods will reduce the foot print enough that # we'll never see this bug again orphans = list(orphan_manager.generate_orphans_by_type_with_unit_keys(content_type)) map(lambda o: o.update(serialization.link.child_link_obj(o['_id'])), orphans) return self.ok(orphans)
def GET(self): orphan_manager = factory.content_orphan_manager() summary = orphan_manager.orphans_summary() # convert the counts into sub-documents so we can add _href fields to them rest_summary = dict((k, {'count': v}) for k, v in summary.items()) # add links to the content type sub-collections map(lambda k: rest_summary[k].update(serialization.link.child_link_obj(k)), rest_summary) return self.ok(rest_summary)
def DELETE(self): orphan_manager = factory.content_orphan_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans') ] call_request = CallRequest(orphan_manager.delete_all_orphans, tags=tags, archive=True) return execution.execute_async(self, call_request)
def DELETE(self, content_type, content_id): orphan_manager = factory.content_orphan_manager() orphan_manager.get_orphan(content_type, content_id) ids = [{'content_type_id': content_type, 'unit_id': content_id}] tags = [ resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans') ] call_request = CallRequest(orphan_manager.delete_orphans_by_id, [ids], tags=tags, archive=True) return execution.execute_async(self, call_request)
def POST(self): orphans = self.params() orphan_manager = factory.content_orphan_manager() tags = [ action_tag('delete_orphans'), resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans') ] call_request = CallRequest(orphan_manager.delete_orphans_by_id, [orphans], tags=tags, archive=True) return execution.execute_async(self, call_request)
def delete(self, request, content_type): """ Dispatch a delete_orphans_by_type task. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: restrict the list of orphans to be deleted to this content type :type content_type: str :raises: OperationPostponed when an async operation is performed """ orphan_manager = factory.content_orphan_manager() orphan_manager.validate_type(content_type) task_tags = [tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, "orphans")] async_task = content_orphan.delete_orphans_by_type.apply_async((content_type,), tags=task_tags) raise OperationPostponed(async_task)
def get(self, request, content_type, unit_id): """ Return a serialized object representing the requested orphan :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: content type of the requested orphan :type content_type: str :param unit_id: id of the requested unit :type unit_id: str :return: response conainting a serialized dict of the requested orphan :rtype : django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() orphan_dict = orphan_manager.get_orphan(content_type, unit_id) orphan_dict['_href'] = request.get_full_path() return generate_json_response(orphan_dict)
def get(self, request, content_type, unit_id): """ Return a serialized object representing the requested orphan :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: content type of the requested orphan :type content_type: str :param unit_id: id of the requested unit :type unit_id: str :return: response conainting a serialized dict of the requested orphan :rtype : django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() orphan_dict = orphan_manager.get_orphan(content_type, unit_id) orphan_dict["_href"] = request.get_full_path() return generate_json_response(orphan_dict)
def delete(self, request, content_type): """ Dispatch a delete_orphans_by_type task. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: restrict the list of orphans to be deleted to this content type :type content_type: str :raises: OperationPostponed when an async operation is performed """ orphan_manager = factory.content_orphan_manager() orphan_manager.validate_type(content_type) task_tags = [ tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans') ] async_task = content_orphan.delete_orphans_by_type.apply_async( (content_type, ), tags=task_tags) raise OperationPostponed(async_task)
def get(self, request, content_type): """ Returns a response containing a serialized list of all orphans of the specified type. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: restrict the list of orphans to this content type :type content_type: str :return: response containing a serialized list of all orphans of specified type. :rtype : django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() matched_orphans = list(orphan_manager.generate_orphans_by_type_with_unit_keys(content_type)) for orphan_dict in matched_orphans: orphan_dict["_href"] = reverse( "content_orphan_resource", kwargs={"content_type": content_type, "unit_id": orphan_dict["_id"]} ) return generate_json_response(matched_orphans)
def delete(self, request, content_type, unit_id): """ Dispatch a delete_orphans_by_id task. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: content type of the requested orphan :type content_type: str :param unit_id: id of the requested orphan :type unit_id: str :raises: OperationPostponed when an async operation is performed """ orphan_manager = factory.content_orphan_manager() orphan_manager.get_orphan(content_type, unit_id) unit_info = [{"content_type_id": content_type, "unit_id": unit_id}] task_tags = [tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, "orphans")] async_task = content_orphan.delete_orphans_by_id.apply_async((unit_info,), tags=task_tags) raise OperationPostponed(async_task)
def get(self, request): """ Return a response containing a dict of dicts, one for each orphaned unit. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: response containing a dict that itself contains a dict for each orphan. :rtype: django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() # convert the counts into sub-documents so we can add _href fields to them # add links to the content type sub-collections rest_summary = {} for key, value in orphan_manager.orphans_summary().items(): rest_summary[key] = { "count": value, "_href": reverse("content_orphan_type_subcollection", kwargs={"content_type": key}), } return generate_json_response(rest_summary)
def delete(self, request, content_type, unit_id): """ Dispatch a delete_orphans_by_id task. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: content type of the requested orphan :type content_type: str :param unit_id: id of the requested orphan :type unit_id: str :raises: OperationPostponed when an async operation is performed """ orphan_manager = factory.content_orphan_manager() orphan_manager.get_orphan(content_type, unit_id) unit_info = [{'content_type_id': content_type, 'unit_id': unit_id}] task_tags = [ tags.resource_tag(tags.RESOURCE_CONTENT_UNIT_TYPE, 'orphans') ] async_task = content_orphan.delete_orphans_by_id.apply_async( (unit_info, ), tags=task_tags) raise OperationPostponed(async_task)
def get(self, request, content_type): """ Returns a response containing a serialized list of all orphans of the specified type. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param content_type: restrict the list of orphans to this content type :type content_type: str :return: response containing a serialized list of all orphans of specified type. :rtype : django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() matched_orphans = list( orphan_manager.generate_orphans_by_type_with_unit_keys( content_type)) for orphan_dict in matched_orphans: orphan_dict['_href'] = reverse('content_orphan_resource', kwargs={ 'content_type': content_type, 'unit_id': orphan_dict['_id'] }) return generate_json_response(matched_orphans)
def get(self, request): """ Return a response containing a dict of dicts, one for each orphaned unit. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: response containing a dict that itself contains a dict for each orphan. :rtype: django.http.HttpResponse """ orphan_manager = factory.content_orphan_manager() # convert the counts into sub-documents so we can add _href fields to them # add links to the content type sub-collections rest_summary = {} for key, value in orphan_manager.orphans_summary().items(): rest_summary[key] = { 'count': value, '_href': reverse('content_orphan_type_subcollection', kwargs={'content_type': key}) } return generate_json_response(rest_summary)
def GET(self, content_type, content_id): orphan_manager = factory.content_orphan_manager() orphan = orphan_manager.get_orphan(content_type, content_id) orphan.update(serialization.link.current_link_obj()) return self.ok(orphan)
def clean_orphans(self): """ Exposes the ability to clean up this unit as an orphan. """ orphan_manger = factory.content_orphan_manager() orphan_manger.delete_orphan_content_units_by_type(self._content_type_id, self.id)
def test_factory(self): try: manager_factory.content_orphan_manager() except: self.fail(traceback.format_exc())
def DELETE(self, content_type): orphan_manager = factory.content_orphan_manager() tags = [resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, 'orphans')] call_request = CallRequest(orphan_manager.delete_orphans_by_type, [content_type], tags=tags, archive=True) return execution.execute_async(self, call_request)
def GET(self, content_type): orphan_manager = factory.content_orphan_manager() orphans = orphan_manager.list_orphans_by_type(content_type) map(lambda o: o.update(serialization.link.child_link_obj(o['_id'])), orphans) return self.ok(orphans)