From 3af82ab14e7ff8e98050f68510a6c97abc2329ac Mon Sep 17 00:00:00 2001 From: fonfon Date: Mon, 26 Dec 2016 18:05:20 +0100 Subject: [PATCH] Firstboot: minor variable renaming and cleanup --- plinth/modules/first_boot/__init__.py | 7 +++++-- plinth/modules/first_boot/middleware.py | 10 +++++----- .../first_boot/templatetags/firstboot_extras.py | 6 +++--- plinth/modules/help/templates/help_base.html | 8 ++++---- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/plinth/modules/first_boot/__init__.py b/plinth/modules/first_boot/__init__.py index b0cbb20e0..b490e1b97 100644 --- a/plinth/modules/first_boot/__init__.py +++ b/plinth/modules/first_boot/__init__.py @@ -106,7 +106,7 @@ def mark_step_done(id): kvstore.set(id, 1) if not next_step_or_none(): - kvstore.set('setup_state', 1) + set_completed() def is_completed(): @@ -115,9 +115,12 @@ def is_completed(): global _is_completed if _is_completed is None: + # TODO + # Rename setup_state to 'firstboot_completed', + # taking care of the existing kvstore variable name. _is_completed = kvstore.get_default('setup_state', 0) - return _is_completed + return bool(_is_completed) def set_completed(): diff --git a/plinth/modules/first_boot/middleware.py b/plinth/modules/first_boot/middleware.py index 625a6315a..9e47fad00 100644 --- a/plinth/modules/first_boot/middleware.py +++ b/plinth/modules/first_boot/middleware.py @@ -48,20 +48,20 @@ class FirstBootMiddleware(object): if user_requests_help: return - state = first_boot.is_completed() + firstboot_completed = first_boot.is_completed() # Migrate from old settings variable - if state == 0: + if not firstboot_completed: old_state = kvstore.get_default('firstboot_state', 0) if old_state == 10: - state = 1 + firstboot_completed = True first_boot.set_completed() user_requests_firstboot = first_boot.is_firstboot_url(request.path) # Redirect to first boot if requesting normal page and first # boot is not complete. - if state == 0 and not user_requests_firstboot: + if not firstboot_completed and not user_requests_firstboot: next_step = first_boot.next_step_or_none() if next_step: return HttpResponseRedirect(reverse(next_step)) @@ -71,5 +71,5 @@ class FirstBootMiddleware(object): # Redirect to index page if request firstboot after it is # finished. - if state == 1 and user_requests_firstboot: + if firstboot_completed and user_requests_firstboot: return HttpResponseRedirect(reverse('index')) diff --git a/plinth/modules/first_boot/templatetags/firstboot_extras.py b/plinth/modules/first_boot/templatetags/firstboot_extras.py index eac4f7c07..4b2c81d95 100644 --- a/plinth/modules/first_boot/templatetags/firstboot_extras.py +++ b/plinth/modules/first_boot/templatetags/firstboot_extras.py @@ -21,13 +21,13 @@ Template tags for first boot module. from django import template +from plinth.modules import first_boot from plinth import kvstore register = template.Library() @register.simple_tag -def firstboot_is_finished(): +def firstboot_is_completed(): """Return whether firstboot process is completed.""" - state = kvstore.get_default('setup_state', 0) - return state == 1 + return first_boot.is_completed() diff --git a/plinth/modules/help/templates/help_base.html b/plinth/modules/help/templates/help_base.html index 5217c2542..b9613a59a 100644 --- a/plinth/modules/help/templates/help_base.html +++ b/plinth/modules/help/templates/help_base.html @@ -26,8 +26,8 @@ {# Adapt mainmenu-links during firstboot #} {% block mainmenu_left %} - {% firstboot_is_finished as firstboot_finished %} - {% if not firstboot_finished %} + {% firstboot_is_completed as firstboot_completed %} + {% if not firstboot_completed %}