|
15 | 15 | from django.utils.safestring import mark_safe |
16 | 16 | from django.utils.translation import gettext_lazy |
17 | 17 |
|
18 | | -from weblate.accounts.utils import get_key_name |
19 | | - |
20 | 18 | if TYPE_CHECKING: |
21 | | - from django_otp.models import Device |
22 | 19 | from django_stubs_ext import StrOrPromise |
23 | 20 |
|
24 | 21 | from weblate.accounts.types import DeviceType |
|
59 | 56 | "recovery": gettext_lazy("Use recovery codes"), |
60 | 57 | } |
61 | 58 |
|
62 | | -IMAGE_SOCIAL_TEMPLATE = """ |
63 | | -<img class="auth-image" src="{image}" /> |
64 | | -""" |
| 59 | +IMAGE_SOCIAL_TEMPLATE = """<img class="auth-image" src="{image}" />""" |
| 60 | + |
| 61 | +NAME_SOCIAL_TEMPLATE = """<span class="auth-name">{name}</span>""" |
65 | 62 |
|
66 | | -SOCIAL_TEMPLATE = """ |
67 | | -{icon} |
68 | | -{separator} |
69 | | -{name} |
70 | | -""" |
| 63 | +SOCIAL_TEMPLATE = """{icon}{label}""" |
71 | 64 |
|
72 | 65 |
|
73 | 66 | def get_auth_params(auth: str) -> dict[str, StrOrPromise]: |
@@ -96,30 +89,26 @@ def get_auth_params(auth: str) -> dict[str, StrOrPromise]: |
96 | 89 |
|
97 | 90 |
|
98 | 91 | @register.simple_tag |
99 | | -def auth_name(auth: str, separator: str = auth_name_default_separator, only: str = ""): |
| 92 | +def auth_name(auth: str, only: str = ""): |
100 | 93 | """Create HTML markup for social authentication method.""" |
101 | 94 | params = get_auth_params(auth) |
102 | 95 |
|
103 | 96 | if not params["image"].startswith(("http", "data:")): |
104 | 97 | params["image"] = staticfiles_storage.url(f"auth/{params['image']}") |
105 | | - params["icon"] = format_html(IMAGE_SOCIAL_TEMPLATE, separator=separator, **params) |
| 98 | + params["icon"] = format_html(IMAGE_SOCIAL_TEMPLATE, **params) |
| 99 | + params["label"] = format_html(NAME_SOCIAL_TEMPLATE, **params) |
106 | 100 |
|
107 | 101 | if only: |
108 | 102 | return params[only] |
109 | 103 |
|
110 | | - return format_html(SOCIAL_TEMPLATE, separator=separator, **params) |
| 104 | + return format_html(SOCIAL_TEMPLATE, **params) |
111 | 105 |
|
112 | 106 |
|
113 | 107 | def get_auth_name(auth: str): |
114 | 108 | """Get nice name for authentication backend.""" |
115 | 109 | return get_auth_params(auth)["name"] |
116 | 110 |
|
117 | 111 |
|
118 | | -@register.simple_tag |
119 | | -def key_name(device: Device) -> str: |
120 | | - return format_html('<span class="auth-name">{}</span>', get_key_name(device)) |
121 | | - |
122 | | - |
123 | 112 | @register.simple_tag |
124 | 113 | def second_factor_name(name: DeviceType) -> StrOrPromise: |
125 | 114 | return SECOND_FACTORS[name] |
|
0 commit comments