<s> from django . contrib . auth . models import User <EOL> from django . db . utils import DatabaseError <EOL> from django . views . generic import FormView <EOL> from customers . forms import GenerateUsersForm <EOL> from customers . models import Client <EOL> from random import choice <EOL> class TenantView ( FormView ) : <EOL> form_class = GenerateUsersForm <EOL> template_name = "<STR_LIT>" <EOL> success_url = "<STR_LIT:/>" <EOL> def get_context_data ( self , ** kwargs ) : <EOL> context = super ( TenantView , self ) . get_context_data ( ** kwargs ) <EOL> context [ '<STR_LIT>' ] = Client . objects . all ( ) <EOL> context [ '<STR_LIT>' ] = User . objects . all ( ) <EOL> return context <EOL> def form_valid ( self , form ) : <EOL> User . objects . all ( ) . delete ( ) <EOL> USERS_TO_GENERATE = <NUM_LIT:5> <EOL> first_names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> last_names = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> while User . objects . count ( ) != USERS_TO_GENERATE : <EOL> first_name = choice ( first_names ) <EOL> last_name = choice ( last_names ) <EOL> try : <EOL> user = User ( username = ( first_name + last_name ) . lower ( ) , <EOL> email = "<STR_LIT>" % ( first_name , last_name ) , <EOL> first_name = first_name , <EOL> last_name = last_name ) <EOL> user . save ( ) <EOL> except DatabaseError : <EOL> pass <EOL> return super ( TenantView , self ) . form_valid ( form ) </s>
