Show
Ignore:
Timestamp:
09/11/08 08:24:10 (18 months ago)
Author:
JensDiemer
Message:

remove the work-a-round: ticket:227

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/PyLucid/plugins_internal/auth/auth.py

    r1755 r1758  
    161161# FORMS 
    162162 
    163 #class UsernameForm(forms.ModelForm): 
    164 #    """ 
    165 #    form for input the username, used in auth.login() 
    166 #    """ 
    167 #    class Meta: 
    168 #        model = User 
    169 #        fields=("username",) 
    170  
    171 class UsernameForm(forms.Form): 
    172     """ 
    173     FIXME: If we use ModelForm from above, we always get the form error: 
    174         User with this Username already exists. 
    175     Why? 
    176     """ 
    177     username = forms.CharField(max_length=30, help_text=_( 
    178             "Required. 30 characters or fewer. Alphanumeric characters only" 
    179             " (letters, digits and underscores)." 
    180         ) 
    181     ) 
    182  
    183 #class PasswordForm(forms.ModelForm): 
    184 #    """ 
    185 #    form for input the username, used in auth._sha_login() 
    186 #    """ 
    187 #    class Meta: 
    188 #        model = User 
    189 #        fields=("password",) 
    190 class PasswordForm(forms.Form): 
    191     """ 
    192     Same 'User with this Username already exists.' problem from above. 
    193     """ 
    194     password = forms.CharField(max_length=128) 
    195  
    196  
    197 class ResetForm(forms.Form): 
    198     """ 
    199     We should not use a ModelForm from the User model, because, the email 
    200     is required here or we must patch a ModelForm. 
    201     """ 
    202     username = forms.CharField(max_length=30, help_text=_( 
    203             "Required. 30 characters or fewer. Alphanumeric characters only" 
    204             " (letters, digits and underscores)." 
    205         ) 
    206     ) 
    207     email = forms.EmailField() 
     163class ModelForm2(forms.ModelForm): 
     164    def validate_unique(self): 
     165        """ 
     166        Don't validate unique fields. 
     167        We used a ModelForm only for generating the forms and not for 
     168        create/update any database data. So a field unique Test would like 
     169        generate Errors like: 
     170            User with this Username already exists. 
     171        """ 
     172        pass 
     173 
     174 
     175class UsernameForm(ModelForm2): 
     176    """ 
     177    form for input the username, used in auth.login() 
     178    """     
     179    class Meta: 
     180        model = User 
     181        fields=("username",) 
     182 
     183 
     184class PasswordForm(ModelForm2): 
     185    """ 
     186    form for input the username, used in auth._sha_login() 
     187    """ 
     188    class Meta: 
     189        model = User 
     190        fields=("password",) 
     191 
     192 
     193class ResetForm(ModelForm2): 
     194    """ 
     195    from for input username and email, used in auth.pass_reset() 
     196    """ 
     197    def __init__(self, *args, **kwargs): 
     198        super(ResetForm, self).__init__(*args, **kwargs) 
     199        # User.email is normaly a not required field, here it's required! 
     200        self.fields['email'].required = True 
     201         
     202    class Meta: 
     203        model = User 
     204        fields=("username","email") 
    208205 
    209206 
     
    253250            username_form = UsernameForm() 
    254251        else: 
    255 #            self.page_msg(self.request.POST) 
    256             username_form = UsernameForm(self.request.POST) 
     252            #self.page_msg(self.request.POST) 
     253            username_form = UsernameForm(self.request.POST)           
    257254            user = get_data(username_form) 
    258255            if user != None: # A valid form with a existing user was send.