~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/forms.py

  • Committer: Greg Lutostanski
  • Date: 2014-06-02 17:15:15 UTC
  • Revision ID: gregory.lutostanski@canonical.com-20140602171515-imbicaxmaxxmhz39
 - Fix NodeForm's is_valid() method so that it uses Django's way of setting
   errors on forms instead of putting text in self.errors['architecture']
   (LP: #1301465)
 - Change BootMethods to return their own IReader per-request, update method
   names to reflect new usage. (LP: #1315154)
 - Return early and stop the DHCP server when the list of managed interfaces
   of the nodegroup is empty. (LP: #1324944)
 - Fix invalid attribute references in the VirshSSH class. Added more test
   for the VirshSSH class. (LP: #1324966)

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
BLANK_CHOICE = ('', '-------')
119
119
 
120
120
 
 
121
def set_form_error(form, field_name, error_value):
 
122
    """Set an error on a form's field.
 
123
 
 
124
    This utility method encapsulates Django's arguably awkward way
 
125
    of settings errors inside a form's clean()/is_valid() method.  This
 
126
    method will override any previously-registered error for 'field_name'.
 
127
    """
 
128
    # Hey Django devs, this is a crap API to set errors.
 
129
    form.errors[field_name] = form.error_class([error_value])
 
130
 
 
131
 
121
132
def remove_None_values(data):
122
133
    """Return a new dictionary without the keys corresponding to None values.
123
134
    """
249
260
    def is_valid(self):
250
261
        is_valid = super(NodeForm, self).is_valid()
251
262
        if len(list_all_usable_architectures()) == 0:
252
 
            self.errors['architecture'] = (
253
 
                [NO_ARCHITECTURES_AVAILABLE])
 
263
            set_form_error(
 
264
                self, "architecture", NO_ARCHITECTURES_AVAILABLE)
254
265
            is_valid = False
255
266
        return is_valid
256
267
 
420
431
            try:
421
432
                get_power_types([self._get_nodegroup()])
422
433
            except ClusterUnavailable as e:
423
 
                # Hey Django devs, this is a crap API to set errors.
424
 
                self._errors["power_type"] = self.error_class(
425
 
                    [CLUSTER_NOT_AVAILABLE + e.args[0]])
 
434
                set_form_error(
 
435
                    self, "power_type", CLUSTER_NOT_AVAILABLE + e.args[0])
426
436
        # If power_type is not set and power_parameters_skip_check is not
427
437
        # on, reset power_parameters (set it to the empty string).
428
438
        no_power_type = cleaned_data.get('power_type', '') == ''