• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python resource.build_custom_hateoas函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中superdesk.resource.build_custom_hateoas函数的典型用法代码示例。如果您正苦于以下问题:Python build_custom_hateoas函数的具体用法?Python build_custom_hateoas怎么用?Python build_custom_hateoas使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了build_custom_hateoas函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: create

    def create(self, docs, **kwargs):
        target_id = request.view_args['target_id']
        doc = docs[0]
        link_id = doc.get('link_id')
        desk_id = doc.get('desk')
        service = get_resource_service(ARCHIVE)
        target = service.find_one(req=None, _id=target_id)
        self._validate_link(target, target_id)
        link = {}

        if is_genre(target, BROADCAST_GENRE):
            raise SuperdeskApiError.badRequestError("Cannot add new take to the story with genre as broadcast.")

        if desk_id:
            link = {'task': {'desk': desk_id}}
            user = get_user()
            lookup = {'_id': desk_id, 'members.user': user['_id']}
            desk = get_resource_service('desks').find_one(req=None, **lookup)
            if not desk:
                raise SuperdeskApiError.forbiddenError("No privileges to create new take on requested desk.")

            link['task']['stage'] = desk['working_stage']

        if link_id:
            link = service.find_one(req=None, _id=link_id)

        linked_item = self.packageService.link_as_next_take(target, link)
        doc.update(linked_item)
        build_custom_hateoas(CUSTOM_HATEOAS, doc)
        return [linked_item['_id']]
开发者ID:actionless,项目名称:superdesk,代码行数:30,代码来源:archive_link.py


示例2: create

    def create(self, docs, **kwargs):
        doc = docs[0] if len(docs) > 0 else {}
        original_id = request.view_args['original_id']
        update_document = doc.get('update')

        archive_service = get_resource_service(ARCHIVE)
        original = archive_service.find_one(req=None, _id=original_id)
        self._validate_rewrite(original, update_document)

        digital = TakesPackageService().get_take_package(original)
        rewrite = self._create_rewrite_article(original, digital,
                                               existing_item=update_document,
                                               desk_id=doc.get('desk_id'))

        if update_document:
            # process the existing story
            archive_service.patch(update_document[config.ID_FIELD], rewrite)
            rewrite[config.ID_FIELD] = update_document[config.ID_FIELD]
            ids = [update_document[config.ID_FIELD]]
        else:
            ids = archive_service.post([rewrite])
            build_custom_hateoas(CUSTOM_HATEOAS, rewrite)

        self._add_rewritten_flag(original, digital, rewrite)
        get_resource_service('archive_broadcast').on_broadcast_master_updated(ITEM_CREATE,
                                                                              item=original,
                                                                              rewrite_id=ids[0])
        return [rewrite]
开发者ID:superdesk,项目名称:superdesk-core,代码行数:28,代码来源:archive_rewrite.py


示例3: create

    def create(self, docs, **kwargs):
        target_id = request.view_args['target_id']
        doc = docs[0]
        link_id = doc.get('link_id')
        desk_id = doc.get('desk')
        service = get_resource_service(ARCHIVE)
        target = service.find_one(req=None, _id=target_id)
        self._validate_link(target, target_id)
        link = {}

        if desk_id:
            link = {'task': {'desk': desk_id}}
            user = get_user()
            lookup = {'_id': desk_id, 'members.user': user['_id']}
            desk = get_resource_service('desks').find_one(req=None, **lookup)
            if not desk:
                raise SuperdeskApiError.forbiddenError("No privileges to create new take on requested desk.")

            link['task']['stage'] = desk['working_stage']

        if link_id:
            link = service.find_one(req=None, _id=link_id)

        linked_item = self.packageService.link_as_next_take(target, link)
        insert_into_versions(id_=linked_item[config.ID_FIELD])
        doc.update(linked_item)
        build_custom_hateoas(CUSTOM_HATEOAS, doc)
        return [linked_item['_id']]
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:28,代码来源:archive_link.py


示例4: create

    def create(self, docs, **kwargs):
        doc = docs[0] if len(docs) > 0 else {}
        template_name = doc.get('template_name')
        item = doc.get('item') or {}
        item['desk_name'] = get_resource_service('desks').get_desk_name(item.get('task', {}).get('desk'))

        if not template_name:
            SuperdeskApiError.badRequestError(message='Invalid Template Name')

        if not item:
            SuperdeskApiError.badRequestError(message='Invalid Item')

        template = superdesk.get_resource_service('content_templates').get_template_by_name(template_name)
        if not template:
            SuperdeskApiError.badRequestError(message='Invalid Template')

        updates = render_content_template(item, template)
        item.update(updates)

        if template_name == 'kill':
            apply_null_override_for_kill(item)

        docs[0] = item
        build_custom_hateoas(CUSTOM_HATEOAS, docs[0])
        return [docs[0].get(config.ID_FIELD)]
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:25,代码来源:content_templates.py


