Coverage for an_website/utils/themes.py: 100.000%

11 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-10 18:56 +0000

1# This program is free software: you can redistribute it and/or modify 

2# it under the terms of the GNU Affero General Public License as 

3# published by the Free Software Foundation, either version 3 of the 

4# License, or (at your option) any later version. 

5# 

6# This program is distributed in the hope that it will be useful, 

7# but WITHOUT ANY WARRANTY; without even the implied warranty of 

8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

9# GNU Affero General Public License for more details. 

10# 

11# You should have received a copy of the GNU Affero General Public License 

12# along with this program. If not, see <https://www.gnu.org/licenses/>. 

13 

14"""A module providing THEMES.""" 

15 

16from collections.abc import Iterable, Sequence 

17from typing import Final 

18 

19from .. import STATIC_DIR 

20 

21 

22def get_themes() -> Iterable[str]: 

23 """Get a list of available themes.""" 

24 for file in (STATIC_DIR / "css/themes").iterdir(): 

25 if file.is_file() and file.name.endswith(".css"): 

26 yield file.name[:-4] 

27 yield "random" # add random to the list of themes 

28 

29 

30THEMES: Final[Sequence[str]] = tuple(sorted(get_themes())) 

31NAMED_THEMES: Final[Sequence[tuple[str, str]]] = tuple( 

32 (theme, theme.replace("_", " ").title()) 

33 for theme in THEMES 

34 if theme != "lowest_contrast" 

35) 

36RANDOM_THEMES: Final[Sequence[str]] = tuple( 

37 theme for theme, _ in NAMED_THEMES if theme not in {"random", "christmas"} 

38)