Ejemplo n.º 1
0
    def __init__(
        self,
        scripts=list(),
        styles=list(),
        label=None,
        default_value=None,
        modclass=None,
        disabled=False,
    ):
        """Initialize the module

        Args:
            scripts:
            styles:
            label:
            default_value:
            modclass:
            disabled:
        """
        scripts = ["core_parser_app/js/builtin/sync_input.js"] + scripts
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        if modclass is None:
            raise ModuleError("'modclass' is required.")

        self.modclass = modclass
        self.label = label
        self.default_value = default_value
        self.disabled = disabled
Ejemplo n.º 2
0
    def __init__(
        self,
        scripts=list(),
        styles=list(),
        label=None,
        default_value=None,
        disabled=False,
        placeholder=None,
    ):
        """Initialize the module

        Args:
            scripts:
            styles:
            label:
            default_value:
            disabled:
            placeholder:
        """
        scripts = ["core_parser_app/js/builtin/input.js"] + scripts
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        self.label = label
        self.default_value = default_value
        self.disabled = disabled
        self.placeholder = placeholder
Ejemplo n.º 3
0
    def __init__(
            self,
            scripts=list(),
            styles=list(),
            label=None,
            name=None,
            options=None,
            selected=list(),
    ):
        """Initialize the module

        Args:
            scripts:
            styles:
            label:
            name:
            options:
            selected:
        """
        scripts = ["core_parser_app/js/builtin/checkboxes.js"] + scripts
        styles = ["core_parser_app/css/builtin/checkboxes.css"] + styles
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        if name is None:
            raise ModuleError("The name can't be empty.")

        self.selected = selected
        self.options = options if options is not None else dict()
        self.label = label
Ejemplo n.º 4
0
    def __init__(
        self,
        scripts=list(),
        styles=list(),
        label=None,
        options=None,
        disabled=False,
        selected=None,
    ):
        """Initialize module

        Args:
            scripts:
            styles:
            label:
            options:
            disabled:
            selected:
        """
        if options is None:
            options = {}

        scripts = ["core_parser_app/js/builtin/options.js"] + scripts
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        self.options = options
        self.label = label
        self.disabled = disabled
        self.selected = selected
Ejemplo n.º 5
0
 def _get_popup_content(self):
     """ Return module's data rendering
     """
     selected_elements = [self.data]
     template = AbstractModule.render_template(
         'core_module_periodic_table_app/periodic.html',
         {'selected_elements': selected_elements})
     return AbstractModule.render_template(
         'core_module_periodic_table_app/periodic_simple.html',
         {'periodic_table': template})
def get_chemical_composition_popup_content(data, edit_template):
    """ Chemical_composition module's rendering
    """
    # rendering data in the periodic table
    template = AbstractModule.render_template('core_module_periodic_table_app/periodic.html',
                                              {'selected_elements': get_periodic_table_selected_elements(data)})

    # rendering both form in the popup template
    return AbstractModule.render_template('core_module_chemical_composition_app/chemical_composition.html',
                                          {'periodic_table': template,
                                           'data_template': edit_template})
 def _get_popup_content(self):
     """Return module's data rendering"""
     selected_elements = [self.data]
     template = AbstractModule.render_template(
         "core_module_periodic_table_app/periodic.html",
         {"selected_elements": selected_elements},
     )
     return AbstractModule.render_template(
         "core_module_periodic_table_app/periodic_simple.html",
         {"periodic_table": template},
     )
    def __init__(self, scripts=list(), styles=list(), label=None):
        """Initialize the module

        Args:
            scripts:
            styles:
            label:
        """
        scripts = ["core_parser_app/js/builtin/autocomplete.js"] + scripts
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        self.label = label
Ejemplo n.º 9
0
    def __init__(self, scripts=list(), styles=list(), button_label=""):
        """Initialize module

        Args:
            scripts:
            styles:
        """
        scripts = ["core_parser_app/js/builtin/popup.js"] + scripts
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        self.button_label = button_label
        self.popup_content = ""
