first_boot: Fix various issues and refactor

- Fix major regression so that steps can submitted multiple times in
  case of errors.

- Don't serve the welcome page (and other pages) only once.  Show it
  until action is an taken.  This does not apply to the final step.

- Eliminate all coupling of one first boot step on another.

- Move first boot helper methods to __init__.py instead of middleware as
  it is more generic than middleware.

- Implement caching the first boot state to avoid an SQL query on every
  page load.  The down side is that if first boot state is modified in
  the backend DB outside Plinth, Plinth will need to be restarted to
  catch the modified value.

- Mark some methods as private.

- Refactor middleware code for slightly more simplicity.

- Don't show sidebar in pagekite first boot step.  Set width like other
  pages.
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2016-12-04 15:24:48 -05:00
1 parent 6cce89ed68
commit f457a0bdd3
9 files changed
+227 -157

No files matched your search

+13 -12
View File
@@ -28,9 +28,8 @@ from django.utils.translation import ugettext as _, ugettext_lazy
from .forms import CreateUserForm, UserChangePasswordForm, UserUpdateForm, \
FirstBootForm
from plinth import actions
from plinth import cfg
from plinth.errors import ActionError
from plinth.modules.first_boot.middleware import mark_step_done, next_step
from plinth.modules import first_boot
subsubmenu = [{'url': reverse_lazy('users:index'),
'text': ugettext_lazy('Users')},
@@ -171,20 +170,22 @@ class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
class FirstBootView(django.views.generic.CreateView):
"""Create user account and log the user in."""
template_name = 'users_firstboot.html'
form_class = FirstBootForm
success_url = ''
def __init__(self, *args, **kwargs):
"""Initialize the view object."""
if not cfg.danube_edition:
mark_step_done('pagekite_firstboot')
mark_step_done('users_firstboot')
self.success_url = next_step()
return super(FirstBootView, self).__init__(*args, **kwargs)
def get_form_kwargs(self):
"""Make request available to the form (to insert messages)"""
kwargs = super(FirstBootView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs
def form_valid(self, form):
"""Mark this first boot step as completed and save form."""
if User.objects.all():
first_boot.mark_step_done('users_firstboot')
return super().form_valid(form)
def get_success_url(self):
"""Return the next first boot step after valid form submission."""
return reverse(first_boot.next_step())