示例5: create

 def create(self, docs, **kwargs):
     user = get_user(required=True)
     auth = get_auth()
     item_id = request.view_args['item_id']
     item = get_component(ItemHold).hold({'_id': item_id}, user['_id'], auth['_id'])
     build_custom_hateoas(custom_hateoas, item)
     return [item['_id']]
开发者ID:ahilles107,项目名称:superdesk-1,代码行数:7,代码来源:archive_hold.py


示例6: create

 def create(self, docs, **kwargs):
     original_id = request.view_args["original_id"]
     archive_service = get_resource_service("archive")
     original = archive_service.find_one(req=None, _id=original_id)
     self._validate_rewrite(original)
     digital = TakesPackageService().get_take_package(original)
     rewrite = self._create_rewrite_article(original, digital)
     archive_service.post([rewrite])
     build_custom_hateoas(CUSTOM_HATEOAS, rewrite)
     self._add_rewritten_flag(original, digital, rewrite)
     return [rewrite]
开发者ID:nistormihai,项目名称:superdesk,代码行数:11,代码来源:archive_rewrite.py


示例7: on_fetched

    def on_fetched(self, doc):
        """
        Overriding to add HATEOS for each individual item in the response.

        :param doc: response doc
        :type doc: dict
        """

        docs = doc[app.config['ITEMS']]
        for item in docs:
            build_custom_hateoas({'self': {'title': item['_type'], 'href': '/{}/{{_id}}'.format(item['_type'])}}, item)
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:11,代码来源:__init__.py


示例8: get

 def get(self, req, lookup):
     if lookup.get('blog_id'):
         lookup['blog'] = ObjectId(lookup['blog_id'])
         del lookup['blog_id']
     docs = super().get(req, lookup)
     for doc in docs:
         build_custom_hateoas(self.custom_hateoas, doc, location='posts')
         for assoc in self.packageService._get_associations(doc):
             if assoc.get('residRef'):
                 item = get_resource_service('archive').find_one(req=None, _id=assoc['residRef'])
                 assoc['item'] = item
     return docs
开发者ID:catalyst,项目名称:liveblog,代码行数:12,代码来源:posts.py


示例9: fetch

    def fetch(self, docs, id=None, **kwargs):
        id_of_fetched_items = []

        for doc in docs:
            id_of_item_to_be_fetched = doc.get('_id') if id is None else id

            desk_id = doc.get('desk')
            stage_id = doc.get('stage')

            ingest_service = get_resource_service('ingest')
            ingest_doc = ingest_service.find_one(req=None, _id=id_of_item_to_be_fetched)

            if not ingest_doc:
                raise SuperdeskApiError.notFoundError('Fail to found ingest item with _id: %s' %
                                                      id_of_item_to_be_fetched)

            if not is_workflow_state_transition_valid('fetch_from_ingest', ingest_doc[config.CONTENT_STATE]):
                raise InvalidStateTransitionError()

            if doc.get('macro'):  # there is a macro so transform it
                ingest_doc = get_resource_service('macros').execute_macro(ingest_doc, doc.get('macro'))

            archived = utcnow()
            ingest_service.patch(id_of_item_to_be_fetched, {'archived': archived})

            dest_doc = dict(ingest_doc)
            new_id = generate_guid(type=GUID_TAG)
            id_of_fetched_items.append(new_id)
            dest_doc['_id'] = new_id
            dest_doc['guid'] = new_id
            dest_doc['destination_groups'] = doc.get('destination_groups')
            generate_unique_id_and_name(dest_doc)

            dest_doc[config.VERSION] = 1
            send_to(dest_doc, desk_id, stage_id)
            dest_doc[config.CONTENT_STATE] = doc.get('state', STATE_FETCHED)
            dest_doc[INGEST_ID] = dest_doc[FAMILY_ID] = ingest_doc['_id']

            remove_unwanted(dest_doc)
            set_original_creator(dest_doc)
            self.__fetch_items_in_package(dest_doc, desk_id, stage_id,
                                          doc.get('state', STATE_FETCHED),
                                          doc.get('destination_groups'))

            get_resource_service(ARCHIVE).post([dest_doc])
            insert_into_versions(doc=dest_doc)
            build_custom_hateoas(custom_hateoas, dest_doc)
            doc.update(dest_doc)

        if kwargs.get('notify', True):
            push_notification('item:fetch', fetched=1)

        return id_of_fetched_items
