Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Dec 30, 2023
1 parent da7b793 commit 36038dd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions funnel/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ def ticket_followers(self) -> Query[Account]:
'is_verified',
},
}
__json_datasets__ = ('primary', 'related')

profile_state.add_conditional_state(
'ACTIVE_AND_PUBLIC',
Expand Down
1 change: 1 addition & 0 deletions funnel/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ class Comment(UuidMixin, BaseMixin[int, Account], Model):
'json': {'created_at', 'urls', 'uuid_b58', 'absolute_url'},
'minimal': {'created_at', 'uuid_b58'},
}
__json_datasets__ = ('json',)

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
Expand Down
8 changes: 5 additions & 3 deletions funnel/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@
class IntTitle(DataclassFromType, int):
"""Integer value with a title (for enums)."""

title: str
# The empty default is required for Mypy's enum plugin's `Enum.__call__` analysis
title: str = ''


@dataclass(frozen=True)
class IntNameTitle(DataclassFromType, int):
"""Integer value with a name and title (for enums)."""

name: str
title: str
# The empty default is required for Mypy's enum plugin's `Enum.__call__` analysis
name: str = ''
title: str = ''


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion funnel/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def __init__( # pylint: disable=super-init-not-called
self.fragment_uuid = fragment.uuid if fragment is not None else None
self.created_at = utcnow()
self.created_by = user
self.created_by_id = cast(int, user.id) if user is not None else None
self.created_by_id = user.id if user is not None else None

def __getattr__(self, attr: str) -> Any:
"""Get an attribute."""
Expand Down
14 changes: 8 additions & 6 deletions funnel/views/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from email.utils import formataddr
from functools import wraps
from itertools import islice
from typing import Any, ClassVar, Literal
from typing import Any, ClassVar, Literal, cast
from uuid import UUID, uuid4

from flask import url_for
Expand Down Expand Up @@ -319,19 +319,21 @@ def fragments_order_by(self) -> list[sa.UnaryExpression]:
]

@property
def fragments_query_options(self) -> list: # TODO: full spec
def fragments_query_options(self) -> Sequence:
"""Provide a list of SQLAlchemy options for loading fragments."""
return []

@cached_property
def fragments(self) -> list[RoleAccessProxy[ModelUuidProtocol]]:
def fragments(
self,
) -> list[RoleAccessProxy[ModelUuidProtocol]]: # type: ignore[type-var] # FIXME
query = self.notification_recipient.rolledup_fragments()
if query is None:
return []

query = query.order_by(*self.fragments_order_by)
if self.fragments_query_options:
query = query.options(*self.fragments_query_options)
if query_options := self.fragments_query_options:
query = query.options(*query_options)

return [
_f.access_for(actor=self.notification_recipient.recipient)
Expand Down Expand Up @@ -366,7 +368,7 @@ def web(self) -> str:
@property
def email_base_url(self) -> str:
"""Base URL for relative links in email."""
return self.notification.role_provider_obj.absolute_url
return cast(str, self.notification.role_provider_obj.absolute_url)

def email_subject(self) -> str:
"""
Expand Down
4 changes: 3 additions & 1 deletion funnel/views/notifications/proposal_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

from collections.abc import Sequence

from flask import render_template
from werkzeug.utils import cached_property

Expand Down Expand Up @@ -76,7 +78,7 @@ def fragments_order_by(self) -> list[sa.UnaryExpression]:
return [Proposal.datetime.desc()]

@property
def fragments_query_options(self):
def fragments_query_options(self) -> Sequence:
return [
sa_orm.load_only(
Proposal.name, Proposal.title, Proposal.project_id, Proposal.uuid
Expand Down

0 comments on commit 36038dd

Please sign in to comment.