Ejemplo n.º 1
0
 def handle_submit(self, REQUEST=None):
     logger.info("senaite.databox::handle_submit")
     form_data = self.get_form_data()
     for key, value in form_data.items():
         logger.info("Set field '{}' -> {}".format(key, value))
         setattr(self.databox, key, value)
     modified(self.context)
Ejemplo n.º 2
0
def afterUpgradeStepHandler(event):
    """Event handler that is executed after running an upgrade step of senaite.core
    """
    if not is_installed():
        return
    logger.info("Run senaite.databox.afterUpgradeStepHandler ...")
    portal = get_portal()
    setup_navigation_types(portal)
    logger.info("Run senaite.databox.afterUpgradeStepHandler [DONE]")
Ejemplo n.º 3
0
def setup_handler(context):
    """Generic setup handler
    """

    if context.readDataFile("senaite.databox.txt") is None:
        return

    logger.info("SENAITE.DATABOX setup handler [BEGIN]")
    portal = context.getSite()  # noqa
    add_databoxes_folder(portal)
    setup_navigation_types(portal)
    logger.info("SENAITE.DATABOX setup handler [DONE]")
Ejemplo n.º 4
0
def post_uninstall(portal_setup):
    """Runs after the last import step of the *uninstall* profile

    This handler is registered as a *post_handler* in the generic setup profile

    :param portal_setup: SetupTool
    """
    logger.info("SENAITE.DATABOX uninstall handler [BEGIN]")

    # https://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py
    profile_id = "profile-senaite.databox:uninstall"
    context = portal_setup._getImportContext(profile_id)
    portal = context.getSite()  # noqa

    logger.info("SENAITE.DATABOX uninstall handler [DONE]")
Ejemplo n.º 5
0
    def query(self):
        """Catalog query
        """
        query = {"portal_type": self.query_type}
        if self.limit:
            query["limit"] = self.limit
        if self.sort_on:
            query["sort_on"] = self.sort_on
        if self.sort_order:
            query["sort_order"] = self.sort_order

        if self.date_index:
            date_from = self.date_from or DateTime("2000-01-01")
            date_to = self.date_to or DateTime()
            # always make the to_date inclusive
            query[self.date_index] = {
                "query": (DateTime(date_from), DateTime(date_to) + 1),
                "range": "minmax"
            }

        # update additional queries
        query.update(self.advanced_query)
        logger.info("DataBox Query: {}".format(query))
        return query
Ejemplo n.º 6
0
def add_databoxes_folder(portal):
    """Adds the initial Databox folder
    """
    if portal.get("databoxes") is None:
        logger.info("Adding DataBox Folder")
        portal.invokeFactory("DataBoxFolder", "databoxes", title="Databoxes")
Ejemplo n.º 7
0
    def get_reference_columns(self, column):
        """Returns configured reference columns for the given colum

        Called from the page template to render the column controls.

        Note: Here we need to work without any real objects!
              This is just to configure the column config for the query
        """

        columns = []

        # get the column data from the columns config
        column_data = self.columns.get(column)

        # get the column key
        column_key = column_data.get("column")

        # get all fields of the databox
        fields = self.databox.get_fields()

        # get the requested field
        field = fields.get(column_key)

        # return immediately if the field is not a reference field
        if not self.is_reference_field(field):
            return columns

        # check if we have further stored references
        refs = column_data.get("refs", [DEFAULT_REF])

        logger.info("Reference Columns '{}' -> {}".format(column, refs))

        # get the fields of the referenced object
        ref_type = self.get_reftype(field)
        ref_fields = self.databox.get_fields(portal_type=ref_type)

        for num, ref in enumerate(refs):

            # get the field of the referenced object
            field = ref_fields.get(ref)

            if field is None:
                continue

            columns.append({
                "key": ref,
                "type": ref_type,
                "fields": sorted(ref_fields),
            })

            # get the fields of the referenced object
            ref_type = self.get_reftype(field)
            ref_fields = self.databox.get_fields(portal_type=ref_type)

            # not a reference anymore, break
            if not ref_type:
                break

            if num == len(refs) - 1:
                if self.is_reference_field(field):
                    ref_type = self.get_reftype(field)
                    ref_fields = self.databox.get_fields(portal_type=ref_type)
                    columns.append({
                        "key": DEFAULT_REF,
                        "type": ref_type,
                        "fields": sorted(ref_fields),
                    })

        return columns
Ejemplo n.º 8
0
def auto_generate_id(obj, event):
    """Generate ID with the IDServer from senaite.core
    """
    logger.info("Auto-Generate ID for {}".format(repr(obj)))
    renameAfterCreation(obj)
Ejemplo n.º 9
0
 def __init__(self, context):
     self.context = context
     logger.info("IDataBoxBehavior::__init__:context={}".format(
         repr(context)))
Ejemplo n.º 10
0
 def __call__(self):
     logger.info("DataBoxEdit::call")
     return self.template()
Ejemplo n.º 11
0
 def __init__(self, context, request):
     logger.info("DataBoxEdit::init")
     super(DataBoxEdit, self).__init__(context, request)
     self.context = context
     self.request = request