Files
solum-dashboard/solumdashboard/languagepacks/forms.py
Swati Dewan 283c142d00 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
2016-08-17 22:42:23 +05:30

72 lines
2.4 KiB
Python

# 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