firstboot: Rename views/urls to be non-numeric

This commit is contained in:
Sunil Mohan Adapa 2016-11-12 12:04:54 +05:30 committed by James Valleroy
parent c37aa0fbd5
commit 56686b7148
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
13 changed files with 40 additions and 37 deletions

View File

@ -25,13 +25,13 @@ is_essential = True
first_boot_steps = [
{
'id': 'firstboot_state0',
'url': 'first_boot:state0',
'id': 'firstboot_welcome',
'url': 'first_boot:welcome',
'order': 0
},
{
'id': 'firstboot_state10',
'url': 'first_boot:state10',
'id': 'firstboot_complete',
'url': 'first_boot:complete',
'order': 10
}
]

View File

@ -22,12 +22,13 @@ URLs for the First Boot module
from django.conf.urls import url
from stronghold.decorators import public
from .views import State0View, state10
from .views import WelcomeView, complete
urlpatterns = [
# Take care of the firstboot middleware when changing URLs
url(r'^firstboot/$', public(State0View.as_view()), name='index'),
url(r'^firstboot/state0/$', public(State0View.as_view()), name='state0'),
url(r'^firstboot/state10/$', state10, name='state10'),
url(r'^firstboot/$', public(WelcomeView.as_view()), name='index'),
url(r'^firstboot/welcome/$', public(WelcomeView.as_view()),
name='welcome'),
url(r'^firstboot/complete/$', complete, name='complete'),
]

View File

