Skip to content

Commit

Permalink
refactor: final migration of optinal href to mixin
Browse files Browse the repository at this point in the history
this is a final migration of all occurances of Optional[HrefMixin]
to OptionalHrefMixin and comments on the fact that we have to
convert the href to a str because the pyndatic object is not
compatible with httpx
  • Loading branch information
devraj committed May 8, 2024
1 parent df100d3 commit d33175e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions gallagher/cc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ async def _get(
try:

response = await _httpx_async.get(
f'{url}',
f'{url}', # required to turn pydantic object to str
headers=get_authorization_headers(),
)

Expand Down Expand Up @@ -470,7 +470,7 @@ async def _post(
try:

response = await _httpx_async.post(
f'{url}',
f'{url}', # required to turn pydantic object to str
json=payload.dict() if payload else None,
headers=get_authorization_headers(),
)
Expand Down
7 changes: 4 additions & 3 deletions gallagher/dto/detail/access_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ..utils import (
AppBaseModel,
IdentityMixin,
HrefMixin
HrefMixin,
OptionalHrefMixin,
)
from ..summary import (
AlarmSummary,
Expand All @@ -30,13 +31,13 @@ class AccessGroupDetail(
description: Optional[str]
parent: Optional[AccessGroupRef]
division: IdentityMixin
cardholders: Optional[HrefMixin]
cardholders: OptionalHrefMixin
server_display_name: Optional[str]

description: Optional[str]
parent: Optional[AccessGroupRef]
division: DivisionDetail
cardholders: Optional[HrefMixin]
cardholders: OptionalHrefMixin
server_display_name: Optional[str]
children: list[AccessGroupRef]
personal_data_definitions: list[PDFRef]
Expand Down
13 changes: 7 additions & 6 deletions gallagher/dto/detail/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..utils import (
AppBaseModel,
HrefMixin,
OptionalHrefMixin,
IdentityMixin,
)

Expand Down Expand Up @@ -56,18 +57,18 @@ class AlarmDetail(
state: str
active: bool
division: HrefMixin
event: Optional[HrefMixin] = None
event: OptionalHrefMixin = None
note_presets: list[str] = []

# The following URLS should be used to follow through
# on various actions that the system allows
view: HrefMixin
comment: HrefMixin
acknowledge: Optional[HrefMixin] = None
acknowledge_with_comment: Optional[HrefMixin] = None
process: Optional[HrefMixin] = None
process_with_comment: Optional[HrefMixin] = None
force_process: Optional[HrefMixin] = None
acknowledge: OptionalHrefMixin = None
acknowledge_with_comment: OptionalHrefMixin = None
process: OptionalHrefMixin = None
process_with_comment: OptionalHrefMixin = None
force_process: OptionalHrefMixin = None

# Details fields, these are what don't appear in the summary
details: Optional[str] = ""
Expand Down
5 changes: 3 additions & 2 deletions gallagher/dto/detail/division.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ..utils import (
AppBaseModel,
IdentityMixin,
HrefMixin
HrefMixin,
OptionalHrefMixin,
)


Expand All @@ -18,7 +19,7 @@ class DivisionDetail(
name: str
description: Optional[str] = None
server_display_name: Optional[str] = None
parent: Optional[HrefMixin] = None
parent: OptionalHrefMixin = None

# TODO: Looks like we don't have access to visitor management
# on our test instance at the moment
Expand Down
5 changes: 3 additions & 2 deletions gallagher/dto/summary/access_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from ..utils import (
AppBaseModel,
IdentityMixin,
HrefMixin
HrefMixin,
OptionalHrefMixin,
)

from ..ref import (
Expand Down Expand Up @@ -36,5 +37,5 @@ class AccessGroupSummary(
description: Optional[str]
parent: Optional[AccessGroupRef]
division: IdentityMixin
cardholders: Optional[HrefMixin]
cardholders: OptionalHrefMixin
server_display_name: Optional[str]
13 changes: 7 additions & 6 deletions gallagher/dto/summary/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ..utils import (
AppBaseModel,
HrefMixin,
OptionalHrefMixin,
IdentityMixin,
)

Expand Down Expand Up @@ -45,15 +46,15 @@ class AlarmSummary(
state: str
active: bool
division: HrefMixin
event: Optional[HrefMixin] = None
event: OptionalHrefMixin = None
note_presets: list[str] = []

# The following URLS should be used to follow through
# on various actions that the system allows
view: HrefMixin
comment: HrefMixin
acknowledge: Optional[HrefMixin] = None
acknowledge_with_comment: Optional[HrefMixin] = None
process: Optional[HrefMixin] = None
process_with_comment: Optional[HrefMixin] = None
force_process: Optional[HrefMixin] = None
acknowledge: OptionalHrefMixin = None
acknowledge_with_comment: OptionalHrefMixin = None
process: OptionalHrefMixin = None
process_with_comment: OptionalHrefMixin = None
force_process: OptionalHrefMixin = None
5 changes: 3 additions & 2 deletions gallagher/dto/summary/division.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from ..utils import (
AppBaseModel,
IdentityMixin,
HrefMixin
HrefMixin,
OptionalHrefMixin,
)


Expand All @@ -24,7 +25,7 @@ class DivisionSummary(
name: str
description: Optional[str] = None
server_display_name: Optional[str] = None
parent: Optional[HrefMixin] = None
parent: OptionalHrefMixin = None


def __rich_repr__(self):
Expand Down

0 comments on commit d33175e

Please sign in to comment.