Coverage for src/comments_views/core/app_settings.py: 71%
22 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
1from django.conf import settings
4class AppSettings:
5 """Wrapper for django settings related to this application."""
7 def __init__(self):
8 self.prefix = "COMMENTS_VIEWS_"
10 def _setting(self, name, default):
11 """
12 Gets the provided setting with the app prefix (see `self.prefix`).
13 Params:
14 - `name`: The name of the setting.
15 - `default`: Fallback if the settings is not defined.
16 """
17 return getattr(settings, self.prefix + name, default)
19 @property
20 def API_BASE_URL(self) -> str:
21 """
22 The base URL of the comments database server.
23 Falls back to https://comments.centre-mersenne.org.
24 """
25 return self._setting("API_BASE_URL", "https://comments.centre-mersenne.org")
27 @property
28 def API_CREDENTIALS(self):
29 """
30 Credentials used to authenticate when performing API calls to the comments
31 server.
32 """
33 return self._setting("API_CREDENTIALS", None)
35 @property
36 def EMAIL_AUTHOR(self) -> bool:
37 """
38 Whether to send an e-mail to the article's authors when a comment is validated
39 by a moderator.
40 Default: True.
42 TODO: This should be included in the comments_moderation app instead.
43 There is a design error regarding the POST function of
44 `CommentDashboardDetailsView`. It's used differently by comments_views/journal
45 and comments_moderation apps. The POST logic for the moderation should be
46 overwritten in comments_moderation app instead of being located
47 in comments_views/core.
48 """
49 return self._setting("EMAIL_AUTHOR", True)
51 @property
52 def ORCID_BASE_URL(self) -> str:
53 """
54 Base URL used to generate ORCID record links.
56 This should only be used in test to use https://sandbox.orcid.org/ domain
57 instead of https://orcid.org/
58 """
59 url = self._setting("ORCID_BASE_URL", "https://orcid.org/")
60 if url[-1] != "/":
61 url += "/"
62 return url
65app_settings = AppSettings()