~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/forms_settings.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
"""Configuration items definition and utilities."""
13
13
 
14
14
__metaclass__ = type
15
15
__all__ = [
16
 
    'compose_invalid_choice_text',
17
16
    'CONFIG_ITEMS',
18
17
    'CONFIG_ITEMS_KEYS',
19
18
    'get_config_field',
25
24
 
26
25
from django import forms
27
26
from maasserver.enum import (
 
27
    COMMISSIONING_DISTRO_SERIES_CHOICES,
28
28
    DISTRO_SERIES,
29
29
    DISTRO_SERIES_CHOICES,
30
 
    NODE_AFTER_COMMISSIONING_ACTION,
31
 
    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
32
 
    )
33
 
 
34
 
 
35
 
def compose_invalid_choice_text(choice_of_what, valid_choices):
36
 
    """Compose an "invalid choice" string for form error messages.
37
 
 
38
 
    This returns a template string that is intended to be used as the
39
 
    argument to the 'error_messages' parameter in a Django form.
40
 
 
41
 
    :param choice_of_what: The name for what the selected item is supposed
42
 
        to be, to be inserted into the error string.
43
 
    :type choice_of_what: unicode
44
 
    :param valid_choices: Valid choices, in Django choices format:
45
 
        (name, value).
46
 
    :type valid_choices: sequence
47
 
    """
48
 
    return "%s is not a valid %s.  It should be one of: %s." % (
49
 
        "%(value)s",
50
 
        choice_of_what,
51
 
        ", ".join(name for name, value in valid_choices),
52
 
    )
 
30
    )
 
31
from maasserver.utils.forms import compose_invalid_choice_text
53
32
 
54
33
 
55
34
INVALID_URL_MESSAGE = "Enter a valid url (e.g. http://host.example.com)."
60
39
 
61
40
 
62
41
CONFIG_ITEMS = {
63
 
    'after_commissioning': {
64
 
        'default': NODE_AFTER_COMMISSIONING_ACTION.DEFAULT,
65
 
        'form': forms.ChoiceField,
66
 
        'form_kwargs': {
67
 
            'choices': NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
68
 
            'label': "After commissioning action"
69
 
        }
70
 
    },
71
42
    'check_compatibility': {
72
43
        'default': False,
73
44
        'form': forms.BooleanField,
184
155
        }
185
156
    },
186
157
    'default_distro_series': {
187
 
        'default': DISTRO_SERIES.precise,
 
158
        'default': DISTRO_SERIES.trusty,
188
159
        'form': forms.ChoiceField,
189
160
        'form_kwargs': {
190
161
            'label': "Default distro series used for deployment",
195
166
        }
196
167
    },
197
168
    'commissioning_distro_series': {
198
 
        'default': DISTRO_SERIES.precise,
 
169
        'default': DISTRO_SERIES.trusty,
199
170
        'form': forms.ChoiceField,
200
171
        'form_kwargs': {
201
172
            'label': "Default distro series used for commissioning",
202
 
            'choices': DISTRO_SERIES_CHOICES,
 
173
            'choices': COMMISSIONING_DISTRO_SERIES_CHOICES,
203
174
            'required': False,
204
175
            'error_messages': {
205
176
                'invalid_choice': INVALID_DISTRO_SERIES_MESSAGE},
272
243
        form_details = config_details['form_kwargs']
273
244
        doc.append("- " + config_name + ": " + form_details['label'] + ". ")
274
245
        # Append help text if present.
275
 
        help_text = form_details.get('help_text', "")
276
 
        doc.append(help_text)
 
246
        help_text = form_details.get('help_text')
 
247
        if help_text is not None:
 
248
            doc.append(help_text.strip())
277
249
        # Append list of possible choices if present.
278
250
        choices = form_details.get('choices')
279
251
        if choices is not None: