Coverage for app/venv/lib/python3.14/site-packages/weblate/utils/docs.py: 83%

17 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4from __future__ import annotations 

5 

6from typing import TYPE_CHECKING 

7 

8from django.conf import settings 

9from django.utils.translation import get_language 

10from weblate_language_data.docs import DOCUMENTATION_LANGUAGES 

11 

12import weblate.utils.version 

13 

14if TYPE_CHECKING: 14 ↛ 15line 14 didn't jump to line 15 because the condition on line 14 was never true

15 from weblate.auth.models import User 

16 

17 

18def get_doc_url(page: str, anchor: str = "", user: User | None = None) -> str: 

19 """Return URL to documentation.""" 

20 version = weblate.utils.version.VERSION 

21 # Should we use tagged release or latest version 

22 if version.endswith(("-dev", "-rc")) or ( 22 ↛ 25line 22 didn't jump to line 25 because the condition on line 22 was never true

23 settings.HIDE_VERSION and (user is None or not user.is_authenticated) 

24 ): 

25 doc_version = "latest" 

26 else: 

27 doc_version = f"weblate-{version}" 

28 # Language variant 

29 code = DOCUMENTATION_LANGUAGES.get(get_language(), "en") 

30 # Optionally append anchor 

31 if anchor: 

32 anchor = f"#{anchor}" 

33 # Generate URL 

34 return f"https://docs.weblate.org/{code}/{doc_version}/{page}.html{anchor}"