Skip to content

Conversation

@GRazvan12
Copy link
Contributor

No description provided.

@GRazvan12 GRazvan12 requested a review from Photonios August 9, 2023 13:41
Comment on lines 18 to 19
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless, this is the default behavior.

Comment on lines 100 to 103
if re.match("False", local_value, re.IGNORECASE):
local_value = False
elif re.match("True", local_value, re.IGNORECASE):
local_value = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit overkill to use regex for this when .lower() will do the job.

Comment on lines 33 to 37
# if we were used in an expression somehow then it might be
# that we're returning an individual value or an array, so
# we should not convert that into an :see:LocalizedBooleanValue
if not isinstance(db_value, LocalizedValue):
return db_value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment explains what we're doing, not why.

elif re.match("True", local_value, re.IGNORECASE):
local_value = True
else:
local_value = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should raise an error instead of silently ignoring the problem.

for lang_code, _ in settings.LANGUAGES:
local_value = value.get(lang_code, None)

if isinstance(local_value, str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If local_value is not a string (unlikely), this check will just swoop the error under the carpet instead of loudly failing.

for lang_code, _ in settings.LANGUAGES:
local_value = prepped_value[lang_code]

if local_value is not None and local_value not in ("False", "True"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the values already be strings at this point?

Copy link
Contributor Author

@GRazvan12 GRazvan12 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the values get converted from bool to str during this step prepped_value = super().get_prep_value(value)

class LocalizedBooleanValue(LocalizedValue):
def __bool__(self):
"""Gets the value in the current language as a boolean,"""
value = self.translate()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't self.translate() return a boolean like the other value classes?

@GRazvan12 GRazvan12 requested a review from Photonios August 10, 2023 10:50
Photonios
Photonios previously approved these changes Aug 10, 2023
@GRazvan12 GRazvan12 requested a review from Photonios August 10, 2023 12:23
@Photonios Photonios merged commit a66b349 into master Aug 10, 2023
@Photonios Photonios deleted the add-localized-boolean-field branch August 10, 2023 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants