in pulseapi/utility/management/commands/load_fake_data.py [0:0]
def handle(self, *args, **options):
if options['delete']:
call_command('flush_data')
if options['seed']:
seed = options['seed']
else:
seed = randint(0, 5000000)
print('Seeding Faker with {}'. format(seed))
faker = factory.faker.Faker._get_faker(locale='en-US')
faker.random.seed(seed)
print('Creating tags')
[TagFactory.create() for i in range(options['tags_count'])]
print('Creating users')
generate_fake_data(BasicEmailUserFactory, options['users_count'])
# Since every Mozilla users' emails must be @mozillafoundation.org, we run into "UNIQUE constraint failed"
# error from time to time
try:
generate_fake_data(MozillaEmailUserFactory, options['users_count'])
except IntegrityError:
print('Failed to create user: this email address is already in the database. No more users will be '
'created this run.')
pass
print('Creating pulse entries')
generate_fake_data(BasicEntryFactory, options['entries_count'])
generate_fake_data(GetInvolvedEntryFactory, options['entries_count'])
print('Creating fellows')
generate_fellows(options['fellows_count'])
# Select random published entries and bookmark them for 1 to 10 users
print('Creating bookmarks')
approved_entries = Entry.objects.public().with_related()
for e in sample(list(approved_entries), k=len(approved_entries) // 2):
[UserBookmarksFactory.create(entry=e) for i in range(randint(1, 10))]
# Select random entries and link them to 1 to 5 creators
print('Linking random profiles as creators with random entries')
all_entries = Entry.objects.all()
for e in sample(list(all_entries), k=len(all_entries) // 2):
try:
[EntryCreatorFactory.create(entry=e) for i in range(randint(1, 5))]
# That creator and entry might already be linked. If it's the case, skip it and move on:
except IntegrityError:
continue
print(self.style.SUCCESS('Done!'))