Пример #1
0
async def search_post(context, request):
    q = await request.json()
    search = query_utility(ICatalogUtility)
    if search is None:
        raise HTTPServiceUnavailable()

    return await search.search_raw(context, q)
Пример #2
0
async def aggregation_get(context, request):
    query = request.query.copy()
    search = query_utility(ICatalogUtility)
    if search is None:
        raise HTTPServiceUnavailable()

    fields = request.query.get("_metadata", "").split(",")
    result = await search.query_aggregation(context, query)
    if "items" in result:
        aggregation = []
        for field in fields:
            aggregation.append([])

        for items in result["items"]:
            for index, item in enumerate(items):
                if isinstance(item, list):
                    aggregation[index].extend(item)
                elif isinstance(item, str):
                    aggregation[index].append(item)

        final_result = {}

        for index, field in enumerate(fields):
            elements = dict(Counter(aggregation[index]))
            final_result[field] = {"items": elements, "total": len(elements)}
        return final_result
    else:
        return {}
Пример #3
0
async def catalog_delete(context, request):
    search = query_utility(ICatalogUtility)
    if search is None:
        raise HTTPServiceUnavailable()
    await search.remove_catalog(context)
    return {}
Пример #4
0
async def catalog_post(context, request):
    search = query_utility(ICatalogUtility)
    if search is None:
        raise HTTPServiceUnavailable()
    await search.initialize_catalog(context)
    return {}
Пример #5
0
 async def __call__(self):
     search = query_utility(ICatalogUtility)
     if search is None:
         raise HTTPServiceUnavailable()
     await search.reindex_all_content(self.context, self._security_reindex)
     return {}
Пример #6
0
async def search_get(context, request):
    search = query_utility(ICatalogUtility)
    if search is None:
        raise HTTPServiceUnavailable()

    return await search.search(context, dict(request.query))
Пример #7
0
    async def start(
        self,
        as_user: str,
        email: str,
        from_user: str,
        task_description: str,
        task_id: str,
        redirect_url=None,
        context_description=None,
        ttl=3660,
        data=None,
    ):
        # from_user will be mostly anonymous
        registry = await get_registry()
        if registry is None:
            logger.error("No registry")
            raise HTTPServiceUnavailable()

        config = registry.for_interface(IValidationSettings)
        if config is None:
            logger.error("No configuration on registry")
            raise HTTPServiceUnavailable()

        util = get_utility(IMailer)
        if util is None:
            logger.error("No mail service configured")
            raise HTTPServiceUnavailable()

        template_name = config["validation_template"]
        site_url = config["site_url"]
        validate_url = config["validation_url"]
        from_email = config["site_mails_from"]

        render_util = get_utility(IJinjaUtility)
        if render_util is None:
            logger.error("Template render not enabled")
            raise HTTPServiceUnavailable()

        if task_id not in app_settings["auth_validation_tasks"]:
            logger.error(f"Task {task_id} unavailable")
            raise HTTPServiceUnavailable()

        if data is None:
            data = {}

        data.update({
            "v_user": as_user,
            "v_querier": from_user,
            "v_task": task_id,
            "v_redirect_url": redirect_url
        })

        token, last_date = await generate_validation_token(data, ttl=ttl)

        link = f"{site_url}{validate_url}?token={token}"
        template = await render_util.render(
            template_name,
            context_description=context_description,
            link=link,
            last_date=last_date,
            task=task_description,
        )
        await util.send(recipient=email,
                        sender=from_email,
                        subject=task_description,
                        html=template)