templatetags: make sure |get_preference gets a user (#87741)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2024-03-04 16:50:09 +01:00
parent f418c515f5
commit 2eb29089a1
2 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import os
import pytest
from wcs.formdef import FormDef
from wcs.qommon.http_request import HTTPRequest
from wcs.qommon.ident.password_accounts import PasswordAccount
@ -86,6 +87,10 @@ def test_admin_for_all(pub):
user = create_superuser(pub)
role = create_role(pub)
formdef = FormDef()
formdef.name = 'test'
formdef.store()
try:
with open(os.path.join(pub.app_dir, 'ADMIN_FOR_ALL'), 'w'):
pass # create empty file

View File

@ -1281,7 +1281,7 @@ def intcomma(value):
@register.filter
def get_preference(user, pref_name):
return user.get_preference(pref_name)
return user.get_preference(pref_name) if user else None
@register.simple_tag(takes_context=True)