<s> from __future__ import unicode_literals <EOL> from django import forms <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . contrib . auth import get_user_model <EOL> from django . utils import timezone <EOL> from django . template import defaultfilters <EOL> from django . conf import settings <EOL> from . models import UserProfile <EOL> User = get_user_model ( ) <EOL> class CleanEmailMixin ( object ) : <EOL> def clean_email ( self ) : <EOL> email = self . cleaned_data [ "<STR_LIT:email>" ] <EOL> if settings . ST_CASE_INSENSITIVE_EMAILS : <EOL> email = email . lower ( ) <EOL> if not settings . ST_UNIQUE_EMAILS : <EOL> return email <EOL> is_taken = User . objects . filter ( email = email ) . exists ( ) <EOL> if is_taken : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return email <EOL> def get_email ( self ) : <EOL> return self . cleaned_data [ "<STR_LIT:email>" ] <EOL> class EmailCheckForm ( CleanEmailMixin , forms . Form ) : <EOL> email = forms . CharField ( label = _ ( "<STR_LIT>" ) , widget = forms . EmailInput , max_length = <NUM_LIT> ) <EOL> class EmailChangeForm ( CleanEmailMixin , forms . Form ) : <EOL> email = forms . CharField ( label = _ ( "<STR_LIT>" ) , widget = forms . EmailInput , max_length = <NUM_LIT> ) <EOL> password = forms . CharField ( label = _ ( "<STR_LIT>" ) , widget = forms . PasswordInput ) <EOL> def __init__ ( self , user = None , * args , ** kwargs ) : <EOL> self . user = user <EOL> super ( EmailChangeForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def clean_password ( self ) : <EOL> password = self . cleaned_data [ "<STR_LIT:password>" ] <EOL> if not self . user . check_password ( password ) : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return password <EOL> class UserForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = User <EOL> fields = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class UserProfileForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = UserProfile <EOL> fields = ( "<STR_LIT:location>" , "<STR_LIT>" ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UserProfileForm , self ) . __init__ ( * args , ** kwargs ) <EOL> now = timezone . localtime ( timezone . now ( ) ) <EOL> self . fields [ '<STR_LIT>' ] . help_text = _ ( '<STR_LIT>' ) % { <EOL> '<STR_LIT:date>' : defaultfilters . date ( now ) , <EOL> '<STR_LIT:time>' : defaultfilters . time ( now ) <EOL> } </s>
