2525"""
2626
2727from datetime import datetime , timedelta , tzinfo
28- from jinja2 import Environment , StrictUndefined , contextfilter , \
29- contextfunction , environmentfunction
28+ from jinja2 import Environment , StrictUndefined , pass_context , \
29+ pass_environment
3030from jinja2 .runtime import Context
3131import markdown_it
3232import markupsafe
4545from cmscommon .mimetypes import get_type_for_file_name , get_icon_for_type
4646
4747
48- @contextfilter
48+ @pass_context
4949def all_ (ctx : Context , l : list , test : str | None = None , * args ) -> bool :
5050 """Check if all elements of the given list pass the given test.
5151
@@ -69,7 +69,7 @@ def all_(ctx: Context, l: list, test: str | None = None, *args) -> bool:
6969 return True
7070
7171
72- @contextfilter
72+ @pass_context
7373def any_ (ctx : Context , l : list , test : str | None = None , * args ) -> bool :
7474 """Check if any element of the given list passes the given test.
7575
@@ -93,7 +93,7 @@ def any_(ctx: Context, l: list, test: str | None = None, *args) -> bool:
9393 return False
9494
9595
96- @contextfilter
96+ @pass_context
9797def dictselect (
9898 ctx : Context , d : dict , test : str | None = None , * args , by : str = "key"
9999) -> dict :
@@ -122,7 +122,7 @@ def dictselect(
122122 if ctx .call (test , {"key" : k , "value" : v }[by ], * args ))
123123
124124
125- @contextfunction
125+ @pass_context
126126def today (ctx : Context , dt : datetime ) -> bool :
127127 """Returns whether the given datetime is today.
128128
@@ -185,7 +185,7 @@ def instrument_generic_toolbox(env: Environment):
185185 env .tests ["today" ] = today
186186
187187
188- @environmentfunction
188+ @pass_environment
189189def safe_get_task_type (env : Environment , * , dataset : Dataset ):
190190 try :
191191 return dataset .task_type_object
@@ -195,7 +195,7 @@ def safe_get_task_type(env: Environment, *, dataset: Dataset):
195195 return env .undefined ("TaskType not found: %s" % err )
196196
197197
198- @environmentfunction
198+ @pass_environment
199199def safe_get_score_type (env : Environment , * , dataset : Dataset ):
200200 try :
201201 return dataset .score_type_object
@@ -215,59 +215,59 @@ def instrument_cms_toolbox(env: Environment):
215215 env .filters ["to_language" ] = get_language
216216
217217
218- @contextfilter
218+ @pass_context
219219def format_datetime (ctx : Context , dt : datetime ):
220220 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
221221 timezone : tzinfo = ctx .get ("timezone" , local_tz )
222222 return translation .format_datetime (dt , timezone )
223223
224224
225- @contextfilter
225+ @pass_context
226226def format_time (ctx : Context , dt : datetime ):
227227 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
228228 timezone : tzinfo = ctx .get ("timezone" , local_tz )
229229 return translation .format_time (dt , timezone )
230230
231231
232- @contextfilter
232+ @pass_context
233233def format_datetime_smart (ctx : Context , dt : datetime ):
234234 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
235235 now : datetime = ctx .get ("now" , make_datetime ())
236236 timezone : tzinfo = ctx .get ("timezone" , local_tz )
237237 return translation .format_datetime_smart (dt , now , timezone )
238238
239239
240- @contextfilter
240+ @pass_context
241241def format_timedelta (ctx : Context , td : timedelta ):
242242 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
243243 return translation .format_timedelta (td )
244244
245245
246- @contextfilter
246+ @pass_context
247247def format_duration (ctx : Context , d : float , length : str = "short" ):
248248 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
249249 return translation .format_duration (d , length )
250250
251251
252- @contextfilter
252+ @pass_context
253253def format_size (ctx : Context , s : int ):
254254 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
255255 return translation .format_size (s )
256256
257257
258- @contextfilter
258+ @pass_context
259259def format_decimal (ctx : Context , n : int ):
260260 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
261261 return translation .format_decimal (n )
262262
263263
264- @contextfilter
264+ @pass_context
265265def format_locale (ctx : Context , n : str ):
266266 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
267267 return translation .format_locale (n )
268268
269269
270- @contextfilter
270+ @pass_context
271271def wrapped_format_status_text (ctx : Context , status_text : list [str ]):
272272 translation : Translation = ctx .get ("translation" , DEFAULT_TRANSLATION )
273273 return format_status_text (status_text , translation = translation )
0 commit comments