Skip to content

Commit

Permalink
Fix some type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mwild1 committed Dec 8, 2023
1 parent c63b95c commit 46a7d0c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion snikket_web/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def edit_user(localpart: str) -> typing.Union[werkzeug.Response, str]:
"success",
)
return redirect(url_for(".users"))
except aiohttp.ClientResponseError as exc:
except aiohttp.ClientResponseError:
if form.action_restore.data:
await flash(
_("Could not restore user account"),
Expand Down
22 changes: 17 additions & 5 deletions snikket_web/infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,27 @@ def format_last_activity(timestamp: typing.Optional[int]) -> str:

yesterday = now - timedelta(days=1)

if last_active.year == now.year and last_active.month == now.month and last_active.day == now.day:
if (
last_active.year == now.year
and last_active.month == now.month
and last_active.day == now.day
):
return _l("Today")
elif last_active.year == yesterday.year and last_active.month == yesterday.month and last_active.day == yesterday.day:
elif (
last_active.year == yesterday.year
and last_active.month == yesterday.month
and last_active.day == yesterday.day
):
return _l("Yesterday")

return _.gettext("%(time)s ago", time=flask_babel.format_timedelta(time_ago, granularity="day"))
return _.gettext(
"%(time)s ago",
time=flask_babel.format_timedelta(time_ago, granularity="day"),
)

def template_now() -> datetime:
return dict(now=lambda : datetime.now(timezone.utc))

def template_now() -> typing.Dict[str, typing.Any]:
return dict(now=lambda: datetime.now(timezone.utc))


def add_vary_language_header(resp: quart.Response) -> quart.Response:
Expand Down
24 changes: 18 additions & 6 deletions snikket_web/prosodyclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ class UserDeletionRequestInfo:
@classmethod
def from_api_response(
cls,
data: typing.Mapping[str, typing.Any],
data: typing.Optional[typing.Mapping[str, typing.Any]],
) -> typing.Optional["UserDeletionRequestInfo"]:
if data is None:
return None
return cls(
deleted_at=datetime.fromtimestamp(data["deleted_at"], tz=timezone.utc),
pending_until=datetime.fromtimestamp(data["pending_until"], tz=timezone.utc)
deleted_at=datetime.fromtimestamp(
data["deleted_at"],
tz=timezone.utc
),
pending_until=datetime.fromtimestamp(
data["pending_until"],
tz=timezone.utc
)
)


@dataclasses.dataclass(frozen=True)
class AvatarMetadata:
bytes: int
Expand All @@ -71,7 +78,7 @@ class AvatarMetadata:
def from_api_response(
cls,
data: typing.Mapping[str, typing.Any],
) -> "AvatarMetadata":
) -> "AvatarMetadata":
return cls(
hash=data["hash"],
bytes=data["bytes"],
Expand Down Expand Up @@ -120,8 +127,13 @@ def from_api_response(
roles=roles,
enabled=data.get("enabled", True),
last_active=data.get("last_active") or None,
deletion_request=UserDeletionRequestInfo.from_api_response(data.get("deletion_request")),
avatar_info=[AvatarMetadata.from_api_response(avatar_info) for avatar_info in data.get("avatar_info", [])],
deletion_request=UserDeletionRequestInfo.from_api_response(
data.get("deletion_request")
),
avatar_info=[
AvatarMetadata.from_api_response(avatar_info)
for avatar_info in data.get("avatar_info", [])
],
)


Expand Down

0 comments on commit 46a7d0c

Please sign in to comment.