Spaces:
Running
Running
Download api/seeding/practice_users.py from Dayozoe/harvestconnect-api: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/Dayozoe/harvestconnect-api/resolve/main/api/seeding/practice_users.py
- Command line
-
hf download hf://spaces/Dayozoe/harvestconnect-api/api/seeding/practice_users.py
-
curl -L -o practice_users.py https://huggingface.co/spaces/Dayozoe/harvestconnect-api/resolve/main/api/seeding/practice_users.py
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 | |