@ -23,30 +23,30 @@ from plinth import network
from .middleware import mark_step_done, next_step
class State0View(TemplateView):
class WelcomeView(TemplateView):
"""Show the welcome screen."""
template_name = 'firstboot_state0.html'
template_name = 'firstboot_welcome.html'
def get_context_data(self, **kwargs):
"""Returns the context data for the template."""
context = super(State0View, self).get_context_data(**kwargs)
mark_step_done('firstboot_state0')
context = super(WelcomeView, self).get_context_data(**kwargs)
mark_step_done('firstboot_welcome')
context['next_url'] = next_step()
return context
def state10(request):
"""State 10 is when all firstboot setup is done.
def complete(request):
"""Show summary after all firstboot setup is done.
After viewing this page the firstboot module can't be accessed anymore.
"""
# Make sure that a user exists before finishing firstboot
if User.objects.all():
mark_step_done('firstboot_state10')
mark_step_done('firstboot_complete')
connections = network.get_connection_list()
return render(request, 'firstboot_state10.html',
return render(request, 'firstboot_complete.html',
{'title': _('Setup Complete'),
'connections': connections})

View File

@ -263,7 +263,7 @@ class AddCustomServiceForm(BaseCustomServiceForm):
raise
class State5Form(forms.Form):
class FirstBootForm(forms.Form):
"""Set up freedombox.me pagekite subdomain"""
DOMAIN_APPENDIX = '.freedombox.me'
# Webservice url for domain validation and registration

View File

@ -27,7 +27,7 @@
<h2>{% trans "Setup a freedombox.me subdomain with your voucher" %}</h2>
<p>
{% url 'first_boot:state10' as finish_firstboot_url %}
{% url 'first_boot:complete' as finish_firstboot_url %}
{% blocktrans trimmed %}
<a href="{{ finish_firstboot_url }}">Skip this step</a> if you
do not have a voucher or want to configure PageKite later with a
@ -54,7 +54,7 @@
<button type="submit" class="btn btn-primary">
{% trans "Register" %}
</button>
<a href="{% url 'first_boot:state10' %}" class="btn btn-default"
<a href="{% url 'first_boot:complete' %}" class="btn btn-default"
role="button">
{% trans "Skip Registration" %}
</a>

View File

@ -22,7 +22,7 @@ URLs for the PageKite module
from django.conf.urls import url
from .views import StandardServiceView, CustomServiceView, ConfigurationView, \
DeleteServiceView, index, State5View
DeleteServiceView, index, FirstBootView
urlpatterns = [
url(r'^sys/pagekite/$', index, name='index'),
@ -34,5 +34,6 @@ urlpatterns = [
name='custom-services'),
url(r'^sys/pagekite/services/custom/delete$', DeleteServiceView.as_view(),
name='delete-custom-service'),
url(r'^sys/pagekite/firstboot/$', State5View.as_view(), name='firstboot'),
url(r'^sys/pagekite/firstboot/$', FirstBootView.as_view(),
name='firstboot'),
]

View File

@ -25,7 +25,7 @@ from django.views.generic.edit import FormView
from . import utils
from .forms import ConfigurationForm, StandardServiceForm, \
AddCustomServiceForm, DeleteCustomServiceForm, State5Form
AddCustomServiceForm, DeleteCustomServiceForm, FirstBootForm
from plinth.errors import DomainRegistrationError
from plinth.modules import pagekite
from plinth.modules.first_boot.middleware import mark_step_done
@ -134,15 +134,15 @@ class ConfigurationView(ContextMixin, FormView):
return super(ConfigurationView, self).form_valid(form)
class State5View(FormView):
"""State 5 is the (optional) setup of the Pagekite subdomain."""
template_name = 'firstboot_state5.html'
form_class = State5Form
class FirstBootView(FormView):
"""First boot (optional) setup of the Pagekite subdomain."""
template_name = 'pagekite_firstboot.html'
form_class = FirstBootForm
def get(self, *args, **kwargs):
"""Respond to GET request."""
mark_step_done('pagekite_firstboot')
return super(State5View, self).get(*args, **kwargs)
return super(FirstBootView, self).get(*args, **kwargs)
def form_valid(self, form):
"""Act on valid form submission."""
@ -156,4 +156,4 @@ class State5View(FormView):
message = _('Pagekite setup finished. The HTTP and HTTPS services '
'are activated now.')
messages.success(self.request, message)
return super(State5View, self).form_valid(form)
return super(FirstBootView, self).form_valid(form)

View File

@ -245,8 +245,8 @@ class UserChangePasswordForm(SetPasswordForm):
return user
class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
"""Firstboot state 1: create a new user."""
class FirstBootForm(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
"""User module first boot step: create a new admin user."""
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request')

View File

@ -41,5 +41,6 @@ urlpatterns = [
{'template_name': 'login.html'}, name='login'),
url(r'^accounts/logout/$', auth_views.logout,
{'next_page': reverse_lazy('index')}, name='logout'),
url(r'^users/firstboot/$', public(views.State1View.as_view()), name='firstboot'),
url(r'^users/firstboot/$', public(views.FirstBootView.as_view()),
name='firstboot'),
]

View File

@ -26,7 +26,7 @@ import django.views.generic
from django.utils.translation import ugettext as _, ugettext_lazy
from .forms import CreateUserForm, UserChangePasswordForm, UserUpdateForm, \
State1Form
FirstBootForm
from plinth import actions
from plinth import cfg
from plinth.errors import ActionError
@ -168,10 +168,10 @@ class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
return super(UserChangePassword, self).form_valid(form)
class State1View(django.views.generic.CreateView):
class FirstBootView(django.views.generic.CreateView):
"""Create user account and log the user in."""
template_name = 'firstboot_state1.html'
form_class = State1Form
template_name = 'users_firstboot.html'
form_class = FirstBootForm
success_url = ''
def __init__(self, *args, **kwargs):
@ -181,10 +181,10 @@ class State1View(django.views.generic.CreateView):
mark_step_done('users_firstboot')
self.success_url = next_step()
return super(State1View, self).__init__(*args, **kwargs)
return super(FirstBootView, self).__init__(*args, **kwargs)
def get_form_kwargs(self):
"""Make request available to the form (to insert messages)"""
kwargs = super(State1View, self).get_form_kwargs()
kwargs = super(FirstBootView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs