Finished Task: KEERO-117. Added new UI wizard for Create Services Action.

This commit is contained in:
Timur Nurlygayanov 2013-03-07 14:44:41 +04:00
parent e9a33eb4b1
commit d9d42b80ca
6 changed files with 111 additions and 36 deletions

View File

@ -36,14 +36,64 @@ LOG = logging.getLogger(__name__)
class WizardFormServiceType(forms.Form):
_type = forms.ChoiceField(label=_("Service Type"))
service = forms.ChoiceField(label=_("Service Type"),
choices=[
('active directory', 'Active Directory'),
('iis', 'Internet Information Services')
],
initial = 'Please, select the type of service...')
class WizardFormConfiguration(forms.Form):
subject = forms.CharField(max_length=100)
sender = forms.CharField(max_length=1)
"The functions for this class will dynamically create in views.py"
pass
class WizardFormADConfiguration(forms.Form):
dc_name = forms.CharField(label=_("Domain Name"),
required=False)
dc_count = forms.IntegerField(label=_("Instances Count"),
required=True,
min_value=1,
max_value=100,
initial=1)
adm_password = forms.CharField(widget=forms.PasswordInput,
label=_("Administrator password"), required=False)
recovery_password = forms.CharField(widget=forms.PasswordInput,
label=_("Recovery password"), required=False)
def handle(self, request, data):
message = "Test"
messages.success(request, message)
LOG.critical('^^^^^^^^^^^^^^^^^^^^^')
class WizardFormIISConfiguration(forms.Form):
iis_name = forms.CharField(label=_("IIS Server Name"),
required=False)
adm_password = forms.CharField(widget=forms.PasswordInput,
label=_("Administrator password"), required=False)
iis_count = forms.IntegerField(label=_("IIS Servers Count"),
required=True,
min_value=1,
max_value=100,
initial=1)
iis_domain = forms.CharField(label=_("Member of the Domain"),
required=False)
domain_user_name = forms.CharField(label=_("Domain User Name"),
required=False)
domain_user_password = forms.CharField(widget=forms.PasswordInput,
label=_("Domain User Password"), required=False)
class UpdateWinDC(forms.SelfHandlingForm):
tenant_id = forms.CharField(widget=forms.HiddenInput)
data_center = forms.CharField(widget=forms.HiddenInput)

View File

@ -1,10 +1,12 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load i18n horizon humanize %}
{% block form_action %}{% url horizon:project:windc:create %}?{{ request.POST.urlencode }}{% endblock %}
{% block modal_id %}create_service{% endblock %}
{% block modal-header %}{% trans "Create Service" %}{% endblock %}
{% block modal-body %}
<p>Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
<form action="" method="post">{% csrf_token %}
<table>
{{ wizard.management_form }}
{% if wizard.form.forms %}
@ -17,12 +19,13 @@
{% endif %}
{{ wizard.form.forms }}
</table>
{% endblock %}
{% block modal-footer %}
{% if wizard.steps.prev %}
<button name="wizard_goto_step" class="btn btn-small" type="submit" value="{{ wizard.steps.prev }}">{% trans "Back" %}</button>
<input type="submit" class="btn btn-primary pull-right" value="{% trans 'Deploy' %}"/>
{% else %}
<button name="wizard_goto_step" class="btn btn-small" type="submit" value="{{ wizard.steps.next }}">{% trans "Next" %}</button>
<input type="submit" class="btn btn-primary pull-right" value="{% trans 'Deploy' %}"/>
{% endif %}
</form>
{% endblock %}
{% endblock %}

View File

@ -1,15 +0,0 @@
{% extends 'base.html' %}
{% load i18n sizeformat %}
{% block title %}{% trans "Services" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title="Domain Controller Services" %}
{% endblock page_header %}
{% block main %}
<div class="row-fluid">
<div class="span12">
{{ tab_group.render }}
</div>
</div>
{% endblock %}

View File