开发者ID:ahilles107,项目名称:superdesk-1,代码行数:53,代码来源:archive_fetch.py


示例10: fetch

    def fetch(self, docs, id=None, **kwargs):
        id_of_fetched_items = []

        for doc in docs:
            id_of_item_to_be_fetched = doc.get("_id") if id is None else id

            desk_id = doc.get("desk")
            stage_id = doc.get("stage")

            ingest_service = get_resource_service("ingest")
            ingest_doc = ingest_service.find_one(req=None, _id=id_of_item_to_be_fetched)

            if not ingest_doc:
                raise SuperdeskApiError.notFoundError(
                    "Fail to found ingest item with _id: %s" % id_of_item_to_be_fetched
                )

            if not is_workflow_state_transition_valid("fetch_from_ingest", ingest_doc[ITEM_STATE]):
                raise InvalidStateTransitionError()

            if doc.get("macro"):  # there is a macro so transform it
                ingest_doc = get_resource_service("macros").execute_macro(ingest_doc, doc.get("macro"))

            archived = utcnow()
            ingest_service.patch(id_of_item_to_be_fetched, {"archived": archived})

            dest_doc = dict(ingest_doc)
            new_id = generate_guid(type=GUID_TAG)
            id_of_fetched_items.append(new_id)
            dest_doc["_id"] = new_id
            dest_doc["guid"] = new_id
            generate_unique_id_and_name(dest_doc)

            dest_doc[config.VERSION] = 1
            send_to(doc=dest_doc, desk_id=desk_id, stage_id=stage_id)
            dest_doc[ITEM_STATE] = doc.get(ITEM_STATE, CONTENT_STATE.FETCHED)
            dest_doc[INGEST_ID] = dest_doc[FAMILY_ID] = ingest_doc["_id"]
            dest_doc[ITEM_OPERATION] = ITEM_FETCH

            remove_unwanted(dest_doc)
            set_original_creator(dest_doc)
            self.__fetch_items_in_package(dest_doc, desk_id, stage_id, doc.get(ITEM_STATE, CONTENT_STATE.FETCHED))

            get_resource_service(ARCHIVE).post([dest_doc])
            insert_into_versions(doc=dest_doc)
            build_custom_hateoas(custom_hateoas, dest_doc)
            doc.update(dest_doc)

        if kwargs.get("notify", True):
            push_notification("item:fetch", fetched=1)

        return id_of_fetched_items
开发者ID:chalkjockey,项目名称:superdesk,代码行数:52,代码来源:archive_fetch.py


示例11: _get_subscribers_by_filter_condition

    def _get_subscribers_by_filter_condition(self, filter_condition):
        """
        Searches all subscribers that has a content filter with the given filter condition

        If filter condition is used in a global filter then it returns all
        subscribers that not disabled the global filter.
        :param filter_condition: Filter condition to test
        :return: List of subscribers
        """
        req = ParsedRequest()
        all_subscribers = list(super().get(req=req, lookup=None))
        selected_products = {}
        selected_subscribers = {}
        selected_content_filters = {}

        filter_condition_service = get_resource_service('filter_conditions')
        content_filter_service = get_resource_service('content_filters')
        product_service = get_resource_service('products')

        existing_products = list(product_service.get(req=req, lookup=None))
        existing_filter_conditions = filter_condition_service.check_similar(filter_condition)
        for fc in existing_filter_conditions:
            existing_content_filters = content_filter_service.get_content_filters_by_filter_condition(fc['_id'])
            for pf in existing_content_filters:
                selected_content_filters[pf['_id']] = pf

                if pf.get('is_global', False):
                    for s in all_subscribers:
                        gfs = s.get('global_filters', {})
                        if gfs.get(str(pf['_id']), True):
                            build_custom_hateoas({'self': {'title': 'subscribers', 'href': '/subscribers/{_id}'}}, s)
                            selected_subscribers[s['_id']] = s

                for product in existing_products:
                    if product.get('content_filter') and \
                        'filter_id' in product['content_filter'] and \
                            product['content_filter']['filter_id'] == pf['_id']:
                        selected_products[product['_id']] = product

                for s in all_subscribers:
                    all_subscriber_products = list(set(s.get('products') or []) | set(s.get('api_products') or []))
                    for p in all_subscriber_products:
                        if p in selected_products:
                            build_custom_hateoas({'self': {'title': 'subscribers', 'href': '/subscribers/{_id}'}}, s)
                            selected_subscribers[s['_id']] = s

        res = {'filter_conditions': existing_filter_conditions,
               'content_filters': list(selected_content_filters.values()),
               'products': list(selected_products.values()),
               'selected_subscribers': list(selected_subscribers.values())}
        return [res]
