-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added timeseries column data validation
- Loading branch information
Showing
6 changed files
with
110 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from validators import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |