<s> from datetime import timedelta <EOL> import itertools <EOL> import random <EOL> from django . core . management . base import BaseCommand <EOL> from django_countries import countries as Countries <EOL> from faker import Faker <EOL> from workshops . models import ( <EOL> Airport , <EOL> Role , <EOL> Tag , <EOL> Badge , <EOL> Lesson , <EOL> Person , <EOL> Award , <EOL> Qualification , <EOL> Host , <EOL> Event , <EOL> Task , <EOL> ) <EOL> class Command ( BaseCommand ) : <EOL> help = '<STR_LIT>' <EOL> def add_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , action = '<STR_LIT:store>' , default = None , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> def fake_airports ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def fake_roles ( self , faker ) : <EOL> """<STR_LIT>""" <EOL> roles = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:host>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> for role in roles : <EOL> Role . objects . create ( name = role ) <EOL> def fake_tags ( self , faker ) : <EOL> """<STR_LIT>""" <EOL> tags = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for tag , details in tags : <EOL> Tag . objects . create ( name = tag , details = details ) <EOL> def fake_badges ( self , faker ) : <EOL> """<STR_LIT>""" <EOL> badges = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ] <EOL> for name , title , criteria in badges : <EOL> Badge . objects . create ( name = name , title = title , criteria = criteria ) <EOL> def fake_instructors ( self , faker , count = <NUM_LIT:5> , add_badge = True , <EOL> add_qualifications = True ) : <EOL> """<STR_LIT>""" <EOL> airports = list ( Airport . objects . all ( ) ) <EOL> badges = list ( Badge . objects . instructor_badges ( ) ) <EOL> lessons = list ( Lesson . objects . all ( ) ) <EOL> for i in range ( count ) : <EOL> user_name = faker . user_name ( ) <EOL> emails = [ faker . email ( ) , faker . safe_email ( ) , faker . free_email ( ) , <EOL> faker . company_email ( ) ] <EOL> gender = random . choice ( Person . GENDER_CHOICES ) [ <NUM_LIT:0> ] <EOL> if gender == '<STR_LIT:F>' : <EOL> name = faker . first_name_female ( ) <EOL> last_name = faker . last_name_female ( ) <EOL> elif gender == '<STR_LIT:M>' : <EOL> name = faker . first_name_male ( ) <EOL> last_name = faker . last_name_male ( ) <EOL> else : <EOL> name , last_name = faker . first_name ( ) , faker . last_name ( ) <EOL> person = Person . objects . create ( <EOL> personal = name , <EOL> middle = None , <EOL> family = last_name , <EOL> email = random . choice ( emails ) , <EOL> gender = gender , <EOL> may_contact = random . choice ( [ True , False ] ) , <EOL> airport = random . choice ( airports ) , <EOL> github = user_name , <EOL> twitter = user_name , <EOL> url = faker . url ( ) , <EOL> username = user_name , <EOL> ) <EOL> if add_badge : <EOL> Award . objects . create ( <EOL> person = person , badge = random . choice ( badges ) , <EOL> awarded = faker . date_time_this_year ( before_now = True , <EOL> after_now = False ) . date ( ) , <EOL> ) <EOL> if add_qualifications : <EOL> for lesson in random . sample ( lessons , <NUM_LIT:4> ) : <EOL> Qualification . objects . create ( person = person , lesson = lesson ) <EOL> def fake_noninstructors ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> return self . fake_instructors ( <EOL> faker = faker , count = count , add_badge = False , <EOL> add_qualifications = False , <EOL> ) <EOL> def fake_hosts ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> countries = list ( Countries ) <EOL> for i in range ( count ) : <EOL> Host . objects . create ( <EOL> domain = faker . domain_name ( ) , <EOL> fullname = faker . company ( ) , <EOL> country = random . choice ( countries ) [ <NUM_LIT:0> ] , <EOL> ) <EOL> def fake_current_events ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> twodays = timedelta ( days = <NUM_LIT:2> ) <EOL> hosts = list ( Host . objects . exclude ( domain = '<STR_LIT>' ) ) <EOL> countries = list ( Countries ) <EOL> for i in range ( count ) : <EOL> start = faker . date_time_this_year ( before_now = False , <EOL> after_now = True ) . date ( ) <EOL> Event . objects . create ( <EOL> slug = '<STR_LIT>' . format ( start , faker . slug ( ) ) , <EOL> start = start , <EOL> end = start + twodays , <EOL> url = faker . url ( ) , <EOL> host = random . choice ( hosts ) , <EOL> country = random . choice ( countries ) [ <NUM_LIT:0> ] , <EOL> venue = faker . word ( ) . title ( ) , <EOL> address = faker . sentence ( nb_words = <NUM_LIT:4> , variable_nb_words = True ) , <EOL> latitude = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> longitude = random . uniform ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> ) <EOL> def fake_uninvoiced_events ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> twodays = timedelta ( days = <NUM_LIT:2> ) <EOL> countries = list ( Countries ) <EOL> hosts = list ( Host . objects . exclude ( domain = '<STR_LIT>' ) ) <EOL> for i in range ( count ) : <EOL> start = faker . date_time_this_year ( before_now = True , <EOL> after_now = False ) . date ( ) <EOL> Event . objects . create ( <EOL> slug = '<STR_LIT>' . format ( start , faker . slug ( ) ) , <EOL> start = start , <EOL> end = start + twodays , <EOL> url = faker . url ( ) , <EOL> host = random . choice ( hosts ) , <EOL> country = random . choice ( countries ) [ <NUM_LIT:0> ] , <EOL> venue = faker . word ( ) . title ( ) , <EOL> address = faker . sentence ( nb_words = <NUM_LIT:4> , variable_nb_words = True ) , <EOL> latitude = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> longitude = random . uniform ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> invoice_status = '<STR_LIT>' , <EOL> ) <EOL> def fake_unpublished_events ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> twodays = timedelta ( days = <NUM_LIT:2> ) <EOL> hosts = list ( Host . objects . exclude ( domain = '<STR_LIT>' ) ) <EOL> for i in range ( count ) : <EOL> start = faker . date_time_this_year ( before_now = True , <EOL> after_now = True ) . date ( ) <EOL> Event . objects . create ( <EOL> slug = '<STR_LIT>' . format ( start , faker . slug ( ) ) , <EOL> start = start , <EOL> end = start + twodays , <EOL> url = faker . url ( ) , <EOL> host = random . choice ( hosts ) , <EOL> ) <EOL> def fake_self_organized_events ( self , faker , count = <NUM_LIT:5> ) : <EOL> """<STR_LIT>""" <EOL> twodays = timedelta ( days = <NUM_LIT:2> ) <EOL> self_organized = Host . objects . get ( domain = '<STR_LIT>' ) <EOL> countries = list ( Countries ) <EOL> invoice_statuses = Event . INVOICED_CHOICES <EOL> for i in range ( count ) : <EOL> start = faker . date_time_this_year ( before_now = True , <EOL> after_now = True ) . date ( ) <EOL> Event . objects . create ( <EOL> slug = '<STR_LIT>' . format ( start , faker . slug ( ) ) , <EOL> start = start , <EOL> end = start + twodays , <EOL> url = faker . url ( ) , <EOL> host = self_organized , <EOL> country = random . choice ( countries ) [ <NUM_LIT:0> ] , <EOL> venue = faker . word ( ) . title ( ) , <EOL> address = faker . sentence ( nb_words = <NUM_LIT:4> , variable_nb_words = True ) , <EOL> latitude = random . uniform ( - <NUM_LIT> , <NUM_LIT> ) , <EOL> longitude = random . uniform ( <NUM_LIT:0> , <NUM_LIT> ) , <EOL> invoice_status = random . choice ( invoice_statuses ) [ <NUM_LIT:0> ] , <EOL> ) <EOL> def fake_tasks ( self , faker , count = <NUM_LIT:50> ) : <EOL> events = Event . objects . all ( ) <EOL> persons = Person . objects . all ( ) <EOL> roles = Role . objects . all ( ) <EOL> all_possible = itertools . product ( events , persons , roles ) <EOL> for event , person , role in random . sample ( list ( all_possible ) , count ) : <EOL> Task . objects . create ( event = event , person = person , role = role ) <EOL> def handle ( self , * args , ** options ) : <EOL> faker = Faker ( ) <EOL> seed = options [ '<STR_LIT>' ] <EOL> if seed is not None : <EOL> faker . seed ( seed ) <EOL> self . fake_airports ( faker ) <EOL> self . fake_roles ( faker ) <EOL> self . fake_tags ( faker ) <EOL> self . fake_badges ( faker ) <EOL> self . fake_instructors ( faker ) <EOL> self . fake_noninstructors ( faker ) <EOL> self . fake_hosts ( faker ) <EOL> self . fake_current_events ( faker ) <EOL> self . fake_uninvoiced_events ( faker ) <EOL> self . fake_unpublished_events ( faker ) <EOL> self . fake_self_organized_events ( faker ) <EOL> self . fake_tasks ( faker ) </s>