Ejemplo n.º 10
0
    def render_module(self, element):
        """Renders a module

        Args:
            element:

        Returns:

        """
        module_options = element.options
        module_url = module_options["url"]

        module = module_api.get_by_url(module_url)
        module_view = AbstractModule.get_view_from_view_path(
            module.view).as_view()

        module_request = self.request
        module_request.method = "GET"

        module_request.GET = {
            "module_id": element.pk,
            "url": module_url,
            "xsd_xpath": module_options["xpath"]["xsd"],
            "xml_xpath": module_options["xpath"]["xml"],
        }

        # if the loaded doc has data, send them to the module for initialization
        if module_options["data"] is not None:
            module_request.GET["data"] = module_options["data"]

        if module_options["attributes"] is not None:
            module_request.GET["attributes"] = module_options["attributes"]

        # renders the module
        return module_view(module_request).content.decode("utf-8")
Ejemplo n.º 11
0
    def _render_module(self, request):
        """Return module's rendering

        Args:
            request:

        Returns:

        """
        params = {}

        if self.label is not None:
            params.update({"label": self.label})

        if self.default_value is not None:
            params.update({"default_value": self.default_value})

        if self.disabled is not None:
            params.update({"disabled": self.disabled})

        if self.placeholder is not None:
            params.update({"placeholder": self.placeholder})

        return AbstractModule.render_template(
            "core_parser_app/builtin/input.html", params)
Ejemplo n.º 12
0
    def __init__(self, scripts=list(), styles=list(), label=None, data=""):
        """Initialize module

        Args:

            scripts:
            styles:
            label:
            data:
        """
        scripts = ["core_parser_app/js/builtin/textarea.js"] + scripts
        styles = ["core_parser_app/css/builtin/textarea.css"] + styles
        AbstractModule.__init__(self, scripts=scripts, styles=styles)

        self.label = label
        self.data = data
def get_chemical_composition_popup_content(data, edit_template):
    """Chemical_composition module's rendering"""
    # rendering data in the periodic table
    template = AbstractModule.render_template(
        "core_module_periodic_table_app/periodic.html",
        {"selected_elements": get_periodic_table_selected_elements(data)},
    )

    # rendering both form in the popup template
    return AbstractModule.render_template(
        "core_module_chemical_composition_app/chemical_composition.html",
        {
            "periodic_table": template,
            "data_template": edit_template,
        },
    )
Ejemplo n.º 14
0
    def render_module(self, element):
        """Renders a module

        Args:
            element:

        Returns:

        """
        module_options = element.options
        module_url = module_options['url']

        module = module_api.get_by_url(module_url)
        module_view = AbstractModule.get_view_from_view_path(
            module.view).as_view()

        module_request = self.request
        module_request.method = 'GET'

        module_request.GET = {
            'module_id': element.pk,
            'url': module_url,
            'xsd_xpath': module_options['xpath']['xsd'],
            'xml_xpath': module_options['xpath']['xml']
        }

        # if the loaded doc has data, send them to the module for initialization
        if module_options['data'] is not None:
            module_request.GET['data'] = module_options['data']

        if module_options['attributes'] is not None:
            module_request.GET['attributes'] = module_options['attributes']

        # renders the module
        return module_view(module_request).content.decode("utf-8")
Ejemplo n.º 15
0
    def render_blob_host_data(data, error):
        """Render blob host data

        Args:
            data:
            error:

        Returns:

        """
        context = {}
        if error is not None:
            context["error"] = error
        else:
            """We have to unescape the string before the graphical render"""
            context["handle"] = XmlEntities.unescape_xml_entities(data)[0]
        """Even if we have unescaped the graphical version of the data
         we have to display the warning message if there are xml predefined entities"""
        data_xml_entities = XmlEntities()
        data_xml_entities.escape_xml_entities(data)
        if (data_xml_entities.number_of_subs_made > 0 or len(
                re.findall(r"((&)|(>)|(<)|(')|("))", data))
                > 0):
            context["xml_entities_warning"] = True

        return AbstractModule.render_template(
            "core_module_blob_host_app/blob_host_display.html", context)
