~ubuntu-branches/ubuntu/vivid/horizon/vivid-proposed

« back to all changes in this revision

Viewing changes to horizon/forms/views.py

  • Committer: Package Import Robot
  • Author(s): Corey Bryant, Chuck Short, Corey Bryant, James Page
  • Date: 2015-01-05 16:42:06 UTC
  • mfrom: (0.9.1) (1.2.5)
  • Revision ID: package-import@ubuntu.com-20150105164206-zrt2q64h4weugkur
Tags: 1:2015.1~b1-0ubuntu1
[ Chuck Short ]
* Open for Kilo.
* d/control: Update bzr branches 
* d/patches/embedded-xstatic.patch: Refreshed
* d/patches/add-juju-environment-download.patch: Temporarily disabled.

[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/watch: Update uversionmangle for kilo beta naming.
* d/control: Bumped Standards-Version to 3.9.6.

[ James Page ]
* d/bundle-xstatic.sh: Tweak grep to be case insensitive.
* d/p/add-juju-environment-download.patch: Rebase for kilo-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
import json
16
16
import os
17
17
 
 
18
from django.conf import settings
18
19
from django import http
19
20
from django.utils.translation import ugettext_lazy as _
20
21
from django.views import generic
25
26
ADD_TO_FIELD_HEADER = "HTTP_X_HORIZON_ADD_TO_FIELD"
26
27
 
27
28
 
 
29
class ModalBackdropMixin(object):
 
30
    """This mixin class is to be used for together with ModalFormView and
 
31
    WorkflowView classes to augment them with modal_backdrop context data.
 
32
 
 
33
    .. attribute: modal_backdrop (optional)
 
34
 
 
35
        The appearance and behavior of backdrop under the modal element.
 
36
        Possible options are:
 
37
        * 'true' - show backdrop element outside the modal, close the modal
 
38
        after clicking on backdrop (the default one);
 
39
        * 'false' - do not show backdrop element, do not close the modal after
 
40
        clicking outside of it;
 
41
        * 'static' - show backdrop element outside the modal, do not close
 
42
        the modal after clicking on backdrop.
 
43
    """
 
44
    modal_backdrop = 'static'
 
45
 
 
46
    def __init__(self):
 
47
        super(ModalBackdropMixin, self).__init__()
 
48
        config = getattr(settings, 'HORIZON_CONFIG', {})
 
49
        if 'modal_backdrop' in config:
 
50
            self.modal_backdrop = config['modal_backdrop']
 
51
 
 
52
    def get_context_data(self, **kwargs):
 
53
        context = super(ModalBackdropMixin, self).get_context_data(**kwargs)
 
54
        context['modal_backdrop'] = self.modal_backdrop
 
55
        return context
 
56
 
 
57
 
28
58
class ModalFormMixin(object):
29
59
    def get_template_names(self):
30
60
        if self.request.is_ajax():
47
77
        return context
48
78
 
49
79
 
50
 
class ModalFormView(ModalFormMixin, generic.FormView):
 
80
class ModalFormView(ModalBackdropMixin, ModalFormMixin, generic.FormView):
51
81
    """The main view class from which all views which handle forms in Horizon
52
82
    should inherit. It takes care of all details with processing
53
83
    :class:`~horizon.forms.base.SelfHandlingForm` classes, and modal concerns
61
91
    /en/dev/ref/class-based-views/generic-editing/#formview>`_ class for
62
92
    more details.
63
93
 
 
94
    .. attribute: modal_id (recommended)
 
95
 
 
96
        The HTML element id of this modal.
 
97
 
 
98
    .. attribute: modal_header (recommended)
 
99
 
 
100
        The title of this modal.
 
101
 
 
102
    .. attribute: form_id (recommended)
 
103
 
 
104
        The HTML element id of the form in this modal.
 
105
 
 
106
    .. attribute: submit_url (required)
 
107
 
 
108
        The url for a submit action.
 
109
 
64
110
    .. attribute: submit_label (optional)
65
111
 
66
112
        The label for the submit button. This label defaults to ``Submit``.
78
124
        if ommitted. Note that the cancel_url redirect is nullified when
79
125
        shown in a modal dialog.
80
126
    """
 
127
 
 
128
    modal_id = None
 
129
    modal_header = ""
 
130
    form_id = None
 
131
    submit_url = None
81
132
    submit_label = _("Submit")
82
133
    cancel_label = _("Cancel")
83
134
    cancel_url = None
84
135
 
85
136
    def get_context_data(self, **kwargs):
86
137
        context = super(ModalFormView, self).get_context_data(**kwargs)
 
138
        context['modal_id'] = self.modal_id
 
139
        context['modal_header'] = self.modal_header
 
140
        context['form_id'] = self.form_id
 
141
        context['submit_url'] = self.submit_url
87
142
        context['submit_label'] = self.submit_label
88
143
        context['cancel_label'] = self.cancel_label
89
144
        context['cancel_url'] = self.get_cancel_url()