2
2
3
3
from h .models import Annotation , User
4
4
from h .presenters import DocumentJSONPresenter
5
+ from h .presenters .mention_json import MentionJSONPresenter
5
6
from h .security import Identity , identity_permits
6
7
from h .security .permissions import Permission
8
+ from h .services import MentionService
7
9
from h .services .annotation_read import AnnotationReadService
8
10
from h .services .flag import FlagService
9
11
from h .services .links import LinksService
@@ -22,6 +24,7 @@ def __init__(
22
24
links_service : LinksService ,
23
25
flag_service : FlagService ,
24
26
user_service : UserService ,
27
+ mention_service : MentionService ,
25
28
):
26
29
"""
27
30
Instantiate the service.
@@ -30,11 +33,13 @@ def __init__(
30
33
:param links_service: LinksService instance
31
34
:param flag_service: FlagService instance
32
35
:param user_service: UserService instance
36
+ :param mention_service: MentionService instance
33
37
"""
34
38
self ._annotation_read_service = annotation_read_service
35
39
self ._links_service = links_service
36
40
self ._flag_service = flag_service
37
41
self ._user_service = user_service
42
+ self ._mention_service = mention_service
38
43
39
44
def present (self , annotation : Annotation ):
40
45
"""
@@ -71,6 +76,10 @@ def present(self, annotation: Annotation):
71
76
"target" : annotation .target ,
72
77
"document" : DocumentJSONPresenter (annotation .document ).asdict (),
73
78
"links" : self ._links_service .get_all (annotation ),
79
+ "mentions" : [
80
+ MentionJSONPresenter (mention ).asdict ()
81
+ for mention in annotation .mentions
82
+ ],
74
83
}
75
84
)
76
85
@@ -151,6 +160,8 @@ def present_all_for_user(self, annotation_ids, user: User):
151
160
# which ultimately depends on group permissions, causing a
152
161
# group lookup for every annotation without this
153
162
Annotation .group ,
163
+ # Optimise access to the mentions
164
+ Annotation .mentions ,
154
165
],
155
166
)
156
167
@@ -184,4 +195,5 @@ def factory(_context, request):
184
195
links_service = request .find_service (name = "links" ),
185
196
flag_service = request .find_service (name = "flag" ),
186
197
user_service = request .find_service (name = "user" ),
198
+ mention_service = request .find_service (MentionService ),
187
199
)
0 commit comments