Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DurationValidator when field value is empty #1890

Merged
merged 3 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
- #1895 Disable native form validation in header table
- #1893 Removed unused field PasswordLifeTime
- #1892 Drop jQuery Datepicker for HTML5 native date fields
- #1890 Fix DurationValidator when field value is empty
- #1886 Use the current timestamp instead of the client name for report archive download
- #1883 Fix possible XSS in remarks field
- #1882 Fix catalog query in analysis category modified handler
Expand Down
17 changes: 9 additions & 8 deletions src/bika/lims/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,17 +998,18 @@ class DurationValidator:
def __call__(self, value, *args, **kwargs):

instance = kwargs['instance']
request = kwargs.get('REQUEST', {})
request = kwargs.get('REQUEST') or {}
fieldname = kwargs['field'].getName()
translate = getToolByName(instance, 'translation_service').translate

value = request[fieldname]
for v in value.values():
try:
int(v)
except:
return to_utf8(
translate(_("Validation failed: Values must be numbers")))
value = request.get(fieldname) or None
if value:
for v in value.values():
try:
int(v)
except:
return to_utf8(
translate(_("Validation failed: Values must be numbers")))
return True


Expand Down