From d9d42b80ca546facf5a6ab9fe3693a7e6f55e231 Mon Sep 17 00:00:00 2001 From: Timur Nurlygayanov Date: Thu, 7 Mar 2013 14:44:41 +0400 Subject: [PATCH] Finished Task: KEERO-117. Added new UI wizard for Create Services Action. --- dashboard/windc/forms.py | 56 ++++++++++++++++++- .../windc/templates/windc/_services_tabs.html | 15 +++-- .../windc/templates/windc/services_tabs.html | 15 ----- dashboard/windc/urls.py | 7 +-- dashboard/windc/views.py | 52 +++++++++++++++-- dashboard/windc/workflows.py | 2 - 6 files changed, 111 insertions(+), 36 deletions(-) delete mode 100644 dashboard/windc/templates/windc/services_tabs.html diff --git a/dashboard/windc/forms.py b/dashboard/windc/forms.py index 80ba327..090e1a3 100644 --- a/dashboard/windc/forms.py +++ b/dashboard/windc/forms.py @@ -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) diff --git a/dashboard/windc/templates/windc/_services_tabs.html b/dashboard/windc/templates/windc/_services_tabs.html index 9839711..a00c4c3 100644 --- a/dashboard/windc/templates/windc/_services_tabs.html +++ b/dashboard/windc/templates/windc/_services_tabs.html @@ -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 %} -

Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}

-
{% csrf_token %} {{ wizard.management_form }} {% if wizard.form.forms %} @@ -17,12 +19,13 @@ {% endif %} {{ wizard.form.forms }}
+{% endblock %} + +{% block modal-footer %} {% if wizard.steps.prev %} {% else %} - {% endif %} -
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/dashboard/windc/templates/windc/services_tabs.html b/dashboard/windc/templates/windc/services_tabs.html deleted file mode 100644 index 8630ff8..0000000 --- a/dashboard/windc/templates/windc/services_tabs.html +++ /dev/null @@ -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 %} -
-
- {{ tab_group.render }} -
-
-{% endblock %} \ No newline at end of file diff --git a/dashboard/windc/urls.py b/dashboard/windc/urls.py index faa54d9..b6ad6b1 100644 --- a/dashboard/windc/urls.py +++ b/dashboard/windc/urls.py @@ -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[^/]+)/$', WinServices.as_view(), name='services'), - url(r'^update$', - Wizard.as_view([WizardFormServiceType, WizardFormConfiguration]), - name='update'), url(r'^(?P[^/]+)/$', WinServices.as_view(), name='service_details') ) diff --git a/dashboard/windc/views.py b/dashboard/windc/views.py index 87595b2..010a249 100644 --- a/dashboard/windc/views.py +++ b/dashboard/windc/views.py @@ -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): diff --git a/dashboard/windc/workflows.py b/dashboard/windc/workflows.py index dcd9b18..5443cb6 100644 --- a/dashboard/windc/workflows.py +++ b/dashboard/windc/workflows.py @@ -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