-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin semantic versioning, enhance commands for data generation
- Loading branch information
1 parent
5a08a8c
commit 9a5dd68
Showing
20 changed files
with
159 additions
and
323 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import random | ||
import secrets | ||
from os import listdir | ||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from faker import Faker | ||
from measurement.measures import Weight | ||
|
||
from dragonroost.animals.models import Animal | ||
from dragonroost.animals.models import MedicalRecord | ||
from dragonroost.animals.models import Species | ||
from dragonroost.business.models import Location | ||
from dragonroost.people.models import Person | ||
|
||
fake = Faker() | ||
|
||
MEDIA_ROOT = settings.MEDIA_ROOT | ||
|
||
|
||
def random_image(): | ||
dir_path = Path(MEDIA_ROOT) / "images/" | ||
files = [ | ||
content for content in listdir(dir_path) if Path(dir_path / content).is_file() | ||
] | ||
image = random.choice(files) # noqa: S311 | ||
return "images/" + str(image) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Create test data for Dragonroost." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"-c", | ||
"--count", | ||
type=int, | ||
help="Number of animals to create.", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
if options["count"]: | ||
self.create_animals(options["count"]) | ||
self.stdout.write(self.style.SUCCESS("Test data created successfully!")) | ||
|
||
def create_animals(self, count): | ||
species = list(Species.objects.all()) | ||
locations = list(Location.objects.all()) | ||
people = list(Person.objects.all()) | ||
names = [fake.unique.first_name() for i in range(200)] | ||
|
||
statuses = [ | ||
"ADOPTED", | ||
"AMBASSADOR", | ||
"AVAILABLE", | ||
"DECEASED", | ||
"FOSTERED", | ||
"MEDICAL_HOLD", | ||
"ON_HOLD", | ||
"QUARANTINE", | ||
] | ||
|
||
for i in range(count): | ||
animal = Animal.objects.create( | ||
name=names[i], | ||
description=fake.text(max_nb_chars=50), | ||
species=secrets.choice(species), | ||
location=secrets.choice(locations), | ||
color=fake.color(), | ||
donation_fee=random.uniform(5.00, 350.00), # noqa: S311 | ||
age=random.uniform(1, 50), # noqa: S311 | ||
starting_weight=Weight(lb=random.randint(5, 35)), # noqa: S311 | ||
status=secrets.choice(statuses), | ||
animal_photo=random_image(), | ||
) | ||
animal.save() | ||
record_count = secrets.randbelow(6) | ||
for _i in range(record_count): | ||
medical_record = MedicalRecord.objects.create( | ||
animal=animal, | ||
notes=fake.text(max_nb_chars=50), | ||
treatments=fake.text(max_nb_chars=75), | ||
current_weight=Weight(lb=random.randint(7, 40)), # noqa: S311 | ||
bowel_movement=fake.boolean(chance_of_getting_true=50), | ||
q_volunteer=secrets.choice(people), | ||
) | ||
medical_record.save() |
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
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
23 changes: 0 additions & 23 deletions
23
dragonroost/animals/migrations/0002_medicalrecord_findings_medicalrecord_problem_list.py
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
dragonroost/animals/migrations/0003_alter_medicalrecord_options_alter_animal_status.py
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
dragonroost/animals/migrations/0004_alter_animal_animal_photo_and_more.py
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.