Ejemplo n.º 16
0
    def _render_module(self, request):
        """Return module's rendering

        Args:
            request:

        Returns:

        """
        options_html = ""

        if self.selected not in list(self.options.keys()):
            self.selected = None

        for key, val in list(self.options.items()):
            if self.selected is not None and key == self.selected:
                options_html += ("<option value='" + key + "' selected>" +
                                 val + "</option>")
            else:
                options_html += "<option value='" + key + "'>" + val + "</option>"

        params = {"options": options_html}

        if self.label is not None:
            params.update({"label": self.label})

        if self.disabled is not None:
            params.update({"disabled": self.disabled})

        return AbstractModule.render_template(
            "core_parser_app/builtin/options.html", params)
Ejemplo n.º 17
0
    def _get_popup_content(self):
        """ Return popup content

        Returns:

        """
        return AbstractModule.render_template('core_module_excel_uploader_app/excel_uploader.html',
                                              {'form': ExcelUploaderForm()})
Ejemplo n.º 18
0
    def _get_popup_content(self):
        """ Return popup content

        Returns:

        """
        return AbstractModule.render_template(
            'core_module_blob_host_app/blob_host.html',
            {'form': BLOBHostForm()})
Ejemplo n.º 19
0
    def __init__(self,
                 scripts=list(),
                 styles=list(),
                 button_label='Send',
                 label=None,
                 default_value=None):
        """ Initialize the module

        Args:
            scripts:
            styles:
            button_label:
            label:
            default_value:
        """
        AbstractModule.__init__(self, scripts=scripts, styles=styles)
        self.button_label = button_label
        self.label = label
        self.default_value = default_value
Ejemplo n.º 20
0
def discover_modules(urls):
    """

    :return:
    """
    logger.info("START discover modules.")

    # Remove all existing modules
    module_api.delete_all()

    # Look for modules in project urls
    try:
        for url in urls:
            if hasattr(url, "url_patterns"):
                for url_pattern in url.url_patterns:
                    module_view_name = (url_pattern.lookup_str if hasattr(
                        url_pattern, "lookup_str") else "")
                    if module_view_name.startswith("core_module_"):
                        module_view = AbstractModule.get_view_from_view_path(
                            module_view_name)
                        if issubclass(module_view, AbstractModule):
                            # FIXME: do not use private field
                            module_object = Module(
                                url=url_pattern.pattern._regex,
                                name=url_pattern.name,
                                view=module_view_name,
                                multiple=module_view.is_managing_occurrences,
                            )
                            try:
                                module_api.upsert(module_object)
                            except NotUniqueError:
                                logger.error(
                                    "The module %s is already present in the database."
                                    "Please check the list of urls for duplicates."
                                    % url_pattern.name)
    except ValidationError:
        # something went wrong, delete already added modules
        module_api.delete_all()

        error_msg = (
            "A validation error occurred during the module discovery. "
            "Please provide a name to all modules urls using the name argument."
        )

        logger.error("Discover modules failed with %s." % error_msg)

        raise ModuleError(error_msg)
    except Exception as e:
        # something went wrong, delete already added modules
        module_api.delete_all()
        logger.error("Discover modules failed with %s." % str(e))
        raise e

    logger.info("FINISH discover modules.")
Ejemplo n.º 21
0
    def _render_module(self, request):
        """ Return module's rendering

        Args:
            request:

        Returns:

        """
        params = {"label": self.label, 'data': self.data}

        return AbstractModule.render_template(
            'core_parser_app/builtin/textarea.html', params)
Ejemplo n.º 22
0
    def _render_module(self, request):
        """ Return module's rendering

        Args:
            request:

        Returns:

        """
        params = {
            "popup_content": self._get_popup_content(),
            "button_label": self.button_label,
        }

        return AbstractModule.render_template(
            'core_parser_app/builtin/popup.html', params)
