From 5c06b6c31af0e583a9311d1ff707867fc173c92e Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 1 Oct 2024 19:19:08 -0700 Subject: [PATCH] names: Don't show resolver status if package is not installed Tests: - Ensure that systemd-resolved package is not installed. - Resolver status table is now shown. - Instead a message is shown with button to re-run setup. Clicking the button re-runs setup of the names app. - Configuration form is also now shown. - If systemd-resolved package is installed during re-run of setup, then status table is shown. - Message to install systemd-resolved is not shown. - Configuration form is shown. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/modules/names/templates/names.html | 22 +++++++++++++++++++++- plinth/modules/names/views.py | 14 +++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/plinth/modules/names/templates/names.html b/plinth/modules/names/templates/names.html index 6c54a6ad2..80effd115 100644 --- a/plinth/modules/names/templates/names.html +++ b/plinth/modules/names/templates/names.html @@ -55,7 +55,7 @@

{% trans "Resolver Status" %}

- {% if resolved_status %} + {% if resolved_installed and resolved_status %}
@@ -107,6 +107,20 @@
+ {% elif not resolved_installed %} +

+ {% blocktrans trimmed %} + systemd-resolved package is not installed. Install it for additional + functionality. + {% endblocktrans %} +

+ {% csrf_token %} + + +
+

{% else %}
{% trans "Error retrieving status:" %} {{ resolved_status_error }} @@ -114,3 +128,9 @@ {% endif %} {% endblock %} + +{% block configuration %} + {% if resolved_installed %} + {{ block.super }} + {% endif %} +{% endblock %} diff --git a/plinth/modules/names/views.py b/plinth/modules/names/views.py index b5e94dcd1..27d3a6376 100644 --- a/plinth/modules/names/views.py +++ b/plinth/modules/names/views.py @@ -31,17 +31,21 @@ class NamesAppView(AppView): def get_initial(self): """Return the values to fill in the form.""" initial = super().get_initial() - initial.update(privileged.get_resolved_configuration()) + if names.is_resolved_installed(): + initial.update(privileged.get_resolved_configuration()) + return initial def get_context_data(self, *args, **kwargs): """Add additional context data for template.""" context = super().get_context_data(*args, **kwargs) context['status'] = get_status() - try: - context['resolved_status'] = resolved.get_status() - except Exception as exception: - context['resolved_status_error'] = exception + context['resolved_installed'] = names.is_resolved_installed() + if context['resolved_installed']: + try: + context['resolved_status'] = resolved.get_status() + except Exception as exception: + context['resolved_status_error'] = exception return context