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(boolean-values): allow 0 and 1 as boolean values (DEV-251) #131

Merged
merged 4 commits into from Dec 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/dsp-tools-xmlupload.md
Expand Up @@ -696,7 +696,7 @@ Attributes:

#### `<boolean>`

The `<boolean>` element must contain the string "true" or "false", or the numeral 1 or 0.
The `<boolean>` element must contain the string "true" or "false", or the numeral 1 (true) or 0 (false).

Attributes:

Expand Down
13 changes: 6 additions & 7 deletions knora/dsplib/models/value.py
Expand Up @@ -601,18 +601,17 @@ def __init__(self,
iri: Optional[str] = None,
ark_url: Optional[str] = None,
vark_url: Optional[str] = None):

if type(value) is bool:
self._value = value

elif type(value) is str:
if value.upper() == 'TRUE':
else:
if value == 1 or value.upper() == 'TRUE' or value == '1':
self._value = True
elif value.upper() == 'FALSE':
elif value == 0 or value.upper() == 'FALSE' or value == '0':
self._value = False
else:
raise BaseError("Invalid boolean format! " + str(value))
elif type(value) is int:
self._value = False if value == 0 else True
raise BaseError(f"ERROR Invalid boolean format {value}!")

super().__init__(iri=iri,
comment=comment,
permissions=permissions,
Expand Down