~ubuntu-branches/ubuntu/raring/maas/raring

« back to all changes in this revision

Viewing changes to src/maasserver/forms.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Dave Walker (Daviey), Andres Rodriguez, Scott Moser
  • Date: 2012-03-22 10:56:58 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120322105658-cc42wllftxl8qpxm
Tags: 0.1+bzr338+dfsg-0ubuntu1
[ Dave Walker (Daviey) ]
* d/patches/03-txlongpoll-config.patch: Resolve typo error from prior patch.
  - LP: #961031

[ Andres Rodriguez ]
* debian/maas.config: Don't allow reconfigure.
* debian/maas.postinst: Don't allow reconfigure. Run sync/migrate db on
  all upgrades.

[ Scott Moser ]
* add rsylog config for logging node boots (LP: 960149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
    "MACAddressForm",
17
17
    "MAASAndNetworkForm",
18
18
    "UbuntuForm",
 
19
    "UIAdminNodeEditForm",
 
20
    "UINodeEditForm",
19
21
    ]
20
22
 
21
23
from django import forms
40
42
    Node,
41
43
    NODE_AFTER_COMMISSIONING_ACTION,
42
44
    NODE_AFTER_COMMISSIONING_ACTION_CHOICES,
 
45
    UserProfile,
43
46
    )
44
47
 
45
48
 
83
86
            'architecture', 'power_type')
84
87
 
85
88
 
 
89
class UINodeEditForm(ModelForm):
 
90
    after_commissioning_action = forms.ChoiceField(
 
91
        choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
 
92
 
 
93
    class Meta:
 
94
        model = Node
 
95
        fields = ('hostname', 'after_commissioning_action')
 
96
 
 
97
 
 
98
class UIAdminNodeEditForm(ModelForm):
 
99
    after_commissioning_action = forms.ChoiceField(
 
100
        choices=NODE_AFTER_COMMISSIONING_ACTION_CHOICES)
 
101
    owner = forms.ModelChoiceField(
 
102
        queryset=UserProfile.objects.all_users(), required=False)
 
103
 
 
104
    class Meta:
 
105
        model = Node
 
106
        fields = (
 
107
            'hostname', 'after_commissioning_action', 'power_type', 'owner')
 
108
 
 
109
 
86
110
class MACAddressForm(ModelForm):
87
111
    class Meta:
88
112
        model = MACAddress
120
144
                ['One or more MAC Addresses is invalid.'])
121
145
        return valid
122
146
 
 
147
    def clean_mac_addresses(self):
 
148
        data = self.cleaned_data['mac_addresses']
 
149
        for mac in data:
 
150
            if MACAddress.objects.filter(mac_address=mac.lower()).count() > 0:
 
151
                raise ValidationError(
 
152
                    {'mac_addresses': [
 
153
                        'Mac address %s already in use.' % mac]})
 
154
        return data
 
155
 
123
156
    def save(self):
124
157
        node = super(NodeWithMACAddressesForm, self).save()
125
158
        for mac in self.cleaned_data['mac_addresses']:
171
204
        user.save()
172
205
        return user
173
206
 
 
207
    def clean_email(self):
 
208
        """Validate that the supplied email address is unique for the
 
209
        site.
 
210
        """
 
211
        email = self.cleaned_data['email']
 
212
        email_count = User.objects.filter(email__iexact=email).count()
 
213
        if email_count != 0:
 
214
            raise forms.ValidationError(
 
215
                "User with this E-mail address already exists.")
 
216
        return email
 
217
 
174
218
 
175
219
class EditUserForm(UserChangeForm):
176
220
    # Override the default label.