@ -29,13 +29,12 @@ VIEW_MOD = 'openstack_dashboard.dashboards.project.windc.views'
urlpatterns = patterns(VIEW_MOD,
url(r'^$', IndexView.as_view(), name='index'),
url(r'^create$', CreateWinServiceView.as_view(), name='create'),
url(r'^create$',
Wizard.as_view([WizardFormServiceType, WizardFormConfiguration]),
name='create'),
url(r'^create_dc$', CreateWinDCView.as_view(), name='create_dc'),
url(r'^(?P<data_center_id>[^/]+)/$', WinServices.as_view(),
name='services'),
url(r'^update$',
Wizard.as_view([WizardFormServiceType, WizardFormConfiguration]),
name='update'),
url(r'^(?P<service_id>[^/]+)/$', WinServices.as_view(),
name='service_details')
)

View File

@ -22,6 +22,7 @@
Views for managing instances.
"""
import logging
import re
from django import http
from django import shortcuts
@ -41,9 +42,12 @@ from horizon.forms.views import ModalFormMixin
from openstack_dashboard import api
from .tables import WinDCTable, WinServicesTable
from .workflows import CreateWinService, CreateWinDC
from .forms import WizardFormServiceType, WizardFormConfiguration
from .forms import (WizardFormServiceType, WizardFormConfiguration,
WizardFormADConfiguration, WizardFormIISConfiguration)
import pdb
from horizon import messages
from django.http import HttpResponseRedirect
LOG = logging.getLogger(__name__)
@ -51,14 +55,50 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
template_name = 'project/windc/services_tabs.html'
def done(self, form_list, **kwargs):
#do_something_with_the_form_data(form_list)
return HttpResponseRedirect('/')
link = self.request.__dict__['META']['HTTP_REFERER']
datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1]
url = "/project/windc/%s/" % datacenter_id
service_type = form_list[0].data.get('0-service', '')
parameters = {}
if service_type == 'active directory':
parameters['dc_name'] = str(form_list[1].data.get('1-dc_name', 'noname'))
parameters['adm_password'] = str(form_list[1].data.get('1-adm_password', ''))
parameters['dc_count'] = int(form_list[1].data.get('1-dc_count', 1))
parameters['recovery_password'] = str(form_list[1].data.get('1-recovery_password', ''))
elif service_type == 'iis':
parameters['iis_name'] = str(form_list[1].data.get('1-iis_name', 'noname'))
parameters['adm_password'] = str(form_list[1].data.get('1-adm_password', ''))
parameters['iis_count'] = int(form_list[1].data.get('1-iis_count', 1))
parameters['iis_domain'] = str(form_list[1].data.get('1-iis_domain', ''))
parameters['domain_user_name'] = str(form_list[1].data.get('1-domain_user_name', ''))
parameters['domain_user_password'] = str(form_list[1].data.get('1-domain_user_password', ''))
service = api.windc.services_create(self.request,
datacenter_id,
parameters)
message = "The %s service successfully created." % service_type
messages.success(self.request, message)
return HttpResponseRedirect(url)
def get_form(self, step=None, data=None, files=None):
form = super(Wizard, self).get_form(step, data, files)
print step
print data
LOG.debug("********" + str(self.form_list))
if data:
service_type = data.get('0-service', '')
if service_type == 'active directory':
self.form_list['1'] = WizardFormADConfiguration
elif service_type == 'iis':
self.form_list['1'] = WizardFormIISConfiguration
return form
def get_form_step_data(self, form):
LOG.debug(form.data)
return form.data
class IndexView(tables.DataTableView):

View File

@ -172,10 +172,8 @@ class CreateWinService(workflows.Workflow):
def handle(self, request, context):
try:
############## FIX ME:
link = request.__dict__['META']['HTTP_REFERER']
datacenter_id = re.search('windc/(\S+)', link).group(0)[6:-1]
##############
self.success_url = "/project/windc/%s/" % datacenter_id