enforce not_applied_partners check in applications_example_data
@@ -70,8 +70,9 @@ class Command(BaseCommand):
not_applied_partners = available_partners.exclude(
applications__editor=random_editor
)
- random_partner = random.choice(not_applied_partners)
+ if not_applied_partners:
+ random_partner = random.choice(not_applied_partners)
app = ApplicationFactory(
editor=random_editor,
partner=random_partner,
@@ -93,7 +94,9 @@ class Command(BaseCommand):
app.agreement_with_terms_of_use = True
if random_partner.account_email:
- app.account_email = Faker(random.choice(settings.FAKER_LOCALES)).email()
+ app.account_email = Faker(
+ random.choice(settings.FAKER_LOCALES)
+ ).email()
# Imported applications have very specific information, and were
# all imported on the same date.
@@ -117,13 +120,15 @@ class Command(BaseCommand):
app.date_created = Faker(
random.choice(settings.FAKER_LOCALES)
- ).date_time_between(start_date=start_date, end_date="now", tzinfo=None)
- app.rationale = Faker(random.choice(settings.FAKER_LOCALES)).paragraph(
- nb_sentences=3
- )
- app.comments = Faker(random.choice(settings.FAKER_LOCALES)).paragraph(
- nb_sentences=2
+ ).date_time_between(
+ start_date=start_date, end_date="now", tzinfo=None
)
+ app.rationale = Faker(
+ random.choice(settings.FAKER_LOCALES)
+ ).paragraph(nb_sentences=3)
+ app.comments = Faker(
+ random.choice(settings.FAKER_LOCALES)
+ ).paragraph(nb_sentences=2)
# For closed applications, assign date_closed and date_open
if app.status in Application.FINAL_STATUS_LIST:
