add support for adding reference links to values

Now Value classes accept a 'help_reference' keyword which will get printed when a
ValueRetrievalError or ValueProcessingError occurs
This commit is contained in:
Finn-Thorben Sell 2022-03-24 11:05:20 +01:00
parent 50ac28b667
commit 12ffda4760
No known key found for this signature in database
GPG key ID: A78A03C25A3A3825
3 changed files with 7 additions and 2 deletions

View file

@ -19,6 +19,9 @@ def extract_explanation_lines_from_value(value_instance: 'Value') -> List[str]:
if value_instance.help_text is not None:
result.append(f"Help: {value_instance.help_text}")
if value_instance.help_reference is not None:
result.append(f"Reference: {value_instance.help_reference}")
if value_instance.destination_name is not None:
result.append(f"{value_instance.destination_name} is taken from the environment variable "
f"{value_instance.full_environ_name} as a {type(value_instance).__name__}")

View file

@ -59,7 +59,7 @@ class Value:
def __init__(self, default=None, environ=True, environ_name=None,
environ_prefix='DJANGO', environ_required=False, help_text=None,
*args, **kwargs):
help_reference=None, *args, **kwargs):
if isinstance(default, Value) and default.default is not None:
self.default = copy.copy(default.default)
else:
@ -72,6 +72,7 @@ class Value:
self.environ_required = environ_required
self.destination_name = None
self.help_text = help_text
self.help_reference = help_reference
def __str__(self):
return str(self.value)

View file

@ -4,7 +4,8 @@ from configurations import Configuration, values
class Base(Configuration):
# Django settings for test_project project.
DEBUG = values.BooleanValue(True, environ=True, help_text="Enables or disables django debug mode")
DEBUG = values.BooleanValue(True, environ=True, help_text="Enables or disables django debug mode",
help_reference="https://docs.djangoproject.com/en/dev/ref/settings/#debug")
ADMINS = (
# ('Your Name', 'your_email@example.com'),