flask-deck 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flask_deck/__init__.py +184 -0
- flask_deck/adapters/__init__.py +23 -0
- flask_deck/adapters/sqlalchemy.py +272 -0
- flask_deck/audit.py +363 -0
- flask_deck/auth.py +462 -0
- flask_deck/branding.py +217 -0
- flask_deck/charts.py +514 -0
- flask_deck/cli.py +135 -0
- flask_deck/config.py +81 -0
- flask_deck/dashboard.py +416 -0
- flask_deck/deck.py +4153 -0
- flask_deck/demo.py +1066 -0
- flask_deck/events.py +309 -0
- flask_deck/exceptions.py +34 -0
- flask_deck/exporter.py +240 -0
- flask_deck/formatters.py +386 -0
- flask_deck/i18n.py +399 -0
- flask_deck/icons.py +92 -0
- flask_deck/importer.py +612 -0
- flask_deck/introspection.py +376 -0
- flask_deck/jobs.py +382 -0
- flask_deck/mfa.py +670 -0
- flask_deck/model_view.py +1097 -0
- flask_deck/py.typed +0 -0
- flask_deck/query.py +1220 -0
- flask_deck/schema_graph.py +137 -0
- flask_deck/security.py +373 -0
- flask_deck/sql_console.py +391 -0
- flask_deck/sso.py +293 -0
- flask_deck/static/css/deck.css +1333 -0
- flask_deck/static/js/deck.js +1433 -0
- flask_deck/storage.py +669 -0
- flask_deck/templates/flask_deck/audit_list.html +117 -0
- flask_deck/templates/flask_deck/base.html +454 -0
- flask_deck/templates/flask_deck/custom_page.html +12 -0
- flask_deck/templates/flask_deck/dashboard.html +32 -0
- flask_deck/templates/flask_deck/diagnostics.html +80 -0
- flask_deck/templates/flask_deck/error.html +15 -0
- flask_deck/templates/flask_deck/import_wizard.html +143 -0
- flask_deck/templates/flask_deck/jobs_list.html +95 -0
- flask_deck/templates/flask_deck/login.html +93 -0
- flask_deck/templates/flask_deck/login_mfa.html +59 -0
- flask_deck/templates/flask_deck/mfa_setup.html +121 -0
- flask_deck/templates/flask_deck/model_detail.html +124 -0
- flask_deck/templates/flask_deck/model_form.html +389 -0
- flask_deck/templates/flask_deck/model_list.html +489 -0
- flask_deck/templates/flask_deck/partials/drawer_detail.html +93 -0
- flask_deck/templates/flask_deck/partials/widget_grid.html +207 -0
- flask_deck/templates/flask_deck/rbac_matrix.html +59 -0
- flask_deck/templates/flask_deck/record_history.html +102 -0
- flask_deck/templates/flask_deck/schema_inspector.html +83 -0
- flask_deck/templates/flask_deck/sql_console.html +87 -0
- flask_deck-0.3.0.dist-info/METADATA +382 -0
- flask_deck-0.3.0.dist-info/RECORD +57 -0
- flask_deck-0.3.0.dist-info/WHEEL +4 -0
- flask_deck-0.3.0.dist-info/entry_points.txt +5 -0
- flask_deck-0.3.0.dist-info/licenses/LICENSE +21 -0
flask_deck/i18n.py
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# ruff: noqa: RUF001
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from datetime import datetime, timezone, tzinfo
|
|
6
|
+
from decimal import Decimal
|
|
7
|
+
from functools import lru_cache
|
|
8
|
+
from typing import Any, Protocol, runtime_checkable
|
|
9
|
+
from zoneinfo import ZoneInfo, available_timezones
|
|
10
|
+
|
|
11
|
+
from flask import g, has_request_context
|
|
12
|
+
|
|
13
|
+
LOCALE_SESSION_KEY = "_deck_locale"
|
|
14
|
+
TZ_SESSION_KEY = "_deck_tz"
|
|
15
|
+
_G_LOCALE_KEY = "_flask_deck_locale"
|
|
16
|
+
_G_TZ_KEY = "_flask_deck_tz"
|
|
17
|
+
|
|
18
|
+
RTL_LOCALES: frozenset[str] = frozenset({"ar", "he", "fa", "ur"})
|
|
19
|
+
|
|
20
|
+
CURATED_TIMEZONES: tuple[str, ...] = (
|
|
21
|
+
"UTC",
|
|
22
|
+
"Europe/Istanbul",
|
|
23
|
+
"Europe/London",
|
|
24
|
+
"Europe/Berlin",
|
|
25
|
+
"America/New_York",
|
|
26
|
+
"America/Chicago",
|
|
27
|
+
"America/Los_Angeles",
|
|
28
|
+
"Asia/Dubai",
|
|
29
|
+
"Asia/Singapore",
|
|
30
|
+
"Asia/Tokyo",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
LOCALE_LABELS: dict[str, str] = {
|
|
34
|
+
"en": "English (EN)",
|
|
35
|
+
"tr": "Türkçe (TR)",
|
|
36
|
+
"de": "Deutsch (DE)",
|
|
37
|
+
"ar": "العربية (AR · RTL)",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_LOCALE_SEPARATORS: dict[str, tuple[str, str]] = {
|
|
41
|
+
"en": (",", "."),
|
|
42
|
+
"tr": (".", ","),
|
|
43
|
+
"de": (".", ","),
|
|
44
|
+
"ar": (",", "."),
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
BUILTIN_CATALOGS: dict[str, dict[str, str]] = {
|
|
48
|
+
"en": {},
|
|
49
|
+
"tr": {
|
|
50
|
+
"Workspace": "Çalışma Alanı",
|
|
51
|
+
"Dashboard": "Genel Bakış",
|
|
52
|
+
"Governance": "Yönetişim",
|
|
53
|
+
"Audit Ledger": "Denetim Kaydı",
|
|
54
|
+
"RBAC Matrix": "RBAC Matrisi",
|
|
55
|
+
"Schema ERD": "Şema ERD",
|
|
56
|
+
"SQL Console": "SQL Konsolu",
|
|
57
|
+
"Diagnostics": "Tanı Paneli",
|
|
58
|
+
"Background Jobs": "Arka Plan İşleri",
|
|
59
|
+
"2FA Security": "2FA Güvenlik",
|
|
60
|
+
"Jump to model, record, action…": "Model, kayıt veya aksiyon ara…",
|
|
61
|
+
"Filter models…": "Modelleri filtrele…",
|
|
62
|
+
"Recent Events": "Son Olaylar",
|
|
63
|
+
"All →": "Tümü →",
|
|
64
|
+
"Keyboard Shortcuts": "Klavye Kısayolları",
|
|
65
|
+
"Sign out": "Çıkış Yap",
|
|
66
|
+
"Table": "Tablo",
|
|
67
|
+
"Board": "Kanban",
|
|
68
|
+
"Trash": "Çöp Kutusu",
|
|
69
|
+
"Import": "İçe Aktar",
|
|
70
|
+
"Export": "Dışa Aktar",
|
|
71
|
+
"New": "Yeni",
|
|
72
|
+
"Search": "Ara",
|
|
73
|
+
"Reset": "Sıfırla",
|
|
74
|
+
"Filters": "Filtreler",
|
|
75
|
+
"Save View": "Görünümü Kaydet",
|
|
76
|
+
"Columns": "Sütunlar",
|
|
77
|
+
"Apply Filters": "Filtreleri Uygula",
|
|
78
|
+
"Clear": "Temizle",
|
|
79
|
+
"Actions": "İşlemler",
|
|
80
|
+
"Edit": "Düzenle",
|
|
81
|
+
"Delete": "Sil",
|
|
82
|
+
"Restore": "Geri Yükle",
|
|
83
|
+
"History": "Geçmiş",
|
|
84
|
+
"Clone": "Kopyala",
|
|
85
|
+
"Cancel": "İptal",
|
|
86
|
+
"Confirm": "Onayla",
|
|
87
|
+
"Save": "Kaydet",
|
|
88
|
+
"Back": "Geri",
|
|
89
|
+
"Prev": "Önceki",
|
|
90
|
+
"Next": "Sonraki",
|
|
91
|
+
"First": "İlk",
|
|
92
|
+
"Preferences": "Tercihler",
|
|
93
|
+
"Language": "Dil",
|
|
94
|
+
"Timezone": "Saat Dilimi",
|
|
95
|
+
"Apply": "Uygula",
|
|
96
|
+
"matching records": "eşleşen kayıt",
|
|
97
|
+
"Page Summary": "Sayfa Özeti",
|
|
98
|
+
"Sign in": "Giriş Yap",
|
|
99
|
+
"Add Condition": "Koşul Ekle",
|
|
100
|
+
"Exit Impersonation": "Kimliğe Bürünmeyi Bitir",
|
|
101
|
+
},
|
|
102
|
+
"de": {
|
|
103
|
+
"Workspace": "Arbeitsbereich",
|
|
104
|
+
"Dashboard": "Übersicht",
|
|
105
|
+
"Governance": "Governance",
|
|
106
|
+
"Audit Ledger": "Audit-Protokoll",
|
|
107
|
+
"RBAC Matrix": "RBAC-Matrix",
|
|
108
|
+
"Schema ERD": "Schema-ERD",
|
|
109
|
+
"SQL Console": "SQL-Konsole",
|
|
110
|
+
"Diagnostics": "Diagnose",
|
|
111
|
+
"Background Jobs": "Hintergrundjobs",
|
|
112
|
+
"2FA Security": "2FA-Sicherheit",
|
|
113
|
+
"Jump to model, record, action…": "Modell, Datensatz oder Aktion suchen…",
|
|
114
|
+
"Filter models…": "Modelle filtern…",
|
|
115
|
+
"Recent Events": "Letzte Ereignisse",
|
|
116
|
+
"All →": "Alle →",
|
|
117
|
+
"Keyboard Shortcuts": "Tastenkürzel",
|
|
118
|
+
"Sign out": "Abmelden",
|
|
119
|
+
"Table": "Tabelle",
|
|
120
|
+
"Board": "Board",
|
|
121
|
+
"Trash": "Papierkorb",
|
|
122
|
+
"Import": "Importieren",
|
|
123
|
+
"Export": "Exportieren",
|
|
124
|
+
"New": "Neu",
|
|
125
|
+
"Search": "Suchen",
|
|
126
|
+
"Reset": "Zurücksetzen",
|
|
127
|
+
"Filters": "Filter",
|
|
128
|
+
"Save View": "Ansicht speichern",
|
|
129
|
+
"Columns": "Spalten",
|
|
130
|
+
"Apply Filters": "Filter anwenden",
|
|
131
|
+
"Clear": "Leeren",
|
|
132
|
+
"Actions": "Aktionen",
|
|
133
|
+
"Edit": "Bearbeiten",
|
|
134
|
+
"Delete": "Löschen",
|
|
135
|
+
"Restore": "Wiederherstellen",
|
|
136
|
+
"History": "Verlauf",
|
|
137
|
+
"Clone": "Duplizieren",
|
|
138
|
+
"Cancel": "Abbrechen",
|
|
139
|
+
"Confirm": "Bestätigen",
|
|
140
|
+
"Save": "Speichern",
|
|
141
|
+
"Back": "Zurück",
|
|
142
|
+
"Prev": "Zurück",
|
|
143
|
+
"Next": "Weiter",
|
|
144
|
+
"First": "Erste",
|
|
145
|
+
"Preferences": "Einstellungen",
|
|
146
|
+
"Language": "Sprache",
|
|
147
|
+
"Timezone": "Zeitzone",
|
|
148
|
+
"Apply": "Übernehmen",
|
|
149
|
+
"matching records": "passende Einträge",
|
|
150
|
+
"Page Summary": "Seitensumme",
|
|
151
|
+
"Sign in": "Anmelden",
|
|
152
|
+
"Add Condition": "Bedingung hinzufügen",
|
|
153
|
+
"Exit Impersonation": "Impersonation beenden",
|
|
154
|
+
},
|
|
155
|
+
"ar": {
|
|
156
|
+
"Workspace": "مساحة العمل",
|
|
157
|
+
"Dashboard": "لوحة التحكم",
|
|
158
|
+
"Governance": "الحوكمة",
|
|
159
|
+
"Audit Ledger": "سجل التدقيق",
|
|
160
|
+
"RBAC Matrix": "مصفوفة الصلاحيات",
|
|
161
|
+
"Schema ERD": "مخطط الجداول",
|
|
162
|
+
"SQL Console": "وحدة SQL",
|
|
163
|
+
"Diagnostics": "التشخيص",
|
|
164
|
+
"Background Jobs": "المهام الخلفية",
|
|
165
|
+
"2FA Security": "التحقق الثنائي",
|
|
166
|
+
"Jump to model, record, action…": "ابحث عن نموذج أو سجل أو إجراء…",
|
|
167
|
+
"Filter models…": "تصفية النماذج…",
|
|
168
|
+
"Recent Events": "أحدث الأحداث",
|
|
169
|
+
"All →": "الكل ←",
|
|
170
|
+
"Keyboard Shortcuts": "اختصارات لوحة المفاتيح",
|
|
171
|
+
"Sign out": "تسجيل الخروج",
|
|
172
|
+
"Table": "جدول",
|
|
173
|
+
"Board": "لوحة كانبان",
|
|
174
|
+
"Trash": "سلة المحذوفات",
|
|
175
|
+
"Import": "استيراد",
|
|
176
|
+
"Export": "تصدير",
|
|
177
|
+
"New": "جديد",
|
|
178
|
+
"Search": "بحث",
|
|
179
|
+
"Reset": "إعادة تعيين",
|
|
180
|
+
"Filters": "الفلاتر",
|
|
181
|
+
"Save View": "حفظ العرض",
|
|
182
|
+
"Columns": "الأعمدة",
|
|
183
|
+
"Apply Filters": "تطبيق الفلاتر",
|
|
184
|
+
"Clear": "مسح",
|
|
185
|
+
"Actions": "إجراءات",
|
|
186
|
+
"Edit": "تعديل",
|
|
187
|
+
"Delete": "حذف",
|
|
188
|
+
"Restore": "استعادة",
|
|
189
|
+
"History": "السجل",
|
|
190
|
+
"Clone": "نسخ",
|
|
191
|
+
"Cancel": "إلغاء",
|
|
192
|
+
"Confirm": "تأكيد",
|
|
193
|
+
"Save": "حفظ",
|
|
194
|
+
"Back": "رجوع",
|
|
195
|
+
"Prev": "السابق",
|
|
196
|
+
"Next": "التالي",
|
|
197
|
+
"First": "الأول",
|
|
198
|
+
"Preferences": "التفضيلات",
|
|
199
|
+
"Language": "اللغة",
|
|
200
|
+
"Timezone": "المنطقة الزمنية",
|
|
201
|
+
"Apply": "تطبيق",
|
|
202
|
+
"matching records": "سجل مطابق",
|
|
203
|
+
"Page Summary": "ملخص الصفحة",
|
|
204
|
+
"Sign in": "تسجيل الدخول",
|
|
205
|
+
"Add Condition": "إضافة شرط",
|
|
206
|
+
"Exit Impersonation": "إنهاء الانتحال",
|
|
207
|
+
},
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@runtime_checkable
|
|
212
|
+
class Translator(Protocol):
|
|
213
|
+
"""Minimal localization contract implemented by DictTranslator and BabelTranslator."""
|
|
214
|
+
|
|
215
|
+
def translate(self, msgid: str, **params: Any) -> str:
|
|
216
|
+
"""Translate a UI message string for the active locale."""
|
|
217
|
+
|
|
218
|
+
def get_locale(self) -> str:
|
|
219
|
+
"""Return active BCP-47 / ISO-639 locale code (e.g. 'en', 'tr', 'ar')."""
|
|
220
|
+
|
|
221
|
+
def is_rtl(self, locale: str | None = None) -> bool:
|
|
222
|
+
"""Return True if the active or provided locale uses right-to-left script."""
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def normalize_locale(locale: str | None, fallback: str = "en") -> str:
|
|
226
|
+
if not locale:
|
|
227
|
+
return fallback
|
|
228
|
+
primary = locale.strip().replace("_", "-").split("-", 1)[0].lower()
|
|
229
|
+
return primary or fallback
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def is_rtl_locale(locale: str | None) -> bool:
|
|
233
|
+
return normalize_locale(locale) in RTL_LOCALES
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
@lru_cache(maxsize=1)
|
|
237
|
+
def _cached_timezones() -> frozenset[str]:
|
|
238
|
+
return frozenset(available_timezones())
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def is_valid_timezone(tz_name: str | None) -> bool:
|
|
242
|
+
if not tz_name or not isinstance(tz_name, str):
|
|
243
|
+
return False
|
|
244
|
+
clean = tz_name.strip()
|
|
245
|
+
if clean == "UTC":
|
|
246
|
+
return True
|
|
247
|
+
return clean in _cached_timezones()
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def set_request_locale_tz(locale: str, tz_name: str) -> None:
|
|
251
|
+
if has_request_context():
|
|
252
|
+
clean_tz = tz_name.strip() if isinstance(tz_name, str) else "UTC"
|
|
253
|
+
setattr(g, _G_LOCALE_KEY, normalize_locale(locale))
|
|
254
|
+
setattr(g, _G_TZ_KEY, clean_tz if is_valid_timezone(clean_tz) else "UTC")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def get_active_locale(default: str = "en") -> str:
|
|
258
|
+
if has_request_context():
|
|
259
|
+
val = getattr(g, _G_LOCALE_KEY, None)
|
|
260
|
+
if isinstance(val, str) and val:
|
|
261
|
+
return val
|
|
262
|
+
return default
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def get_active_timezone(default: str = "UTC") -> str:
|
|
266
|
+
if has_request_context():
|
|
267
|
+
val = getattr(g, _G_TZ_KEY, None)
|
|
268
|
+
if isinstance(val, str) and is_valid_timezone(val):
|
|
269
|
+
return val.strip()
|
|
270
|
+
return default
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _resolve_tz(zone_name: str) -> tzinfo:
|
|
274
|
+
if zone_name == "UTC":
|
|
275
|
+
return timezone.utc
|
|
276
|
+
try:
|
|
277
|
+
return ZoneInfo(zone_name)
|
|
278
|
+
except Exception:
|
|
279
|
+
return timezone.utc
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def to_user_timezone(dt: datetime, tz_name: str | None = None) -> datetime:
|
|
283
|
+
"""Convert an aware or naive-UTC datetime into the active user's ZoneInfo timezone."""
|
|
284
|
+
aware = dt if dt.tzinfo is not None else dt.replace(tzinfo=timezone.utc)
|
|
285
|
+
zone_name = (tz_name or get_active_timezone("UTC")).strip()
|
|
286
|
+
return aware.astimezone(_resolve_tz(zone_name))
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def from_user_timezone(
|
|
290
|
+
dt: datetime,
|
|
291
|
+
tz_name: str | None = None,
|
|
292
|
+
*,
|
|
293
|
+
store_naive_utc: bool = False,
|
|
294
|
+
) -> datetime:
|
|
295
|
+
"""Convert a naive user-entered datetime from active user timezone into UTC."""
|
|
296
|
+
if dt.tzinfo is None:
|
|
297
|
+
zone_name = (tz_name or get_active_timezone("UTC")).strip()
|
|
298
|
+
aware = dt.replace(tzinfo=_resolve_tz(zone_name))
|
|
299
|
+
else:
|
|
300
|
+
aware = dt
|
|
301
|
+
utc_dt = aware.astimezone(timezone.utc)
|
|
302
|
+
return utc_dt.replace(tzinfo=None) if store_naive_utc else utc_dt
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def format_locale_decimal(
|
|
306
|
+
value: Decimal | float | int,
|
|
307
|
+
*,
|
|
308
|
+
decimals: int = 2,
|
|
309
|
+
locale: str | None = None,
|
|
310
|
+
) -> str:
|
|
311
|
+
"""Format a number using locale-appropriate thousand and decimal separators."""
|
|
312
|
+
loc = normalize_locale(locale or get_active_locale("en"))
|
|
313
|
+
thousands_sep, dec_sep = _LOCALE_SEPARATORS.get(loc, (",", "."))
|
|
314
|
+
sign = "-" if value < 0 else ""
|
|
315
|
+
base = f"{abs(value):,.{decimals}f}"
|
|
316
|
+
if thousands_sep != "," or dec_sep != ".":
|
|
317
|
+
base = base.replace(",", "_").replace(".", dec_sep).replace("_", thousands_sep)
|
|
318
|
+
return f"{sign}{base}"
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
class DictTranslator:
|
|
322
|
+
"""Zero-dependency built-in translator with curated EN, TR, DE, and AR (RTL) catalogs."""
|
|
323
|
+
|
|
324
|
+
__slots__ = ("_catalogs", "_default_locale")
|
|
325
|
+
|
|
326
|
+
def __init__(
|
|
327
|
+
self,
|
|
328
|
+
*,
|
|
329
|
+
default_locale: str = "en",
|
|
330
|
+
extra_catalogs: Mapping[str, Mapping[str, str]] | None = None,
|
|
331
|
+
) -> None:
|
|
332
|
+
self._default_locale = normalize_locale(default_locale)
|
|
333
|
+
self._catalogs: dict[str, dict[str, str]] = {
|
|
334
|
+
code: dict(entries) for code, entries in BUILTIN_CATALOGS.items()
|
|
335
|
+
}
|
|
336
|
+
if extra_catalogs:
|
|
337
|
+
for code, entries in extra_catalogs.items():
|
|
338
|
+
norm = normalize_locale(code)
|
|
339
|
+
self._catalogs.setdefault(norm, {}).update(entries)
|
|
340
|
+
|
|
341
|
+
def get_locale(self) -> str:
|
|
342
|
+
return get_active_locale(self._default_locale)
|
|
343
|
+
|
|
344
|
+
def is_rtl(self, locale: str | None = None) -> bool:
|
|
345
|
+
return is_rtl_locale(locale or self.get_locale())
|
|
346
|
+
|
|
347
|
+
def translate(self, msgid: str, **params: Any) -> str:
|
|
348
|
+
loc = self.get_locale()
|
|
349
|
+
catalog = self._catalogs.get(loc, {})
|
|
350
|
+
text = catalog.get(msgid, msgid)
|
|
351
|
+
if params:
|
|
352
|
+
try:
|
|
353
|
+
return text.format(**params)
|
|
354
|
+
except Exception:
|
|
355
|
+
return text
|
|
356
|
+
return text
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
class BabelTranslator:
|
|
360
|
+
"""Optional Flask-Babel adapter (requires `pip install 'flask-deck[babel]'`)."""
|
|
361
|
+
|
|
362
|
+
__slots__ = ("_babel_module", "_fallback")
|
|
363
|
+
|
|
364
|
+
def __init__(
|
|
365
|
+
self,
|
|
366
|
+
*,
|
|
367
|
+
babel_module: Any | None = None,
|
|
368
|
+
fallback_locale: str = "en",
|
|
369
|
+
) -> None:
|
|
370
|
+
if babel_module is None:
|
|
371
|
+
try:
|
|
372
|
+
import flask_babel # type: ignore[import-not-found]
|
|
373
|
+
except ImportError as exc:
|
|
374
|
+
raise RuntimeError(
|
|
375
|
+
"Flask-Babel is required for BabelTranslator. "
|
|
376
|
+
"Install with: pip install 'flask-deck[babel]'"
|
|
377
|
+
) from exc
|
|
378
|
+
babel_module = flask_babel
|
|
379
|
+
self._babel_module = babel_module
|
|
380
|
+
self._fallback = DictTranslator(default_locale=fallback_locale)
|
|
381
|
+
|
|
382
|
+
def get_locale(self) -> str:
|
|
383
|
+
getter = getattr(self._babel_module, "get_locale", None)
|
|
384
|
+
if callable(getter):
|
|
385
|
+
loc = getter()
|
|
386
|
+
if loc is not None:
|
|
387
|
+
return normalize_locale(str(loc))
|
|
388
|
+
return self._fallback.get_locale()
|
|
389
|
+
|
|
390
|
+
def is_rtl(self, locale: str | None = None) -> bool:
|
|
391
|
+
return is_rtl_locale(locale or self.get_locale())
|
|
392
|
+
|
|
393
|
+
def translate(self, msgid: str, **params: Any) -> str:
|
|
394
|
+
gettext_fn = getattr(self._babel_module, "gettext", None)
|
|
395
|
+
if callable(gettext_fn):
|
|
396
|
+
translated = str(gettext_fn(msgid, **params))
|
|
397
|
+
if translated != msgid:
|
|
398
|
+
return translated
|
|
399
|
+
return self._fallback.translate(msgid, **params)
|
flask_deck/icons.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from markupsafe import Markup, escape
|
|
4
|
+
|
|
5
|
+
# Curated Lucide-style stroke paths (24x24 viewBox, stroke-width 1.75) — zero external icon fonts.
|
|
6
|
+
_ICONS: dict[str, str] = {
|
|
7
|
+
"activity": '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>',
|
|
8
|
+
"alert-triangle": '<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/>',
|
|
9
|
+
"archive": '<polyline points="21 8 21 21 3 21 3 8"/><rect x="1" y="3" width="22" height="5"/><line x1="10" y1="12" x2="14" y2="12"/>',
|
|
10
|
+
"arrow-down": '<line x1="12" y1="5" x2="12" y2="19"/><polyline points="19 12 12 19 5 12"/>',
|
|
11
|
+
"arrow-left": '<line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/>',
|
|
12
|
+
"arrow-right": '<line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/>',
|
|
13
|
+
"arrow-up": '<line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/>',
|
|
14
|
+
"arrow-up-down": '<path d="m21 16-4 4-4-4"/><path d="M17 20V4"/><path d="m3 8 4-4 4 4"/><path d="M7 4v16"/>',
|
|
15
|
+
"bell": '<path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/>',
|
|
16
|
+
"bookmark": '<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/>',
|
|
17
|
+
"box": '<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/>',
|
|
18
|
+
"building": '<rect x="4" y="2" width="16" height="20" rx="2" ry="2"/><path d="M9 22v-4h6v4"/><path d="M8 6h.01"/><path d="M16 6h.01"/><path d="M12 6h.01"/><path d="M12 10h.01"/><path d="M12 14h.01"/><path d="M16 10h.01"/><path d="M16 14h.01"/><path d="M8 10h.01"/><path d="M8 14h.01"/>',
|
|
19
|
+
"check": '<polyline points="20 6 9 17 4 12"/>',
|
|
20
|
+
"check-circle": '<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>',
|
|
21
|
+
"chevron-down": '<polyline points="6 9 12 15 18 9"/>',
|
|
22
|
+
"chevron-left": '<polyline points="15 18 9 12 15 6"/>',
|
|
23
|
+
"chevron-right": '<polyline points="9 18 15 12 9 6"/>',
|
|
24
|
+
"clock": '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
|
|
25
|
+
"code": '<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>',
|
|
26
|
+
"columns": '<rect x="3" y="3" width="18" height="18" rx="2"/><line x1="12" y1="3" x2="12" y2="21"/>',
|
|
27
|
+
"command": '<path d="M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3"/>',
|
|
28
|
+
"copy": '<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>',
|
|
29
|
+
"cpu": '<rect x="4" y="4" width="16" height="16" rx="2"/><rect x="9" y="9" width="6" height="6"/><line x1="9" y1="1" x2="9" y2="4"/><line x1="15" y1="1" x2="15" y2="4"/><line x1="9" y1="20" x2="9" y2="23"/><line x1="15" y1="20" x2="15" y2="23"/><line x1="20" y1="9" x2="23" y2="9"/><line x1="20" y1="14" x2="23" y2="14"/><line x1="1" y1="9" x2="4" y2="9"/><line x1="1" y1="14" x2="4" y2="14"/>',
|
|
30
|
+
"credit-card": '<rect x="2" y="5" width="20" height="14" rx="2"/><line x1="2" y1="10" x2="22" y2="10"/>',
|
|
31
|
+
"database": '<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14a9 3 0 0 0 18 0V5"/><path d="M3 12a9 3 0 0 0 18 0"/>',
|
|
32
|
+
"dollar-sign": '<line x1="12" y1="2" x2="12" y2="22"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>',
|
|
33
|
+
"download": '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/>',
|
|
34
|
+
"edit": '<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>',
|
|
35
|
+
"eye": '<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/>',
|
|
36
|
+
"file-text": '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><line x1="10" y1="9" x2="8" y2="9"/>',
|
|
37
|
+
"filter": '<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"/>',
|
|
38
|
+
"git-branch": '<line x1="6" y1="3" x2="6" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',
|
|
39
|
+
"git-compare": '<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M13 6h3a2 2 0 0 1 2 2v7"/><path d="M11 18H8a2 2 0 0 1-2-2V9"/>',
|
|
40
|
+
"globe": '<circle cx="12" cy="12" r="10"/><line x1="2" y1="12" x2="22" y2="12"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>',
|
|
41
|
+
"heart-pulse": '<path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z"/><path d="M3.22 12H9.5l.5-1 2 4.5 2-7 1.5 3.5h5.27"/>',
|
|
42
|
+
"history": '<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/>',
|
|
43
|
+
"image": '<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>',
|
|
44
|
+
"kanban": '<rect x="3" y="3" width="5" height="18" rx="1"/><rect x="10" y="3" width="5" height="12" rx="1"/><rect x="17" y="3" width="4" height="15" rx="1"/>',
|
|
45
|
+
"key": '<circle cx="7.5" cy="15.5" r="5.5"/><path d="m21 2-9.6 9.6"/><path d="m15.5 7.5 3 3L22 7l-3-3"/>',
|
|
46
|
+
"keyboard": '<rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.001"/><path d="M10 8h.001"/><path d="M14 8h.001"/><path d="M18 8h.001"/><path d="M8 12h.001"/><path d="M12 12h.001"/><path d="M16 12h.001"/><path d="M7 16h10"/>',
|
|
47
|
+
"layers": '<polygon points="12 2 2 7 12 12 22 7 12 2"/><polyline points="2 17 12 22 22 17"/><polyline points="2 12 12 17 22 12"/>',
|
|
48
|
+
"layout-dashboard": '<rect x="3" y="3" width="7" height="9" rx="1"/><rect x="14" y="3" width="7" height="5" rx="1"/><rect x="14" y="12" width="7" height="9" rx="1"/><rect x="3" y="16" width="7" height="5" rx="1"/>',
|
|
49
|
+
"life-buoy": '<circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="4"/><line x1="4.93" y1="4.93" x2="9.17" y2="9.17"/><line x1="14.83" y1="14.83" x2="19.07" y2="19.07"/><line x1="14.83" y1="9.17" x2="19.07" y2="4.93"/><line x1="4.93" y1="19.07" x2="9.17" y2="14.83"/>',
|
|
50
|
+
"list": '<line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/>',
|
|
51
|
+
"lock": '<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/>',
|
|
52
|
+
"log-out": '<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/>',
|
|
53
|
+
"menu": '<line x1="4" y1="6" x2="20" y2="6"/><line x1="4" y1="12" x2="20" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/>',
|
|
54
|
+
"moon": '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>',
|
|
55
|
+
"package": '<path d="m16.5 9.4-9-5.19"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>',
|
|
56
|
+
"paperclip": '<path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/>',
|
|
57
|
+
"play": '<polygon points="5 3 19 12 5 21 5 3"/>',
|
|
58
|
+
"plus": '<line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/>',
|
|
59
|
+
"refresh-cw": '<polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/>',
|
|
60
|
+
"rotate-ccw": '<polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/>',
|
|
61
|
+
"search": '<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>',
|
|
62
|
+
"shield": '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>',
|
|
63
|
+
"shield-check": '<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/><path d="m9 12 2 2 4-4"/>',
|
|
64
|
+
"shopping-bag": '<path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"/><line x1="3" y1="6" x2="21" y2="6"/><path d="M16 10a4 4 0 0 1-8 0"/>',
|
|
65
|
+
"sliders": '<line x1="4" y1="21" x2="4" y2="14"/><line x1="4" y1="10" x2="4" y2="3"/><line x1="12" y1="21" x2="12" y2="12"/><line x1="12" y1="8" x2="12" y2="3"/><line x1="20" y1="21" x2="20" y2="16"/><line x1="20" y1="12" x2="20" y2="3"/><line x1="1" y1="14" x2="7" y2="14"/><line x1="9" y1="8" x2="15" y2="8"/><line x1="17" y1="16" x2="23" y2="16"/>',
|
|
66
|
+
"stop-circle": '<circle cx="12" cy="12" r="10"/><rect x="9" y="9" width="6" height="6"/>',
|
|
67
|
+
"sun": '<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>',
|
|
68
|
+
"table": '<rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="3" y1="15" x2="21" y2="15"/><line x1="9" y1="3" x2="9" y2="21"/>',
|
|
69
|
+
"tag": '<path d="M20.59 13.41 13.42 20.58a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"/><line x1="7" y1="7" x2="7.01" y2="7"/>',
|
|
70
|
+
"terminal": '<polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/>',
|
|
71
|
+
"trash": '<polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',
|
|
72
|
+
"trending-up": '<polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/><polyline points="17 6 23 6 23 12"/>',
|
|
73
|
+
"truck": '<rect x="1" y="3" width="15" height="13"/><polygon points="16 8 20 8 23 11 23 16 16 16 16 8"/><circle cx="5.5" cy="18.5" r="2.5"/><circle cx="18.5" cy="18.5" r="2.5"/>',
|
|
74
|
+
"upload": '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/>',
|
|
75
|
+
"user": '<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>',
|
|
76
|
+
"user-check": '<path d="M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="8.5" cy="7" r="4"/><polyline points="17 11 19 13 23 9"/>',
|
|
77
|
+
"users": '<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/>',
|
|
78
|
+
"x": '<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>',
|
|
79
|
+
"zap": '<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>',
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def render_icon(name: str, size: int = 15, cls: str = "") -> Markup:
|
|
84
|
+
"""Render an inline SVG icon safely with zero external font or CDN requests."""
|
|
85
|
+
body = _ICONS.get(name, _ICONS["database"])
|
|
86
|
+
safe_size = max(10, min(48, int(size)))
|
|
87
|
+
class_attr = f' class="dk-icon {escape(cls)}"' if cls else ' class="dk-icon"'
|
|
88
|
+
return Markup(
|
|
89
|
+
f'<svg{class_attr} width="{safe_size}" height="{safe_size}" viewBox="0 0 24 24" '
|
|
90
|
+
'fill="none" stroke="currentColor" stroke-width="1.75" '
|
|
91
|
+
f'stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">{body}</svg>'
|
|
92
|
+
)
|