Skip to content

Commit 95f2426

Browse files
authored
jinja2: general enhancements (#43)
- move filters and globals to the correct variables (bug 1879586) - add get_messages shortcut to be used in templates (bug 1875914)
1 parent de03189 commit 95f2426

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lando/jinja2.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from jinja2 import Environment
66
from lando import settings
7-
7+
from lando.ui.legacy.forms import UserSettingsForm
88

99
import datetime
1010
import logging
@@ -13,6 +13,8 @@
1313

1414
from typing import Optional
1515

16+
from django.contrib import messages
17+
1618
FAQ_URL = "https://wiki.mozilla.org/Phabricator/FAQ#Lando"
1719
SEC_BUG_DOCS = "https://firefox-source-docs.mozilla.org/bug-mgmt/processes/security-approval.html" # noqa: E501
1820

@@ -312,6 +314,16 @@ def message_type_to_notification_class(flash_message_category: str) -> str:
312314
def environment(**options):
313315
env = Environment(**options)
314316
env.globals.update(
317+
{
318+
"config": settings,
319+
"get_messages": messages.get_messages,
320+
"is_user_authenticated": is_user_authenticated(env),
321+
"new_settings_form": UserSettingsForm,
322+
"url": reverse,
323+
"user_has_phabricator_token": user_has_phabricator_token(env),
324+
}
325+
)
326+
env.filters.update(
315327
{
316328
"avatar_url": avatar_url,
317329
"bug_url": bug_url,
@@ -323,15 +335,13 @@ def environment(**options):
323335
"graph_height": graph_height,
324336
"graph_width": graph_width,
325337
"graph_x_pos": graph_x_pos,
326-
"is_user_authenticated": is_user_authenticated(env),
327338
"linkify_bug_numbers": linkify_bug_numbers,
328339
"linkify_faq": linkify_faq,
329340
"linkify_revision_ids": linkify_revision_ids,
330341
"linkify_revision_urls": linkify_revision_urls,
331342
"linkify_sec_bug_docs": linkify_sec_bug_docs,
332343
"linkify_transplant_details": linkify_transplant_details,
333344
"message_type_to_notification_class": message_type_to_notification_class,
334-
# "new_settings_form": new_settings_form,
335345
"repo_path": repo_path,
336346
"reviewer_to_action_text": reviewer_to_action_text,
337347
"reviewer_to_status_badge_class": reviewer_to_status_badge_class,
@@ -340,8 +350,6 @@ def environment(**options):
340350
"static": static,
341351
"tostatusbadgeclass": tostatusbadgeclass,
342352
"tostatusbadgename": tostatusbadgename,
343-
"url": reverse,
344-
"user_has_phabricator_token": user_has_phabricator_token(env),
345353
}
346354
)
347355
return env

0 commit comments

Comments
 (0)