Add the languagepack create functionality to the dashboard

The dashboard plugin currently does not support the option to create a
new languagepack. This patch adds this option to the dashboard plugin.

Also, here is a link to a screenchot of what the form for creation looks
like: http://pasteboard.co/4hlr2GO3z.png, and what the page after
creation of the languagepack looks like:
http://pasteboard.co/I0HuPcLh.png

Change-Id: I3c53ae0cdfcbd4bb8f99d9003ccfebc5b3e5c7ee
Closes-Bug: #1602874
This commit is contained in:
Swati Dewan
2016-07-15 01:17:27 +05:30
parent fcbc297a13
commit 283c142d00
6 changed files with 112 additions and 2 deletions

View File

@@ -0,0 +1,71 @@
# Copyright (c) 2014 Rackspace Hosting.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import logging
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms
from horizon import messages
from solumclient.common import yamlutils
from solumdashboard.api.client import client as solumclient
LOG = logging.getLogger(__name__)
class CreateForm(forms.SelfHandlingForm):
source_uri = forms.CharField(label=_("Source URI"))
name = forms.CharField(label=_("Languagepack Name"))
description = forms.CharField(label=_("Description"), required=False)
param_file = forms.FileField(label=_("Parameter File"),
required=False)
lp_metadata = forms.FileField(label=_("Languagepack Metadata File"),
required=False)
def handle(self, request, data):
LOG.info('CreateLanguagepack %s' % data)
solum = solumclient(request)
param_data = {}
if data['param_file']:
inf = data['param_file'].read()
param_data = yamlutils.load(inf)
lp_metadata = None
if data['lp_metadata']:
lp_metadata = json.dumps(json.load(data['lp_metadata']))
try:
solum.languagepacks.create(
name=data['name'], source_uri=data['source_uri'],
lp_metadata=lp_metadata, lp_params=param_data,
description=data['description'])
message = _(
'Languagepack %s was successfully created.') % data['name']
messages.success(request, message)
except Exception:
redirect = reverse('horizon:solum:languagepacks:index')
exceptions.handle(self.request,
_('Unable to create languagepack.'),
redirect=redirect)
return True

View File

@@ -48,6 +48,13 @@ class DeleteLanguagepack(tables.DeleteAction):
solum.languagepacks.delete(lp_id=languagepack_id) solum.languagepacks.delete(lp_id=languagepack_id)
class CreateLanguagepack(tables.LinkAction):
name = "create"
verbose_name = _("New Languagepack")
url = "horizon:solum:languagepacks:create"
classes = ("btn-launch", "ajax-modal")
class LanguagepacksTable(tables.DataTable): class LanguagepacksTable(tables.DataTable):
uuid = tables.Column("uuid", verbose_name=_("UUID"), uuid = tables.Column("uuid", verbose_name=_("UUID"),
link=("horizon:solum:languagepacks:detail")) link=("horizon:solum:languagepacks:detail"))
@@ -62,5 +69,5 @@ class LanguagepacksTable(tables.DataTable):
class Meta: class Meta:
name = "languagepacks" name = "languagepacks"
verbose_name = _("Languagepacks") verbose_name = _("Languagepacks")
table_actions = (DeleteLanguagepack,) table_actions = (CreateLanguagepack, DeleteLanguagepack)
row_actions = (DeleteLanguagepack,) row_actions = (DeleteLanguagepack,)

View File

@@ -29,5 +29,6 @@ urlpatterns = patterns(
url(r'^$', views.IndexView.as_view(), name='index'), url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^$', views.IndexView.as_view(), name='languagepacks'), url(r'^$', views.IndexView.as_view(), name='languagepacks'),
url(r'^detail/(?P<languagepack_id>[^/]+)$', url(r'^detail/(?P<languagepack_id>[^/]+)$',
views.DetailView.as_view(), name='detail') views.DetailView.as_view(), name='detail'),
url(r'^create$', views.CreateView.as_view(), name='create')
) )

View File

@@ -13,17 +13,20 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import json import json
from horizon import exceptions from horizon import exceptions
from horizon import forms
from horizon import tables from horizon import tables
from horizon import views from horizon import views
from solumclient.v1 import languagepack as cli_lp from solumclient.v1 import languagepack as cli_lp
from solumdashboard.api.client import client as solumclient from solumdashboard.api.client import client as solumclient
from solumdashboard.languagepacks import forms as lp_forms
from solumdashboard.languagepacks import tables as lp_tables from solumdashboard.languagepacks import tables as lp_tables
@@ -71,3 +74,12 @@ class DetailView(views.HorizonTemplateView):
log.swift_path = log.location log.swift_path = log.location
return languagepack, loglist return languagepack, loglist
class CreateView(forms.ModalFormView):
form_class = lp_forms.CreateForm
template_name = 'languagepacks/create.html'
modal_header = _("Create Languagepack")
page_title = _("Create Languagepack")
submit_url = reverse_lazy("horizon:solum:languagepacks:create")
success_url = reverse_lazy("horizon:solum:languagepacks:index")

View File

@@ -0,0 +1,12 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% block form_attrs %}enctype="multipart/form-data"{% endblock %}
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>
{% trans "Enter the details for the languagepack." %}
</p>
{% endblock %}

View File

@@ -0,0 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Create Languagepack" %}{% endblock %}
{% block main %}
{% include 'languagepacks/_create.html' %}
{% endblock %}