Formatting

This commit is contained in:
Scot Hacker 2019-04-12 00:09:01 -07:00
parent 4a385bde6b
commit befc7ad2cd
28 changed files with 253 additions and 311 deletions

View file

@ -18,7 +18,7 @@ def gen_title(tc=True):
# faker doesn't provide a way to generate headlines in Title Case, without periods, so make our own.
# With arg `tc=True`, Title Cases The Generated Text
fake = Faker()
thestr = fake.text(max_nb_chars=32).rstrip('.')
thestr = fake.text(max_nb_chars=32).rstrip(".")
if tc:
thestr = titlecase(thestr)
@ -29,7 +29,7 @@ def gen_content():
# faker provides paragraphs as a list; convert with linebreaks
fake = Faker()
grafs = fake.paragraphs()
thestr = ''
thestr = ""
for g in grafs:
thestr += "{}\n\n".format(g)
return thestr
@ -43,11 +43,12 @@ class Command(BaseCommand):
"-d",
"--delete",
help="Wipe out existing content before generating new.",
action="store_true")
action="store_true",
)
def handle(self, *args, **options):
if options.get('delete'):
if options.get("delete"):
# Wipe out previous contents? Cascade deletes the Tasks from the TaskLists.
TaskList.objects.all().delete()
print("Content from previous run deleted.")
@ -56,11 +57,11 @@ class Command(BaseCommand):
fake = Faker() # Use to create user's names
# Create users and groups, add different users to different groups. Staff user is in both groups.
sd_group, created = Group.objects.get_or_create(name='Scuba Divers')
bw_group, created = Group.objects.get_or_create(name='Basket Weavers')
sd_group, created = Group.objects.get_or_create(name="Scuba Divers")
bw_group, created = Group.objects.get_or_create(name="Basket Weavers")
# Put user1 and user2 in one group, user3 and user4 in another
usernames = ['user1', 'user2', 'user3', 'user4', 'staffer']
usernames = ["user1", "user2", "user3", "user4", "staffer"]
for username in usernames:
if get_user_model().objects.filter(username=username).exists():
user = get_user_model().objects.get(username=username)
@ -70,15 +71,16 @@ class Command(BaseCommand):
first_name=fake.first_name(),
last_name=fake.last_name(),
email="{}@example.com".format(username),
password="todo")
password="todo",
)
if username in ['user1', 'user2']:
if username in ["user1", "user2"]:
user.groups.add(bw_group)
if username in ['user3', 'user4']:
if username in ["user3", "user4"]:
user.groups.add(sd_group)
if username == 'staffer':
if username == "staffer":
user.is_staff = True
user.first_name = fake.first_name()
user.last_name = fake.last_name()
@ -91,7 +93,9 @@ class Command(BaseCommand):
TaskListFactory.create_batch(5, group=sd_group)
TaskListFactory.create(name="Public Tickets", slug="tickets", group=bw_group)
print("For each of two groups, created fake tasks in each of {} fake lists.".format(num_lists))
print(
"For each of two groups, created fake tasks in each of {} fake lists.".format(num_lists)
)
class TaskListFactory(factory.django.DjangoModelFactory):
@ -120,9 +124,11 @@ class TaskFactory(factory.django.DjangoModelFactory):
task_list = None # Pass this in
note = factory.LazyAttribute(lambda o: gen_content())
priority = factory.LazyAttribute(lambda o: random.randint(1, 100))
completed = factory.Faker('boolean', chance_of_getting_true=30)
created_by = factory.LazyAttribute(lambda o: get_user_model().objects.get(username='staffer')) # Randomized in post
created_date = factory.Faker('date_this_year')
completed = factory.Faker("boolean", chance_of_getting_true=30)
created_by = factory.LazyAttribute(
lambda o: get_user_model().objects.get(username="staffer")
) # Randomized in post
created_date = factory.Faker("date_this_year")
@factory.post_generation
def add_details(self, build, extracted, **kwargs):
@ -130,7 +136,7 @@ class TaskFactory(factory.django.DjangoModelFactory):
fake = Faker() # Use to create user's names
taskgroup = self.task_list.group
self.created_by = taskgroup.user_set.all().order_by('?').first()
self.created_by = taskgroup.user_set.all().order_by("?").first()
if self.completed:
self.completed_date = fake.date_this_year()
@ -141,6 +147,6 @@ class TaskFactory(factory.django.DjangoModelFactory):
# 1/3 of generated tasks are assigned to someone in this tasks's group
if random.randint(1, 3) == 1:
self.assigned_to = taskgroup.user_set.all().order_by('?').first()
self.assigned_to = taskgroup.user_set.all().order_by("?").first()
self.save()