Created
May 14, 2020 18:28
-
-
Save nucleogenesis/263e608cc790132809bd4bc21e3dffa2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kolibri.core.auth.models import FacilityUser, Facility, Role | |
from faker import Faker | |
""" | |
pip install Faker if you don't have it | |
""" | |
FAKE = Faker() | |
""" | |
Generates qty learners in each facility given. | |
If no facilities are given, creates qty learners in each facility | |
If faker is True - then the name and username will be generated with semi-realistic users | |
If faker is False - then the user type is named Learner N where N is a number between 0 and qty | |
""" | |
def generate_learners(qty, facilities = None, faker = False): | |
if not facilities: | |
facilities = Facility.objects.all() | |
for i in range(qty): | |
for facility in facilities: | |
if faker: | |
profile = FAKE.profile(fields=['username', 'name']) | |
else: | |
profile = { "username": "learner_{}".format(i), "name": "Learner {}".format(i)} | |
FacilityUser.objects.create( | |
full_name=profile['username'], | |
username=profile['name'], | |
password='a', | |
facility=facility | |
) | |
def generate_admins(qty, facilities = None, faker = False): | |
if not facilities: | |
facilities = Facility.objects.all() | |
for i in range(qty): | |
for facility in facilities: | |
if faker: | |
profile = FAKE.profile(fields=['username', 'name']) | |
else: | |
profile = { "username": "learner_{}".format(i), "name": "Learner {}".format(i)} | |
FacilityUser.objects.create( | |
full_name=profile['username'], | |
username=profile['name'], | |
password='a', | |
facility=facility | |
) | |
def generate_coaches(qty, facilities = None, faker = False): | |
if not facilities: | |
facilities = Facility.objects.all() | |
for i in range(qty): | |
for facility in facilities: | |
if faker: | |
profile = FAKE.profile(fields=['username', 'name']) | |
else: | |
profile = { "username": "learner_{}".format(i), "name": "Learner {}".format(i)} | |
FacilityUser.objects.create( | |
full_name=profile['username'], | |
username=profile['name'], | |
password='a', | |
facility=facility | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment