<s> from braces . forms import UserKwargModelFormMixin <EOL> from django import forms <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . forms import ( <EOL> AuthenticationForm as BaseAuthenticationForm ) <EOL> from localshop . apps . accounts import models <EOL> class AuthenticationForm ( BaseAuthenticationForm ) : <EOL> remember_me = forms . BooleanField ( required = False ) <EOL> class ProfileForm ( forms . ModelForm ) : <EOL> class Meta : <EOL> model = get_user_model ( ) <EOL> fields = [ '<STR_LIT:username>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:email>' ] <EOL> class AccessKeyForm ( UserKwargModelFormMixin , forms . ModelForm ) : <EOL> class Meta : <EOL> model = models . AccessKey <EOL> fields = [ '<STR_LIT>' ] <EOL> def save ( self ) : <EOL> self . instance . user = self . user <EOL> return super ( AccessKeyForm , self ) . save ( commit = True ) <EOL> class TeamFormMixin ( object ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . team = kwargs . pop ( '<STR_LIT>' ) <EOL> super ( TeamFormMixin , self ) . __init__ ( * args , ** kwargs ) <EOL> class TeamMemberAddForm ( TeamFormMixin , forms . ModelForm ) : <EOL> class Meta : <EOL> model = models . TeamMember <EOL> fields = [ '<STR_LIT:user>' , '<STR_LIT>' ] <EOL> def clean_user ( self ) : <EOL> user = self . cleaned_data [ '<STR_LIT:user>' ] <EOL> if user and self . team . members . filter ( user = user ) . exists ( ) : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" % user . username ) <EOL> return user <EOL> def save ( self , commit = True ) : <EOL> instance = super ( TeamMemberAddForm , self ) . save ( commit = False ) <EOL> if commit : <EOL> instance . team = self . team <EOL> instance . save ( ) <EOL> return instance <EOL> class TeamMemberRemoveForm ( TeamFormMixin , forms . Form ) : <EOL> member_obj = forms . ModelChoiceField ( models . TeamMember . objects . all ( ) ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( TeamMemberRemoveForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] = forms . ModelChoiceField ( <EOL> self . team . members . all ( ) ) <EOL> def clean ( self ) : <EOL> member_obj = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if not member_obj or member_obj . team . pk != self . team . pk : <EOL> raise forms . ValidationError ( "<STR_LIT>" ) <EOL> return self . cleaned_data </s>
