Skip to content

Commit

Permalink
[qa][crud] fix casting of boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBldy committed Aug 24, 2023
1 parent 53ea13b commit d934864
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions zou/app/blueprints/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
from flask_jwt_extended import jwt_required

from sqlalchemy.exc import IntegrityError, StatementError
from sqlalchemy import func

from zou.app.mixin import ArgsMixin
from zou.app.utils import events, fields, permissions
from zou.app.utils import events, fields, permissions, query
from zou.app.services.exception import (
ArgumentsException,
WrongParameterException,
Expand Down Expand Up @@ -86,13 +85,13 @@ def build_filters(self, options):
in_filter.append(
field_key.in_(
[
func.cast(value, field_key.type)
query.cast_value(value, field_key)
for value in value_array
]
)
)
else:
filters[key] = func.cast(value, field_key.type)
filters[key] = query.cast_value(value, field_key)

return (many_join_filter, in_filter, name_filter, filters)

Expand Down
4 changes: 2 additions & 2 deletions zou/app/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class Person(db.Model, BaseMixin, SerializerMixin):
ldap_uid = db.Column(db.String(60), unique=True, default=None)

def __repr__(self):
return "<Person %s>" % self.full_name()
return f"<Person {self.full_name()}>"

def full_name(self):
return "%s %s" % (self.first_name, self.last_name)
return f"{self.first_name} {self.last_name}"

def fido_devices(self):
if self.fido_credentials is None:
Expand Down
10 changes: 9 additions & 1 deletion zou/app/utils/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import math

from zou.app import app
from zou.app.utils import fields
from zou.app.utils import fields, string
from sqlalchemy import func


def get_query_criterions_from_request(request):
Expand Down Expand Up @@ -77,3 +78,10 @@ def apply_sort_by(model, query, sort_by):
else:
sort_field = model.updated_at.desc()
return query.order_by(sort_field)


def cast_value(value, field_key):
if field_key.type.python_type is bool:
return string.strtobool(value)
else:
return func.cast(value, field_key.type)

0 comments on commit d934864

Please sign in to comment.