Skip to content

Commit

Permalink
Revert to Coaster's JsonDict
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Mar 5, 2024
1 parent 8dc4c1e commit 0032f7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 37 deletions.
20 changes: 0 additions & 20 deletions boxoffice/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,6 @@ class Model(ModelBase, DeclarativeBase):
datetime,
sa.orm.mapped_column(sa.TIMESTAMP(timezone=True), default=sa.func.utcnow()),
]
jsonb: TypeAlias = Annotated[
dict,
sa.orm.mapped_column(
# FIXME: mutable_json_type assumes `dict|list`, not just `dict`
mutable_json_type(
dbtype=sa.JSON().with_variant(postgresql.JSONB, 'postgresql'), nested=True
)
),
]
jsonb_dict: TypeAlias = Annotated[
dict,
sa.orm.mapped_column(
# FIXME: mutable_json_type assumes `dict|list`, not just `dict`
mutable_json_type(
dbtype=sa.JSON().with_variant(postgresql.JSONB, 'postgresql'), nested=True
),
nullable=False,
server_default=sa.text("'{}'::jsonb"),
),
]


TimestampMixin.__with_timezone__ = True
Expand Down
9 changes: 6 additions & 3 deletions boxoffice/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sqlalchemy.ext.hybrid import hybrid_property

from baseframe import _
from coaster.sqlalchemy import LazyRoleSet, Query, with_roles
from coaster.sqlalchemy import JsonDict, LazyRoleSet, Query, with_roles
from coaster.utils import utcnow

from . import (
Expand All @@ -20,7 +20,6 @@
MarkdownColumn,
Model,
db,
jsonb_dict,
relationship,
sa,
timestamptz,
Expand Down Expand Up @@ -53,7 +52,11 @@ class Item(BaseScopedNameMixin[UUID, User], Model):
lazy='dynamic',
back_populates='tickets',
)
assignee_details: Mapped[jsonb_dict]
assignee_details: Mapped[dict] = sa.orm.mapped_column(
JsonDict,
nullable=False,
server_default=sa.text("'{}'::jsonb"),
)
event_date: Mapped[date | None]
cancellable_until: Mapped[timestamptz | None]
transferable_until: Mapped[timestamptz | None]
Expand Down
15 changes: 3 additions & 12 deletions boxoffice/models/line_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@
from typing_extensions import TypedDict

from baseframe import localize_timezone
from coaster.sqlalchemy import JsonDict
from coaster.utils import isoweek_datetime, midnight_to_utc, utcnow

from . import (
BaseMixin,
DynamicMapped,
Mapped,
Model,
db,
jsonb,
relationship,
sa,
timestamptz,
)
from . import BaseMixin, DynamicMapped, Mapped, Model, db, relationship, sa, timestamptz
from .enums import LineItemStatus
from .user import User

Expand Down Expand Up @@ -64,7 +55,7 @@ class Assignee(BaseMixin[int, User], Model):
email: Mapped[str] = sa.orm.mapped_column(sa.Unicode(254))
#: Unvalidated phone number
phone: Mapped[str | None] = sa.orm.mapped_column(sa.Unicode(16))
details: Mapped[jsonb] = sa.orm.mapped_column(default={})
details: Mapped[dict] = sa.orm.mapped_column(JsonDict, default={})
current: Mapped[bool | None] = sa.orm.mapped_column()


Expand Down
7 changes: 5 additions & 2 deletions boxoffice/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from typing import TYPE_CHECKING

from coaster.sqlalchemy import JsonDict
from flask_lastuser.sqlalchemy import ProfileBase, UserBase2

from . import DynamicMapped, Mapped, Model, db, jsonb_dict, relationship, sa
from . import DynamicMapped, Mapped, Model, db, relationship, sa
from .utils import HeadersAndDataTuple

__all__ = ['User', 'Organization']
Expand Down Expand Up @@ -37,7 +38,9 @@ class Organization(ProfileBase, Model):
# Number) or llpin (Limited Liability Partnership Identification Number), pan,
# service_tax_no, support_email, logo (image url), refund_policy (html), ticket_faq
# (html), website (url)
details: Mapped[jsonb_dict]
details: Mapped[dict] = sa.orm.mapped_column(
JsonDict, nullable=False, server_default=sa.text("'{}'::jsonb")
)
contact_email: Mapped[str] = sa.orm.mapped_column(sa.Unicode(254))
# This is to allow organizations to have their orders invoiced by the parent
# organization
Expand Down

0 comments on commit 0032f7e

Please sign in to comment.