<s> import logging <EOL> from django import forms <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . forms import ( <EOL> UserChangeForm as BaseUserChangeForm , <EOL> UserCreationForm as BaseUserCreationForm ) <EOL> from django . core . exceptions import ValidationError <EOL> from django . utils . text import slugify <EOL> from . models import Profile <EOL> from . utils import ActivationMailFormMixin <EOL> logger = logging . getLogger ( __name__ ) <EOL> class ResendActivationEmailForm ( <EOL> ActivationMailFormMixin , forms . Form ) : <EOL> email = forms . EmailField ( ) <EOL> mail_validation_error = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def save ( self , ** kwargs ) : <EOL> User = get_user_model ( ) <EOL> try : <EOL> user = User . objects . get ( <EOL> email = self . cleaned_data [ '<STR_LIT:email>' ] ) <EOL> except : <EOL> logger . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> self . cleaned_data [ '<STR_LIT:email>' ] ) ) <EOL> return None <EOL> self . send_mail ( user = user , ** kwargs ) <EOL> return user <EOL> class UserChangeForm ( BaseUserChangeForm ) : <EOL> """<STR_LIT>""" <EOL> class Meta ( BaseUserChangeForm . Meta ) : <EOL> model = get_user_model ( ) <EOL> class UserCreationForm ( <EOL> ActivationMailFormMixin , <EOL> BaseUserCreationForm ) : <EOL> name = forms . CharField ( <EOL> max_length = <NUM_LIT:255> , <EOL> help_text = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> mail_validation_error = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class Meta ( BaseUserCreationForm . Meta ) : <EOL> model = get_user_model ( ) <EOL> fields = ( '<STR_LIT:name>' , '<STR_LIT:email>' ) <EOL> def clean_name ( self ) : <EOL> name = self . cleaned_data [ '<STR_LIT:name>' ] <EOL> disallowed = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:password>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> if name in disallowed : <EOL> raise ValidationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return name <EOL> def save ( self , ** kwargs ) : <EOL> user = super ( ) . save ( commit = False ) <EOL> if not user . pk : <EOL> user . is_active = False <EOL> send_mail = True <EOL> else : <EOL> send_mail = False <EOL> user . save ( ) <EOL> self . save_m2m ( ) <EOL> Profile . objects . update_or_create ( <EOL> user = user , <EOL> defaults = { <EOL> '<STR_LIT:name>' : self . cleaned_data [ '<STR_LIT:name>' ] , <EOL> '<STR_LIT>' : slugify ( <EOL> self . cleaned_data [ '<STR_LIT:name>' ] ) , <EOL> } ) <EOL> if send_mail : <EOL> self . send_mail ( user = user , ** kwargs ) <EOL> return user </s>