Ejemplo n.º 23
0
    def _render_module(self, request):
        """ Return the module rendering

        Args:
            request:

        Returns:

        """
        params = {"button_label": self.button_label}
        if self.label is not None:
            params.update({"label": self.label})
        if self.default_value is not None:
            params.update({"default_value": self.default_value})
        return AbstractModule.render_template(
            'core_parser_app/builtin/input_button.html', params)
Ejemplo n.º 24
0
    def _render_module(self, request):
        """ Return module's rendering

        Args:
            request:

        Returns:

        """

        params = {'class': self.modclass}
        if self.label is not None:
            params.update({"label": self.label})
        if self.default_value is not None:
            params.update({"default_value": self.default_value})
        if self.disabled is not None:
            params.update({"disabled": self.disabled})
        return AbstractModule.render_template('core_parser_app/builtin/sync_input.html', params)
Ejemplo n.º 25
0
    def render_blob_host_data(data, error):
        """ Render blob host data

        Args:
            data:
            error:

        Returns:

        """
        context = {}
        if error is not None:
            context['error'] = error
        else:
            context['handle'] = data

        return AbstractModule.render_template(
            'core_module_blob_host_app/blob_host_display.html', context)
Ejemplo n.º 26
0
    def _render_module(self, request):
        """Return the module

        Args:
            request:

        Returns:

        """
        # Compute number of items in each columns
        col_nb = 3
        opt_nb = len(self.options)
        max_item_nb = int(ceil(old_div(opt_nb, col_nb)))

        # Parameters initialization
        params = {
            "column1": "",
            "column2": "",
            "column3": "",
        }
        item_nb = 0
        col_id = 1
        checkboxes_html = ""

        # Filling the parameters
        for key, val in list(self.options.items()):
            if item_nb == max_item_nb:
                params["column" + str(col_id)] = checkboxes_html

                checkboxes_html = ""
                item_nb = 0
                col_id += 1

            checkboxes_html += CheckboxesModule._create_html_checkbox(
                key, val, checked=(key in self.selected))
            item_nb += 1

        params["column" + str(col_id)] = checkboxes_html

        if self.label is not None:
            params.update({"label": self.label})

        return AbstractModule.render_template(
            "core_parser_app/builtin/checkboxes.html", params)
    def _get_popup_content(self):
        """Return popup content

        Returns:

        """
        module_id = None

        if self.request:
            module_id = self.request.GET.get("module_id", None)

        # create the from and set an unique id
        form = ExcelUploaderForm()
        form.fields["file"].widget.attrs.update(
            {"id": "file-input-%s" % str(module_id)})
        return AbstractModule.render_template(
            "core_module_excel_uploader_app/excel_uploader.html",
            {"form": ExcelUploaderForm()},
        )
    def _render_module(self, request):
        """Return the module

        Args:
            request:

        Returns:

        """
        params = {}

        if self.data != "":
            params["value"] = self.data

        if self.label is not None:
            params.update({"label": self.label})

        return AbstractModule.render_template(
            "core_parser_app/builtin/autocomplete.html", params)
Ejemplo n.º 29
0
    def _get_popup_content(self):
        """Return popup content

        Returns:

        """
        module_id = None

        if self.request:
            module_id = self.request.GET.get("module_id", None)

        # create the from and set an unique id
        form = BLOBHostForm()
        form.fields["file"].widget.attrs.update(
            {"id": "file-input-%s" % str(module_id)})
        return AbstractModule.render_template(
            "core_module_blob_host_app/blob_host.html",
            {
                "form": form,
                "module_id": module_id,
            },
        )
Ejemplo n.º 30
0
    def _render_module(self, request):
        """Return module's rendering

        Args:
            request:

        Returns:

        """
        module_id = None

        if self.request:
            module_id = self.request.GET.get("module_id", None)

        params = {
            "popup_content": self._get_popup_content(),
            "module_id": module_id,
            "button_label": self.button_label,
        }

        return AbstractModule.render_template(
            "core_parser_app/builtin/popup.html", params)