Revision 5ae8216a

b/snf-astakos-app/astakos/im/forms.py
200 200
        return user
201 201

  
202 202

  
203
class InvitedLocalUserCreationForm(LocalUserCreationForm):
204
    """
205
    Extends the LocalUserCreationForm: email is readonly.
206
    """
207
    class Meta:
208
        model = AstakosUser
209
        fields = ("email", "first_name", "last_name", "has_signed_terms")
210

  
211
    def __init__(self, *args, **kwargs):
212
        """
213
        Changes the order of fields, and removes the username field.
214
        """
215
        super(InvitedLocalUserCreationForm, self).__init__(*args, **kwargs)
216

  
217
        #set readonly form fields
218
        ro = ('email', 'username',)
219
        for f in ro:
220
            self.fields[f].widget.attrs['readonly'] = True
221

  
222
    def save(self, commit=True, **kwargs):
223
        user = super(InvitedLocalUserCreationForm, self).save(commit=False,
224
                                                              **kwargs)
225
        user.set_invitations_level()
226
        user.email_verified = True
227
        if commit:
228
            user.save(**kwargs)
229
        return user
230

  
231

  
232 203
class ThirdPartyUserCreationForm(forms.ModelForm, StoreUserMixin):
233 204
    email = forms.EmailField(
234 205
        label='Contact email',
......
312 283
        return user
313 284

  
314 285

  
315
class InvitedThirdPartyUserCreationForm(ThirdPartyUserCreationForm):
316
    """
317
    Extends the ThirdPartyUserCreationForm: email is readonly.
318
    """
319
    def __init__(self, *args, **kwargs):
320
        """
321
        Changes the order of fields, and removes the username field.
322
        """
323
        super(
324
            InvitedThirdPartyUserCreationForm, self).__init__(*args, **kwargs)
325

  
326
        #set readonly form fields
327
        ro = ('email',)
328
        for f in ro:
329
            self.fields[f].widget.attrs['readonly'] = True
330

  
331
    def save(self, commit=True, **kwargs):
332
        user = \
333
            super(InvitedThirdPartyUserCreationForm, self).save(commit=False,
334
                                                                **kwargs)
335
        user.set_invitation_level()
336
        user.email_verified = True
337
        if commit:
338
            user.save(**kwargs)
339
        return user
340

  
341

  
342
class ShibbolethUserCreationForm(ThirdPartyUserCreationForm):
343
    additional_email = forms.CharField(
344
        widget=forms.HiddenInput(), label='', required=False)
345

  
346
    def __init__(self, *args, **kwargs):
347
        super(ShibbolethUserCreationForm, self).__init__(*args, **kwargs)
348
        # copy email value to additional_mail in case user will change it
349
        name = 'email'
350
        field = self.fields[name]
351
        self.initial['additional_email'] = self.initial.get(
352
            name, field.initial)
353
        self.initial['email'] = None
354

  
355

  
356
class InvitedShibbolethUserCreationForm(ShibbolethUserCreationForm,
357
                                        InvitedThirdPartyUserCreationForm):
358
    pass
359

  
360

  
361 286
class LoginForm(AuthenticationForm):
362 287
    username = forms.EmailField(label=_("Email"))
363 288
    recaptcha_challenge_field = forms.CharField(widget=DummyWidget)

Also available in: Unified diff