@@ -45,6 +45,16 @@ def expandable_fields(self):
4545 """Get expandable fields."""
4646 return [EntityResolverExpandableField ("created_by" )]
4747
48+ def links_item_tpl_for_request (self , request ):
49+ """Include the request's type ID in the link template.
50+
51+ This way, the link URL can be contextualised depending on the type of the event's
52+ parent request.
53+ """
54+ return LinksTemplate (
55+ self .config .links_item , context = {"request_type" : str (request .type )}
56+ )
57+
4858 @unit_of_work ()
4959 def create (
5060 self ,
@@ -119,7 +129,7 @@ def create(
119129 identity ,
120130 event ,
121131 schema = schema ,
122- links_tpl = self .links_item_tpl ,
132+ links_tpl = self .links_item_tpl_for_request ( request ) ,
123133 expandable_fields = self .expandable_fields ,
124134 expand = expand ,
125135 )
@@ -136,7 +146,7 @@ def read(self, identity, id_, expand=False):
136146 identity ,
137147 event ,
138148 schema = self ._wrap_schema (event .type .marshmallow_schema ()),
139- links_tpl = self .links_item_tpl ,
149+ links_tpl = self .links_item_tpl_for_request ( request ) ,
140150 expandable_fields = self .expandable_fields ,
141151 expand = expand ,
142152 )
@@ -183,7 +193,7 @@ def update(self, identity, id_, data, revision_id=None, uow=None, expand=False):
183193 identity ,
184194 event ,
185195 schema = schema ,
186- links_tpl = self .links_item_tpl ,
196+ links_tpl = self .links_item_tpl_for_request ( request ) ,
187197 expandable_fields = self .expandable_fields ,
188198 expand = expand ,
189199 )
@@ -269,12 +279,12 @@ def search(
269279 self .config .links_search ,
270280 context = {"request_id" : str (request .id ), "args" : params },
271281 ),
272- links_item_tpl = self .links_item_tpl ,
282+ links_item_tpl = self .links_item_tpl_for_request ( request ) ,
273283 expandable_fields = self .expandable_fields ,
274284 expand = expand ,
275285 )
276286
277- def focussed_list (
287+ def focused_list (
278288 self ,
279289 identity ,
280290 request_id ,
@@ -283,7 +293,7 @@ def focussed_list(
283293 expand = False ,
284294 search_preference = None ,
285295 ):
286- """Return a page of results focussed on a given event, or the first page if the event is not found."""
296+ """Return a page of results focused on a given event, or the first page if the event is not found."""
287297 # Permissions - guarded by the request's can_read.
288298 request = self ._get_request (request_id )
289299 self .require_permission (identity , "read" , request = request )
@@ -332,7 +342,7 @@ def focussed_list(
332342 self .config .links_search ,
333343 context = {"request_id" : str (request .id ), "args" : params },
334344 ),
335- links_item_tpl = self .links_item_tpl ,
345+ links_item_tpl = self .links_item_tpl_for_request ( request ) ,
336346 expandable_fields = self .expandable_fields ,
337347 expand = expand ,
338348 )
0 commit comments