~ubuntu-branches/ubuntu/precise/horizon/precise-updates

« back to all changes in this revision

Viewing changes to horizon/horizon/dashboards/nova/keypairs/views.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-09 16:18:55 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20111209161855-nguyenpghx2o2lqy
Tags: 2012.1~e2~20111209.1104-0ubuntu1
* New upstream release.
* Refreshed patches.
* debian/docs: Removed README

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
LOG = logging.getLogger(__name__)
39
39
 
40
40
 
 
41
# FIXME(gabriel): There's a very obvious pattern to these views.
 
42
#                 This is a perfect candidate for a class-based view.
 
43
 
41
44
@login_required
42
45
def index(request):
43
46
    delete_form, handled = DeleteKeypair.maybe_handle(request)
44
 
 
45
47
    if handled:
46
48
        return handled
47
49
 
48
 
    create_form = CreateKeypair()
49
 
    import_form = ImportKeypair()
50
 
 
51
50
    try:
52
51
        keypairs = api.keypair_list(request)
53
52
    except novaclient_exceptions.ClientException, e:
55
54
        LOG.exception("ClientException in keypair index")
56
55
        messages.error(request, _('Error fetching keypairs: %s') % e.message)
57
56
 
58
 
    return shortcuts.render(request,
59
 
                            'nova/keypairs/index.html', {
60
 
                                'keypairs': keypairs,
61
 
                                'create_form': create_form,
62
 
                                'import_form': import_form,
63
 
                                'delete_form': delete_form})
 
57
    context = {'keypairs': keypairs, 'delete_form': delete_form}
 
58
 
 
59
    if request.is_ajax():
 
60
        template = 'nova/keypairs/_list.html'
 
61
        context['hide'] = True
 
62
    else:
 
63
        template = 'nova/keypairs/index.html'
 
64
 
 
65
    return shortcuts.render(request, template, context)
64
66
 
65
67
 
66
68
@login_required
69
71
    if handled:
70
72
        return handled
71
73
 
72
 
    return shortcuts.render(request,
73
 
                            'nova/keypairs/create.html', {
74
 
                                'create_form': form})
 
74
    context = {'form': form}
 
75
 
 
76
    if request.is_ajax():
 
77
        template = 'nova/keypairs/_create.html'
 
78
        context['hide'] = True
 
79
    else:
 
80
        template = 'nova/keypairs/create.html'
 
81
 
 
82
    return shortcuts.render(request, template, context)
75
83
 
76
84
 
77
85
@login_required
80
88
    if handled:
81
89
        return handled
82
90
 
83
 
    return shortcuts.render(request,
84
 
                            'nova/keypairs/import.html', {
85
 
                                'import_form': form,
86
 
                                'create_form': form})
 
91
    context = {'form': form}
 
92
 
 
93
    if request.is_ajax():
 
94
        template = 'nova/keypairs/_import.html'
 
95
        context['hide'] = True
 
96
    else:
 
97
        template = 'nova/keypairs/import.html'
 
98
 
 
99
    return shortcuts.render(request, template, context)