~ubuntu-branches/ubuntu/utopic/horizon/utopic-updates

« back to all changes in this revision

Viewing changes to openstack_dashboard/dashboards/admin/flavors/forms.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chris Johnston, James Page
  • Date: 2014-10-03 17:54:18 UTC
  • mfrom: (0.4.1) (1.1.44) (70.1.2 utopic)
  • Revision ID: package-import@ubuntu.com-20141003175418-1jomx0azdvnl5fxz
Tags: 1:2014.2~rc1-0ubuntu1
[ Chris Johnston ]
* d/theme/css/ubuntu.css: Fix Ubuntu theme for Instances "more" dropdown
  (LP: #1308651).

[ James Page ]
* New upstream release candidate:
  - d/p/*: Refresh.
* d/watch: Use tarballs.openstack.org for upstream releases. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
# not use this file except in compliance with the License. You may obtain
 
3
# a copy of the License at
 
4
#
 
5
#      http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
# Unless required by applicable law or agreed to in writing, software
 
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
# License for the specific language governing permissions and limitations
 
11
# under the License.
 
12
 
 
13
 
 
14
import json
 
15
 
 
16
from django.utils.translation import ugettext_lazy as _
 
17
 
 
18
from horizon import exceptions
 
19
from horizon import forms
 
20
from horizon import messages
 
21
 
 
22
from openstack_dashboard import api
 
23
 
 
24
 
 
25
class UpdateMetadataForm(forms.SelfHandlingForm):
 
26
 
 
27
    def handle(self, request, data):
 
28
        id = self.initial['id']
 
29
        old_metadata = self.initial['metadata']
 
30
 
 
31
        try:
 
32
            new_metadata = json.loads(self.data['metadata'])
 
33
 
 
34
            metadata = dict(
 
35
                (item['key'], str(item['value']))
 
36
                for item in new_metadata
 
37
            )
 
38
            api.nova.flavor_extra_set(request, id, metadata)
 
39
 
 
40
            remove_keys = [key for key in old_metadata if key not in metadata]
 
41
 
 
42
            api.nova.flavor_extra_delete(request, id, remove_keys)
 
43
 
 
44
            message = _('Metadata successfully updated.')
 
45
            messages.success(request, message)
 
46
        except Exception:
 
47
            exceptions.handle(request,
 
48
                              _('Unable to update the flavor metadata.'))
 
49
            return False
 
50
        return True