Skip to content

Commit

Permalink
Added timeseries column data validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejmets committed Nov 5, 2024
1 parent 7d9dce0 commit 1b61256
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/senaite/timeseries/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: utf-8 -*-

from validators import * # noqa
15 changes: 13 additions & 2 deletions src/senaite/timeseries/browser/overrides/adapters.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# -*- coding: utf-8 -*-

from bika.lims import api

# from bika.lims.interfaces import IAnalysisService
from senaite.core.browser.form.adapters.analysisservice import EditForm
from senaite.core.interfaces import IAjaxEditForm
from zope.interface import implementer


@implementer(IAjaxEditForm)
class AnalysisServiceEditForm(EditForm):
def __init__(self, context, request):
import pdb; pdb.set_trace() # fmt: skip

def toggle_result_type(self, result_type):
"""Hides/Show result options depending on the resulty type
"""
"""Hides/Show result options depending on the result type"""
import pdb; pdb.set_trace() # fmt: skip
if result_type and api.is_list(result_type):
return self.toggle_result_type(result_type[0])

Expand All @@ -29,3 +37,6 @@ def toggle_result_type(self, result_type):
self.add_hide_field("GraphTitle")
self.add_hide_field("GraphXAxisTitle")
self.add_hide_field("GraphYAxisTitle")

def can_change_keyword(self, keyword):
return self.can_change_keyword(str(keyword))
4 changes: 3 additions & 1 deletion src/senaite/timeseries/browser/overrides/overrides.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<adapter
for="bika.lims.interfaces.IAnalysisService
zope.publisher.interfaces.browser.IBrowserRequest"
factory=".adapters.EditForm"/>
factory=".adapters.EditForm"
provides="senaite.core.interfaces.IAjaxEditForm"
/>

<!-- Table Lab Analyses -->
<browser:page
Expand Down
36 changes: 22 additions & 14 deletions src/senaite/timeseries/extenders/abstractbaseanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@
time_series_columns_field = ExtRecordsField(
"TimeSeriesColumns",
schemata="Result Options",
subfields=("ColumnType", "ColumnTitle", "ColumnDataType",),
validators=("timeseriesvalidator",),
subfields=(
"ColumnType",
"ColumnTitle",
"ColumnDataType",
),
subfield_labels={
"ColumnType": _("Column Type"),
"ColumnTitle": _("Column Title"),
"ColumnDataType": _("Column Data Type"),
},
subfield_validators={},
subfield_validators={
"ColumnType": "timeseriesvalidator",
"ColumnTitle": "timeseriestitlevalidator",
},
subfield_types={
"ColumnType": "string",
"ColumnTitle": "string",
Expand All @@ -62,20 +70,21 @@
# 'ColumnTitle': 25,
"ColumnDataType": 1,
},
subfield_maxlength={
"ColumnType": 1,
"ColumnTitle": 25,
"ColumnDataType": 1},
subfield_maxlength={"ColumnType": 1, "ColumnTitle": 25, "ColumnDataType": 1},
subfield_vocabularies={
"ColumnType": DisplayList(
(("index", _("Index")),
("data", _("Data")),
("average", _("Average")),)
(
("index", _("Index")),
("data", _("Data")),
("average", _("Average")),
)
),
"ColumnDataType": DisplayList(
(("float", _("Float")),
("number", _("Number")),
("date", _("Date")),)
(
("float", _("Float")),
("number", _("Number")),
("date", _("Date")),
)
),
},
widget=RecordsWidget(
Expand Down Expand Up @@ -119,8 +128,7 @@ def __init__(self, context):
self.context = context

def fiddle(self, schema):
"""
"""
""" """
if is_installed():
schema["ResultType"].vocabulary = DisplayList(RESULT_TYPES)

Expand Down
5 changes: 2 additions & 3 deletions src/senaite/timeseries/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


# Tuples of (catalog, index_name, index_attribute, index_type)
INDEXES = [
]
INDEXES = []

# Tuples of (catalog, column_name)
COLUMNS = [
Expand All @@ -28,7 +27,7 @@ class HiddenProfiles(object):
def getNonInstallableProfiles(self):
"""Hide uninstall profile from site-creation and quickinstaller."""
return [
'senaite.timeseries:uninstall',
"senaite.timeseries:uninstall",
]


Expand Down
68 changes: 68 additions & 0 deletions src/senaite/timeseries/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from Products.validation import validation
from Products.validation.interfaces.IValidator import IValidator
from senaite.core.i18n import translate as _t
from senaite.timeseries.config import _
from zope.interface import implements


class TimeSeriesValidator:
"""Validate IdentifierTypeAttributes to ensure that attributes are
not duplicated.
"""

implements(IValidator)
name = "timeseriesvalidator"

def __call__(self, value, *args, **kwargs):
instance = kwargs["instance"]
request = instance.REQUEST
form = request.form
fieldname = kwargs["field"].getName()
form_values = form.get(fieldname, False)

# Must have one and only one index column
col_types = [
col["ColumnType"] for col in form_values if col["ColumnType"] == "index"
]
if len(col_types) == 0 or len(col_types) > 1:
return _t(_("One and only one index column is required"))

# No more than 1 average column
col_types = [
col["ColumnType"] for col in form_values if col["ColumnType"] == "average"
]
if len(col_types) > 1:
return _t(_("At most one average column is allowed"))
return True


validation.register(TimeSeriesValidator())


class TimeSeriesTitleValidator:
"""Validate IdentifierTypeAttributes to ensure that attributes are
not duplicated.
"""

implements(IValidator)
name = "timeseriestitlevalidator"

def __call__(self, value, *args, **kwargs):
instance = kwargs["instance"]
request = instance.REQUEST
form = request.form
fieldname = kwargs["field"].getName()
form_values = form.get(fieldname, False)

# Column title must have a value
empty_titles = False
for col in form_values:
title = col.get("ColumnTitle")
if title is None or len(title) == 0:
empty_titles = True
if empty_titles:
return _t(_("Column Title must have a value"))
return True


validation.register(TimeSeriesTitleValidator())

0 comments on commit 1b61256

Please sign in to comment.