Coverage for app/venv/lib/python3.14/site-packages/weblate/wladmin/apps.py: 61%

39 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 

4 

5from __future__ import annotations 

6 

7from typing import TYPE_CHECKING 

8 

9from django.apps import AppConfig 

10from django.core.checks import Info, register 

11 

12from weblate.utils.checks import weblate_check 

13from weblate.wladmin.sites import patch_admin_site 

14 

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

16 from collections.abc import Iterable, Sequence 

17 

18 from django.core.checks import CheckMessage 

19 

20patch_admin_site() 

21 

22 

23class WLAdminConfig(AppConfig): 

24 name = "weblate.wladmin" 

25 label = "wladmin" 

26 verbose_name = "Weblate Admin Extensions" 

27 

28 

29@register(deploy=True) 

30def check_backups( 

31 *, 

32 app_configs: Sequence[AppConfig] | None, 

33 databases: Sequence[str] | None, 

34 **kwargs, 

35) -> Iterable[CheckMessage]: 

36 from weblate.wladmin.models import BackupService 

37 

38 errors = [] 

39 if not BackupService.objects.filter(enabled=True).exists(): 39 ↛ 48line 39 didn't jump to line 48 because the condition on line 39 was always true

40 errors.append( 

41 weblate_check( 

42 "weblate.I028", 

43 "Backups are not configured, " 

44 "it is highly recommended for production use", 

45 Info, 

46 ) 

47 ) 

48 for service in BackupService.objects.filter(enabled=True): 48 ↛ 49line 48 didn't jump to line 49 because the loop on line 48 never started

49 try: 

50 last_obj = service.last_logs[0] 

51 except IndexError: 

52 last_event = "error" 

53 last_log = "backup was never triggered" 

54 else: 

55 last_event = last_obj.event 

56 last_log = last_obj.log 

57 if last_event == "error": 

58 errors.append( 

59 weblate_check( 

60 "weblate.C029", 

61 f"There was error while performing backups: {last_log}", 

62 ) 

63 ) 

64 break 

65 

66 return errors 

67 

68 

69@register(deploy=True) 

70def check_support( 

71 *, 

72 app_configs: Sequence[AppConfig] | None, 

73 databases: Sequence[str] | None, 

74 **kwargs, 

75) -> Iterable[CheckMessage]: 

76 from weblate.wladmin.models import SupportStatus 

77 

78 support_status = SupportStatus.objects.get_current() 

79 if not support_status.has_expired_support or support_status.expiry is None: 79 ↛ 81line 79 didn't jump to line 81 because the condition on line 79 was always true

80 return [] 

81 return [ 

82 weblate_check( 

83 "weblate.C041", 

84 f"Your support subscription has expired on {support_status.expiry.date().isoformat()}. Please renew it at https://weblate.org/user/ or contact Weblate care.", 

85 ) 

86 ]