예제 #1
0
    def __init__(self, app=None):
        if self.name is None:
            msg = "Service must have a name ({})".format(fqcn(self.__class__))
            raise ValueError(msg)

        self.logger = logging.getLogger(fqcn(self.__class__))
        if app:
            self.init_app(app)
예제 #2
0
    def __init__(self, app=None):
        if self.name is None:
            raise ValueError('Service must have a name ({})'.format(
                fqcn(self.__class__)))

        self.logger = logging.getLogger(fqcn(self.__class__))
        if app:
            self.init_app(app)
예제 #3
0
    def content(self):
        obj = self.current_obj

        index_service = get_service("indexing")
        index = index_service.app_state.indexes["default"]
        schema = index.schema
        context = self.context.copy()
        context["schema"] = schema
        context["sorted_fields"] = sorted(schema.names())

        adapter = index_service.adapted.get(fqcn(obj.__class__))
        if adapter and adapter.indexable:
            doc = context["current_document"] = index_service.get_document(
                obj, adapter)
            indexed = {}
            for name, field in schema.items():
                value = doc.get(name)
                indexed[name] = None
                if value and field.analyzer and field.format:
                    indexed[name] = list(field.process_text(value))
            context["current_indexed"] = indexed
            context["current_keys"] = sorted(set(doc) | set(indexed))

        with index.searcher() as search:
            document = search.document(object_key=obj.object_key)

        sorted_keys = sorted(document) if document is not None else None

        context.update({"document": document, "sorted_keys": sorted_keys})

        jinja_env = current_app.jinja_env
        jinja_env.filters.update(self.jinja_env.filters)
        template = jinja_env.get_or_select_template(
            "debug_panels/indexing_panel.html")
        return template.render(context)
예제 #4
0
    def content(self):
        obj = self.current_obj
        svc = current_app.services["indexing"]
        index = svc.app_state.indexes["default"]
        schema = index.schema
        context = self.context.copy()
        context["schema"] = schema
        context["sorted_fields"] = sorted(schema.names())

        adapter = svc.adapted.get(fqcn(obj.__class__))
        if adapter and adapter.indexable:
            doc = context["current_document"] = svc.get_document(obj, adapter)
            indexed = {}
            for name, field in schema.items():
                value = doc.get(name)
                indexed[name] = None
                if value and field.analyzer and field.format:
                    indexed[name] = list(field.process_text(value))
            context["current_indexed"] = indexed
            context["current_keys"] = sorted(set(doc) | set(indexed))

        with index.searcher() as search:
            document = search.document(object_key=obj.object_key)

        sorted_keys = sorted(document) if document is not None else None

        context.update({"document": document, "sorted_keys": sorted_keys})

        jinja_env = current_app.jinja_env
        jinja_env.filters.update(self.jinja_env.filters)
        template = jinja_env.get_or_select_template("debug_panels/indexing_panel.html")
        return template.render(context)
예제 #5
0
    def __init__(self, app: Optional[Any] = None) -> None:
        if self.name is None:
            msg = f"Service must have a name ({fqcn(self.__class__)})"
            raise ValueError(msg)

        self.logger = logging.getLogger(fqcn(self.__class__))
        if app:
            self.init_app(app)
예제 #6
0
def set_entity_type(cls):
    """Decorator used to set the class' entity_type after the class has been
    declared.

    Actually, it works using __module__ during class declaration, but
    linters (Flake8, PyCharm) complain.
    """
    cls.entity_type = fqcn(cls)
    return cls
예제 #7
0
def set_entity_type(cls):
    """Decorator used to set the class' entity_type after the class has been
    declared.

    Actually, it works using __module__ during class declaration, but
    linters (Flake8, PyCharm) complain.
    """
    cls.entity_type = fqcn(cls)
    return cls
예제 #8
0
    def generate_async(self):
        task_kwargs = dict(
            app=self.module.crud_app.name,
            module=self.module.id,
            from_url=request.url,
            user_id=current_user.id,
            component=self.component.name,
        )

        if self.excel_manager != self.component.excel_manager:
            task_kwargs["manager"] = fqcn(self.excel_manager)

        task = export_task.apply_async(kwargs=task_kwargs)
        return render_template("crm/excel/async_export.html", task=task)
예제 #9
0
 def __init__(self, service, running=False):
     self.service = service
     self.running = running
     self.logger = logging.getLogger(fqcn(self.__class__))
예제 #10
0
        if FQCN in app.extensions:
            return

        app.extensions[FQCN] = self
        app.register_blueprint(excel_bp, url_prefix="/crm/excel")

        # register i18n
        app.extensions["babel"].add_translations("abilian.crm")

        jinja_filters.init_filters(app)
        app.register_jinja_loaders(jinja2.PackageLoader(__name__))

        # crm static assets
        app.add_static_url("abilian/crm", STATIC_DIR, endpoint="abilian_crm_static")
        app.extensions["webassets"].append_path(
            STATIC_DIR, app.static_url_path + "/abilian/crm"
        )

        app.register_asset("js", *JS)
        register_js_api.connect(self.register_js_api)

    def register_js_api(self, sender):
        app = sender
        js_api = app.js_api.setdefault("crm", {})
        js_api = js_api.setdefault("excel", {})
        js_api["taskStatusUrl"] = url_for("crm_excel.task_status")


FQCN = fqcn(AbilianCRM)
crm = AbilianCRM()
예제 #11
0
 def __init__(self, service, running=False):
     self.service = service
     self.running = running
     self.logger = logging.getLogger(fqcn(self.__class__))
예제 #12
0
        if FQCN in app.extensions:
            return

        app.extensions[FQCN] = self

        # register i18n
        app.extensions["babel"].add_translations("abilian.sbe")

        # sbe static assets
        app.add_static_url("abilian/sbe",
                           STATIC_DIR,
                           endpoint="abilian_sbe_static")
        app.extensions["webassets"].append_path(
            STATIC_DIR, app.static_url_path + "/abilian/sbe")

        app.register_asset("js", *JS)
        app.register_asset("css", LESSCSS_FILE)

        # Jinja
        logger.info("Register jinja context processors")
        app.context_processor(inject_template_utils)


FQCN = fqcn(AbilianSBE)
sbe = AbilianSBE()


def inject_template_utils():
    return {"uuid": uuid.uuid1}
예제 #13
0
 def _object_type(cls) -> str:
     return fqcn(cls)
예제 #14
0
        app.config.setdefault("SBE_FORUM_REPLY_BY_MAIL", False)

        if FQCN in app.extensions:
            return

        app.extensions[FQCN] = self

        # register i18n
        app.extensions["babel"].add_translations("abilian.sbe")

        # sbe static assets
        app.add_static_url("abilian/sbe", STATIC_DIR, endpoint="abilian_sbe_static")
        app.extensions["webassets"].append_path(
            STATIC_DIR, app.static_url_path + "/abilian/sbe"
        )

        app.register_asset("js", *JS)
        app.register_asset("css", LESSCSS_FILE)

        # Jinja
        logger.info("Register jinja context processors")
        app.context_processor(inject_template_utils)


FQCN = fqcn(AbilianSBE)
sbe = AbilianSBE()


def inject_template_utils():
    return {"uuid": uuid.uuid1}
예제 #15
0
 def __init__(self, service: "Service", running: bool = False) -> None:
     self.service = service
     self.running = running
     self.logger = logging.getLogger(fqcn(self.__class__))