-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from it-goats/feature/ITG-77/more-task-fields
[ITG-77] Add more task properties
- Loading branch information
Showing
14 changed files
with
393 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import datetime | ||
|
||
from sqlalchemy.types import DateTime, TypeDecorator | ||
|
||
|
||
class UTCDateTime(TypeDecorator): | ||
impl = DateTime | ||
cache_ok = True | ||
|
||
def process_bind_param(self, value, _): | ||
if value is not None: | ||
if not value.tzinfo: | ||
raise TypeError("tzinfo is required") | ||
value = value.astimezone(datetime.timezone.utc).replace( | ||
tzinfo=None | ||
) | ||
return value | ||
|
||
def process_result_value(self, value, _): | ||
if value is not None: | ||
value = value.replace(tzinfo=datetime.timezone.utc) | ||
return value |
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,15 @@ | ||
from marshmallow import Schema | ||
|
||
|
||
def camelcase(s): | ||
parts = iter(s.split("_")) | ||
return next(parts) + "".join(i.title() for i in parts) | ||
|
||
|
||
class BaseSchema(Schema): | ||
"""Schema that uses camel-case for its external representation | ||
and snake-case for its internal representation. | ||
""" | ||
|
||
def on_bind_field(self, field_name, field_obj): | ||
field_obj.data_key = camelcase(field_obj.data_key or field_name) |
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,6 +1,16 @@ | ||
from marshmallow import Schema, fields, validate | ||
from marshmallow import fields, validate | ||
|
||
from bode.resources.base_schema import BaseSchema | ||
|
||
class TaskSchema(Schema): | ||
|
||
class TaskInputSchema(BaseSchema): | ||
title = fields.String(validate=validate.Length(1, 80), required=True) | ||
description = fields.String(validate=validate.Length(0, 1024), default="") | ||
due_date = fields.DateTime(allow_none=True) | ||
|
||
|
||
class TaskSchema(BaseSchema): | ||
id = fields.UUID(dump_only=True) | ||
title = fields.String(validate=validate.Length(1, 80)) | ||
title = fields.String() | ||
description = fields.String() | ||
due_date = fields.DateTime() |
41 changes: 41 additions & 0 deletions
41
bode/migrations/versions/9b8806b556b8_add_due_date_and_description_to_task_.py
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,41 @@ | ||
"""Add due date and description to task model | ||
Revision ID: 9b8806b556b8 | ||
Revises: 4daafbe3fd77 | ||
Create Date: 2022-04-03 19:53:56.792053 | ||
""" | ||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "9b8806b556b8" | ||
down_revision = "4daafbe3fd77" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"tasks", | ||
sa.Column( | ||
"description", | ||
sa.String(length=1024), | ||
server_default="", | ||
nullable=False, | ||
), | ||
) | ||
op.add_column( | ||
"tasks", | ||
sa.Column("due_date", sa.DateTime(timezone=False), nullable=True), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("tasks", "due_date") | ||
op.drop_column("tasks", "description") | ||
# ### end Alembic commands ### |
Oops, something went wrong.