Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jonboiser/361604ce4f727b420284c7fccaf994d7 to your computer and use it in GitHub Desktop.
Save jonboiser/361604ce4f727b420284c7fccaf994d7 to your computer and use it in GitHub Desktop.
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'],
facility=facility
)
user.set_password('a')
user.save()
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)}
user = FacilityUser.objects.create(
full_name=profile['name'],
username=profile['username'],
facility=facility
)
user.set_password('a')
user.save()
facility.add_admin(user)
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