harvestconnect-api / api /seeding /practice_users.py
Dayozoe's picture
feat: deploy HarvestConnect Django API with crash-proof persistent volume
a6be783 verified
Raw History Blame Contribute Delete
1.24 kB
from django.contrib.auth.models import User
from api.models import UserProfile
ROLES = ('buyer', 'farmer', 'tradesman', 'artisan')
PASSWORD = 'PracticePassword123'
def create_practice_users(command):
command.stdout.write('Creating core practice users...')
for role in ROLES:
email = f'{role}@harvestconnect.local'
user, _ = User.objects.get_or_create(username=email, defaults={
'email': email, 'first_name': f'{role.capitalize()}User', 'last_name': 'Seed',
})
user.set_password(PASSWORD)
user.save()
profile, _ = UserProfile.objects.get_or_create(user=user)
profile.role, profile.bio = role, f'This is a {role} account for testing HarvestConnect features.'
profile.location, profile.verified = 'Heritage Valley', True
profile.save()
command.stdout.write(f'Verified account for {role}: {email}')
users = list(User.objects.filter(is_staff=False, is_superuser=False))
profiles = {user.id: UserProfile.objects.get(user=user) for user in users}
sellers = [user for user in users if profiles[user.id].role != 'buyer']
buyer = next(user for user in users if profiles[user.id].role == 'buyer')
return users, sellers, buyer