-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable activity for activated insertion and deletion
- Loading branch information
Showing
8 changed files
with
126 additions
and
82 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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from sqlalchemy_api_handler.serialization.as_dict import * | ||
from sqlalchemy_api_handler.serialization.get_result import * | ||
from sqlalchemy_api_handler.serialization.serialize import * |
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 was deleted.
Oops, something went wrong.
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,56 @@ | ||
import enum | ||
from uuid import UUID | ||
from datetime import datetime | ||
from functools import singledispatch | ||
import sqlalchemy | ||
from psycopg2._range import DateTimeRange | ||
|
||
from sqlalchemy_api_handler.utils.date import DateTimes, format_into_ISO_8601 | ||
from sqlalchemy_api_handler.utils.humanize import humanize | ||
from sqlalchemy_api_handler.utils.is_id_column import is_id_column | ||
|
||
|
||
def create_serialize(with_humanize=True): | ||
@singledispatch | ||
def serialize(value, column=None): | ||
return value | ||
|
||
@serialize.register(int) | ||
def _(value, column=None): | ||
if with_humanize and is_id_column(column): | ||
return humanize(value) | ||
return value | ||
|
||
@serialize.register(sqlalchemy.Enum) | ||
def _(value, column=None): | ||
return value.name | ||
|
||
@serialize.register(enum.Enum) | ||
def _(value, column=None): | ||
return value.value | ||
|
||
@serialize.register(datetime) | ||
def _(value, column=None): | ||
return format_into_ISO_8601(value) | ||
|
||
@serialize.register(DateTimeRange) | ||
def _(value, column=None): | ||
return {'start': value.lower, 'end': value.upper} | ||
|
||
@serialize.register(bytes) | ||
def _(value, column=None): | ||
return list(value) | ||
|
||
@serialize.register(list) | ||
def _(value, column=None): | ||
return list(map(serialize, value)) | ||
|
||
@serialize.register(DateTimes) | ||
def _(value, column=None): | ||
return [format_into_ISO_8601(v) for v in value.datetimes] | ||
|
||
@serialize.register(UUID) | ||
def _(value, column=None): | ||
return str(value) | ||
|
||
return serialize |
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,3 +1,5 @@ | ||
# pylint: disable=W0613 | ||
|
||
from datetime import datetime, timedelta | ||
from uuid import uuid4 | ||
import pytest | ||
|