From de82f5002d1e1ddffcac55878faae3414d1a4d60 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 14 Jan 2019 11:34:45 -0800 Subject: [PATCH] setup: Handle showing setup page after app completes installation - During the rendering of the view, the state of installation may keep changing. This may lead to inconsistencies in the page. Avoid that by collecting the state once and then reusing that throughout the rendering process. - During the time that setup middleware's checked of setup state of an app and rendering of app's setup view, if the setup process could get completed. This will lead to setup page being shown even after the application is installed. Handle this case and show a proper page instead of 'Submit Query' button on the page. Fixes #1360. This can be easily replicated by introducing a 10 second sleep after setup middle checks of the application is 'up-to-date'. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/templates/setup.html | 27 +++++++++++++++------------ plinth/views.py | 8 +++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/plinth/templates/setup.html b/plinth/templates/setup.html index 08c9ff131..d7a96b060 100644 --- a/plinth/templates/setup.html +++ b/plinth/templates/setup.html @@ -23,7 +23,7 @@ {% load static %} {% block page_head %} - {% if setup_helper.current_operation %} + {% if setup_current_operation or setup_state == 'up-to-date' %} @@ -48,14 +48,18 @@ {% include "clients.html" with clients=setup_helper.module.clients %} - {% if not setup_helper.current_operation %} + {% if setup_state == 'up-to-date' %} + + {% trans "Application installated." %} + + {% elif not setup_current_operation %}

- {% if setup_helper.get_state == 'needs-setup' %} + {% if setup_state == 'needs-setup' %} {% blocktrans trimmed %} Install this application? {% endblocktrans %} - {% elif setup_helper.get_state == 'needs-update' %} + {% elif setup_state == 'needs-update' %} {% blocktrans trimmed %} This application needs an update. Update now? {% endblocktrans %} @@ -87,27 +91,26 @@ {% if package_manager_is_busy or setup_helper.has_unavailable_packages %} disabled="disabled" {% endif %} - {% if setup_helper.get_state == 'needs-setup' %} + {% if setup_state == 'needs-setup' %} value="{% trans "Install" %}" - {% elif setup_helper.get_state == 'needs-upgrade' %} + {% elif setup_state == 'needs-upgrade' %} value="{% trans "Update" %}" {% endif %} /> - {% else %} - {% if setup_helper.current_operation.step == 'pre' %} + {% if setup_current_operation.step == 'pre' %}

{% trans "Performing pre-install operation" %}
- {% elif setup_helper.current_operation.step == 'post' %} + {% elif setup_current_operation.step == 'post' %}
{% trans "Performing post-install operation" %}
- {% elif setup_helper.current_operation.step == 'install' %} - {% with transaction=setup_helper.current_operation.transaction %} + {% elif setup_current_operation.step == 'install' %} + {% with transaction=setup_current_operation.transaction %}
{% blocktrans trimmed with package_names=transaction.package_names|join:", " status=transaction.status_string %} Installing {{ package_names }}: {{ status }} @@ -135,7 +138,7 @@ {% block page_js %} - {% if setup_helper.current_operation %} + {% if setup_current_operation or setup_state == 'up-to-date' %} {% endif %} diff --git a/plinth/views.py b/plinth/views.py index 42dbe80ec..b31d5cd36 100644 --- a/plinth/views.py +++ b/plinth/views.py @@ -177,7 +177,13 @@ class SetupView(TemplateView): def get_context_data(self, **kwargs): """Return the context data rendering the template.""" context = super(SetupView, self).get_context_data(**kwargs) - context['setup_helper'] = self.kwargs['setup_helper'] + setup_helper = self.kwargs['setup_helper'] + context['setup_helper'] = setup_helper + + # Reuse the value of setup_state throughout the view for consistency. + context['setup_state'] = setup_helper.get_state() + context['setup_current_operation'] = setup_helper.current_operation + context['package_manager_is_busy'] = package.is_package_manager_busy() return context