Firstboot: minor variable renaming and cleanup

This commit is contained in:
fonfon 2016-12-26 18:05:20 +01:00 committed by James Valleroy
parent bf6bcfcf38
commit 3af82ab14e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 17 additions and 14 deletions

View File

@ -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():

View File

@ -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'))

View File

@ -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()

View File

@ -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 %}
<span class="navbar-brand">
<img src="{% static 'theme/img/freedombox-logo-32px.png' %}"
@ -46,8 +46,8 @@
{% block mainmenu_right %}
{% firstboot_is_finished as firstboot_finished %}
{% if not firstboot_finished %}
{% firstboot_is_completed as firstboot_completed %}
{% if not firstboot_completed %}
{% include "firstboot_navbar.html" %}
{% else %}
{{ block.super }}