开发者ID:nistormihai,项目名称:superdesk-core,代码行数:51,代码来源:subscribers.py


示例12: create

 def create(self, docs, **kwargs):
     original_id = request.view_args['original_id']
     archive_service = get_resource_service('archive')
     original = archive_service.find_one(req=None, _id=original_id)
     self._validate_rewrite(original)
     digital = TakesPackageService().get_take_package(original)
     rewrite = self._create_rewrite_article(original, digital)
     ids = archive_service.post([rewrite])
     build_custom_hateoas(CUSTOM_HATEOAS, rewrite)
     self._add_rewritten_flag(original, digital, rewrite)
     get_resource_service('archive_broadcast').on_broadcast_master_updated(ITEM_CREATE,
                                                                           item=original,
                                                                           rewrite_id=ids[0])
     return [rewrite]
开发者ID:will-in-wi,项目名称:superdesk,代码行数:14,代码来源:archive_rewrite.py


示例13: create

    def create(self, docs):
        service = get_resource_service(SOURCE)
        item_id = request.view_args['item_id']
        item = service.find_one(req=None, _id=item_id)
        doc = docs[0]

        self._valid_broadcast_item(item)

        desk_id = doc.get('desk')
        desk = None

        if desk_id:
            desk = get_resource_service('desks').find_one(req=None, _id=desk_id)

        doc.pop('desk', None)
        doc['task'] = {}
        if desk:
            doc['task']['desk'] = desk.get(config.ID_FIELD)
            doc['task']['stage'] = desk.get('working_stage')

        doc['task']['user'] = get_user().get('_id')
        genre_list = get_resource_service('vocabularies').find_one(req=None, _id='genre') or {}
        broadcast_genre = [{'qcode': genre.get('qcode'), 'name': genre.get('name')}
                           for genre in genre_list.get('items', [])
                           if genre.get('qcode') == BROADCAST_GENRE and genre.get('is_active')]

        if not broadcast_genre:
            raise SuperdeskApiError.badRequestError(message="Cannot find the {} genre.".format(BROADCAST_GENRE))

        doc['broadcast'] = {
            'status': '',
            'master_id': item_id,
            'takes_package_id': self.takesService.get_take_package_id(item),
            'rewrite_id': item.get('rewritten_by')
        }

        doc['genre'] = broadcast_genre
        doc['family_id'] = item.get('family_id')

        for key in FIELDS_TO_COPY:
            doc[key] = item.get(key)

        resolve_document_version(document=doc, resource=SOURCE, method='POST')
        service.post(docs)
        insert_into_versions(id_=doc[config.ID_FIELD])
        build_custom_hateoas(CUSTOM_HATEOAS, doc)
        return [doc[config.ID_FIELD]]
开发者ID:akintolga,项目名称:superdesk-core,代码行数:47,代码来源:broadcast.py


示例14: create

    def create(self, docs, **kwargs):
        target_id = request.view_args['target_id']
        doc = docs[0]
        link_id = doc.get('link_id')
        desk_id = doc.get('desk')
        service = get_resource_service(ARCHIVE)
        target = service.find_one(req=None, _id=target_id)
        self._validate_link(target, target_id)

        link = {'task': {'desk': desk_id}} if desk_id else {}

        if link_id:
            link = service.find_one(req=None, _id=link_id)

        linked_item = self.packageService.link_as_next_take(target, link)
        doc.update(linked_item)
        build_custom_hateoas(CUSTOM_HATEOAS, doc)
        return [linked_item['_id']]
开发者ID:oxcarh,项目名称:superdesk,代码行数:18,代码来源:archive_link.py


示例15: get

    def get(self, req, **lookup):
        content_view_id = lookup['lookup']['content_view_id']
        view_items = superdesk.get_resource_service('content_view').find_one(req=None, _id=content_view_id)
        if not view_items:
            raise superdesk.SuperdeskError(payload='Invalid content view id.')
        additional_query = view_items.get('filter')

        query = None
        if req.args.get('source'):
            query = json.loads(req.args.get('source'))

        query = apply_additional_query(query, additional_query)
        parsed_request = init_parsed_request(query)
        location = view_items.get('location', 'archive')
        docs = superdesk.get_resource_service(location).get(req=parsed_request, lookup={})

        for doc in docs:
            build_custom_hateoas(self.custom_hateoas, doc, location=location)
        return docs
开发者ID:chupym,项目名称:superdesk-server,代码行数:19,代码来源:content_view.py



注:本文中的superdesk.resource.build_custom_hateoas函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python resource.Resource类代码示例发布时间:2022-05-27
下一篇:
Python notification.push_notification函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap