Skip to content

Commit eea1aa3

Browse files
committed
docs(config): autogenerate notification configuration options
1 parent 04acc2c commit eea1aa3

5 files changed

Lines changed: 156 additions & 72 deletions

File tree

docs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ update-docs:
5353
@uv run --no-sync ../manage.py list_checks -s checks -o snippets/checks-autogenerated.rst
5454
@uv run --no-sync ../manage.py list_checks -s flags -o snippets/check-flags-autogenerated.rst
5555
@uv run --no-sync ../manage.py list_format_features -o snippets/format-features
56+
@uv run --no-sync ../manage.py list_notification_config -o snippets/notifications-config.rst
5657

5758
# Catch-all target: route all unknown targets to Sphinx using the new
5859
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).

docs/admin/config.rst

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -812,78 +812,7 @@ Default notification settings for every created user.
812812

813813
A list of 3-tuples consisting of notification scope, notification frequency and notification handler.
814814

815-
Scopes:
816-
817-
``0``
818-
:guilabel:`All`
819-
``10``
820-
:guilabel:`Watched`
821-
``20``
822-
:guilabel:`Administered`
823-
``30``
824-
:guilabel:`Project`
825-
``40``
826-
:guilabel:`Component`
827-
828-
Frequencies:
829-
830-
``0``
831-
:guilabel:`No notification`
832-
``1``
833-
:guilabel:`Instant notification`
834-
``2``
835-
:guilabel:`Daily digest`
836-
``3``
837-
:guilabel:`Weekly digest`
838-
``4``
839-
:guilabel:`Monthly digest`
840-
841-
Handlers:
842-
843-
``RepositoryNotification``
844-
:guilabel:`Operation was performed in the repository`
845-
``LockNotification``
846-
:guilabel:`Component was locked or unlocked`
847-
``LicenseNotification``
848-
:guilabel:`License was changed`
849-
``ParseErrorNotification``
850-
:guilabel:`Parse error occurred`
851-
``NewStringNotificaton``
852-
:guilabel:`String is available for translation`
853-
``NewContributorNotificaton``
854-
:guilabel:`Contributor made their first translation`
855-
``NewSuggestionNotificaton``
856-
:guilabel:`Suggestion was added`
857-
``LanguageTranslatedNotificaton``
858-
:guilabel:`Language was translated`
859-
``ComponentTranslatedNotificaton``
860-
:guilabel:`Component was translated`
861-
``NewCommentNotificaton``
862-
:guilabel:`Comment was added`
863-
``MentionCommentNotificaton``
864-
:guilabel:`You were mentioned in a comment`
865-
``LastAuthorCommentNotificaton``
866-
:guilabel:`Your translation received a comment`
867-
``TranslatedStringNotificaton``
868-
:guilabel:`String was edited by user`
869-
``ApprovedStringNotificaton``
870-
:guilabel:`String was approved`
871-
``ChangedStringNotificaton``
872-
:guilabel:`String was changed`
873-
``NewTranslationNotificaton``
874-
:guilabel:`New language was added or requested`
875-
``NewComponentNotificaton``
876-
:guilabel:`New translation component was created`
877-
``NewAnnouncementNotificaton``
878-
:guilabel:`Announcement was published`
879-
``NewAlertNotificaton``
880-
:guilabel:`New alert emerged in a component`
881-
``MergeFailureNotification``
882-
:guilabel:`Repository operation failed`
883-
``PendingSuggestionsNotification``
884-
:guilabel:`Pending suggestions exist`
885-
``ToDoStringsNotification``
886-
:guilabel:`Unfinished strings exist`
815+
.. include:: /snippets/notifications-config.rst
887816

888817
.. note::
889818

docs/admin/management.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,17 @@ list_machinery
827827

828828
Lists automatic suggestions services in reStructuredText as a template for :doc:`/admin/machine`.
829829

830+
.. seealso::
831+
832+
:doc:`/contributing/documentation`
833+
834+
list_notification_config
835+
------------------------
836+
837+
.. weblate-admin:: list_notification_config
838+
839+
Lists notification scopes, frequencies and handlers in reStructuredText as a template for :doc:`/admin/config`.
840+
830841
.. seealso::
831842

832843
:doc:`/contributing/documentation`
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Scopes:
2+
3+
.. AUTOGENERATED START: notification-scopes
4+
.. This section is automatically generated by `./manage.py list_notification_config`. Do not edit manually.
5+
6+
``0``
7+
:guilabel:`All`
8+
``10``
9+
:guilabel:`Watched`
10+
``20``
11+
:guilabel:`Administered`
12+
``30``
13+
:guilabel:`Project`
14+
``40``
15+
:guilabel:`Component`
16+
17+
.. AUTOGENERATED END: notification-scopes
18+
19+
Frequencies:
20+
21+
.. AUTOGENERATED START: notification-frequencies
22+
.. This section is automatically generated by `./manage.py list_notification_config`. Do not edit manually.
23+
24+
``0``
25+
:guilabel:`No notification`
26+
``1``
27+
:guilabel:`Instant notification`
28+
``2``
29+
:guilabel:`Daily digest`
30+
``3``
31+
:guilabel:`Weekly digest`
32+
``4``
33+
:guilabel:`Monthly digest`
34+
35+
.. AUTOGENERATED END: notification-frequencies
36+
37+
Handlers:
38+
39+
.. AUTOGENERATED START: notification-handlers
40+
.. This section is automatically generated by `./manage.py list_notification_config`. Do not edit manually.
41+
42+
``ApprovedStringNotificaton``
43+
:guilabel:`String was approved`
44+
``ChangedStringNotificaton``
45+
:guilabel:`String was changed`
46+
``ComponentTranslatedNotificaton``
47+
:guilabel:`Component was translated`
48+
``LanguageTranslatedNotificaton``
49+
:guilabel:`Language was translated`
50+
``LastAuthorCommentNotificaton``
51+
:guilabel:`Your translation received a comment`
52+
``LicenseNotification``
53+
:guilabel:`License was changed`
54+
``LockNotification``
55+
:guilabel:`Component was locked or unlocked`
56+
``MentionCommentNotificaton``
57+
:guilabel:`You were mentioned in a comment`
58+
``MergeFailureNotification``
59+
:guilabel:`Repository operation failed`
60+
``NewAlertNotificaton``
61+
:guilabel:`New alert emerged in a component`
62+
``NewAnnouncementNotificaton``
63+
:guilabel:`Announcement was published`
64+
``NewCommentNotificaton``
65+
:guilabel:`Comment was added`
66+
``NewComponentNotificaton``
67+
:guilabel:`New translation component was created`
68+
``NewContributorNotificaton``
69+
:guilabel:`Contributor made their first translation`
70+
``NewStringNotificaton``
71+
:guilabel:`String is available for translation`
72+
``NewSuggestionNotificaton``
73+
:guilabel:`Suggestion was added`
74+
``NewTranslationNotificaton``
75+
:guilabel:`New language was added or requested`
76+
``ParseErrorNotification``
77+
:guilabel:`Parse error occurred`
78+
``PendingSuggestionsNotification``
79+
:guilabel:`Pending suggestions exist`
80+
``RepositoryNotification``
81+
:guilabel:`Operation was performed in the repository`
82+
``ToDoStringsNotification``
83+
:guilabel:`Unfinished strings exist`
84+
``TranslatedStringNotificaton``
85+
:guilabel:`String was edited by user`
86+
``TranslationActivitySummaryNotification``
87+
:guilabel:`Translation activity summary`
88+
89+
.. AUTOGENERATED END: notification-handlers
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright © Michal Čihař <michal@weblate.org>
2+
#
3+
# SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
from __future__ import annotations
6+
7+
from typing import TYPE_CHECKING
8+
9+
from weblate.accounts.notifications import (
10+
NOTIFICATIONS,
11+
NotificationFrequency,
12+
NotificationScope,
13+
)
14+
from weblate.utils.management.base import DocGeneratorCommand
15+
16+
if TYPE_CHECKING:
17+
from collections.abc import Iterable
18+
19+
from weblate.accounts.notifications import (
20+
Notification,
21+
)
22+
23+
24+
def sorted_handlers(handlers: Iterable[Notification]) -> Iterable[Notification]:
25+
return sorted(handlers, key=lambda handler: handler.__name__)
26+
27+
28+
class Command(DocGeneratorCommand):
29+
help = "Lists notification scopes, frequencies and handlers"
30+
31+
def handle(self, *args, **options) -> None:
32+
"""List notification scopes, frequencies and handlers."""
33+
scope_content = []
34+
for scope in NotificationScope:
35+
scope_content.extend(
36+
[f"``{scope.value}``", f" :guilabel:`{scope.label}`"]
37+
)
38+
self.add_section("notification-scopes", scope_content)
39+
40+
frequency_content = []
41+
for scope in NotificationFrequency:
42+
frequency_content.extend(
43+
[f"``{scope.value}``", f" :guilabel:`{scope.label}`"]
44+
)
45+
self.add_section("notification-frequencies", frequency_content)
46+
47+
handler_content = []
48+
for handler in sorted_handlers(NOTIFICATIONS):
49+
handler_content.extend(
50+
[f"``{handler.__name__}``", f" :guilabel:`{handler.verbose}`"]
51+
)
52+
self.add_section("notification-handlers", handler_content)
53+
54+
self.write_sections(options.get("output"))

0 commit comments

Comments
 (0)