def users(): n = int(input("Enter number of users to create: ")) for _ in range(n): lorem = LoremPysum() email = lorem.email() + str(n) try: user = CustomUser.objects.create_user(email=email) user.set_password("dwarfstar") user.is_active = True user.save() screen_name = lorem.word() try: SiteUser.objects.create( user=user, screen_name=screen_name, ) except IntegrityError: SiteUser.objects.create( user=user, screen_name=screen_name, ) except IntegrityError: continue
def requests(): numb = int(input("Enter number of requests to create ")) users = SiteUser.objects.all() lorem = LoremPysum() for _ in range(numb): _ = Request.objects.create(creator=choice(users), request=lorem.title(), status=choice([True, False]))
def comments(): users = SiteUser.objects.all() lorem = LoremPysum() for post in Post.objects.all(): for _ in range(randint(5, 50)): _ = Comment.objects.create(creator=choice(users), post=post, comment=lorem.sentence())
def authors(): numb = int(input("Enter number of authors to create ")) users = SiteUser.objects.all() for _ in range(numb): lorem = LoremPysum() _, _ = Author.objects.get_or_create( creator=choice(users), first_name=lorem.word(), last_name=lorem.word(), bio=lorem.paragraphs(count=randint(1, 3)), author_type=choice(AUTHORS))
def posts(): users = SiteUser.objects.all() SONGS = Song.objects.all() lorem = LoremPysum() numb = int(input("Enter number of posts to create ")) for _ in range(numb): title = lorem.title() body = lorem.sentences(count=randint(4, 8)) selector = randint(0, 1) if selector and (len(SONGS) > 0): _ = Post.objects.get_or_create(creator=choice(users), title=title, body=body, song=choice(SONGS), publish=choice([True, False])) else: _ = Post.objects.get_or_create(creator=choice(users), title=title, body=body, publish=choice([True, False]))
def songs(): users = SiteUser.objects.all() voices = Voicing.objects.all() languages = Language.objects.all() numb = int(input("Enter number of songs to create: ")) for _ in range(numb): lorem = LoremPysum() voicing = Voicing.objects.get(name=choice(VOICING)) language = Language.objects.get(name=choice(LANGUAGE)) _ = Song.objects.create(creator=choice(users), title=lorem.title(), publish=choice([True, False]), lyrics=lorem.paragraphs(count=randint(2, 4)), scripture_reference=choice(SCRIPTURE), tempo=randint(45, 250), bpm=randint(4, 8), divisions=randint(4, 8), voicing=choice(voices), language=choice(languages))
def members(): roles = Role.objects.all() n = int(input("Enter number of users to create: ")) for _ in range(n): lorem = LoremPysum("fixtures/eng_names.txt", "fixtures/igbo_names.txt") email = lorem.email() + str(n) try: user = CustomUser.objects.create_user(email=email) user.set_password("dwarfstar") user.is_active = True user.save() first_name = lorem.word() last_name = lorem.word() location = choice(LOCATIONS) screen_name = LoremPysum().word() try: member = SiteUser.objects.create( user=user, first_name=first_name, last_name=last_name, location=location, screen_name=screen_name, avatar=File(open(choice(IMAGES), "rb")), ) except IntegrityError: member = SiteUser.objects.create( user=user, first_name=first_name, last_name=last_name, location=location, screen_name=screen_name + str(n), avatar=File(open(choice(IMAGES), "rb")), ) except IntegrityError: continue try: role = choice(roles) member.roles.add(role.pk) except IntegrityError: continue