def handle(self, *args, **options): if options['delete']: Expense.objects.all().delete() for i in range(10): try: User.objects.create_user("user{}".format(i), password="******") except IntegrityError: pass users = list(User.objects.all()) for u in users: while u.categories.count() < 4: s = silly.a_thing().title() # "Beautiful cat" u.categories.create( title=s, slug=slugify(s), ) for i in range(options['n']): with transaction.atomic(): o = Expense( user=random.choice(users), date=datetime.date(random.randint(2010, 2017), random.randint(1, 12), random.randint(1, 28)), title=silly.a_thing(), amount=random.randint(1, 1000), description=paragraph(random.randint(2, 4)), ) o.full_clean() o.save() cats = random.sample(list(o.user.categories.all()), random.randint(0, 2)) o.categories = cats # for c in cats: # o.categories.create(category=c) for j in range(random.randint(3, 10)): o.comments.create( user=random.choice(users), content=paragraph(random.randint(1, 6)), )
def handle(self, *args, **options): if options['delete']: Expense.objects.all().delete() for i in range(10): try: User.objects.create_user("user{}".format(i), password="******") except IntegrityError: pass users = list(User.objects.all()) for i in range(options['n']): o = Expense( user=random.choice(users), date=datetime.date(random.randint(2010, 2017), random.randint(1, 12), random.randint(1, 28)), title=silly.a_thing(), amount=random.randint(1, 1000), description=paragraph(random.randint(2, 4)), ) o.full_clean() o.save() for j in range(random.randint(3, 10)): o.comments.create(user=random.choice(users), content=paragraph(random.randint(1, 6)))
def handle(self, *args, **options): images = glob.glob(f"{IMG_PATH}/image*.jpeg") try: User.objects.create_superuser('sysop', '', 'sysop') except IntegrityError: pass with SAMPLE_PROJECTS_FILE.open() as f: for i, proj in enumerate(load_projects(json.load(f))): with transaction.atomic(): print(proj['slug']) project = Project() project.name = proj['name'] project.slug = proj['slug'] project.geom = proj['polygon'] project.center = proj['polygon'].centroid f = (IMG_PATH / f"logo_{i + 1:04d}.jpeg").open("rb") project.logo_file.save(f"logo{i + 1}.jpeg", File(f)) project.save() for location_id in range( self.num_of_locations_per_project): location = Location() location.project = project location.name = silly.a_thing() x0, y0, x1, y1 = project.geom.extent x = random.uniform(x0, x1) y = random.uniform(y0, y1) location.point = Point(x, y) location.information = silly.sentence() location.save() for photo_id in range( random.randint( 0, self.num_of_photos_per_location)): photo = Photo() photo.name = silly.a_thing() photo.location = location photo.date_taken = silly.datetime().date() photo.lond_desc = silly.paragraph() with open(random.choice(images), "rb") as f: photo.photo_file.save("random.jpg", File(f)) photo.save()
def handle(self, n, **options): for i in range(n): o = Expense() o.title = silly.a_thing() o.amount = "{}.{}".format(random.randint(1, 100), random.randint(0, 99)) o.date = silly.datetime().date() o.description = "\n".join( [silly.paragraph(), silly.paragraph(), silly.paragraph()]) o.save()
def handle(self, n, *args, **kwargs): Expense.objects.all().delete() for i in range(n): with transaction.atomic(): o = Expense() o.title = silly.a_thing() o.date = silly.datetime().date() o.amount = f"{random.uniform(1, 1000):.2f}" o.comment = "\n".join(silly.paragraph() for i in range(random.randrange(0, 3))) o.save() for j in range(random.randrange(5)): o.notes.create(content="\n".join( silly.paragraph() for i in range(random.randrange(1, 4))))
def create_random_expense(self): with transaction.atomic(): o = Expense() o.title = silly.a_thing() o.amount = "{}.{}".format(random.randint(1, 100), random.randint(0, 99)) o.date = silly.datetime().date() o.description = "\n".join( [silly.paragraph(), silly.paragraph(), silly.paragraph()]) o.save() for j in range(random.randint(0, 5)): text = "\n".join( [silly.paragraph(), silly.paragraph(), silly.paragraph()]) o.comments.create(content=text)
def handle(self, n, **options): next_bid = 0 try: next_bid = Movie.objects.latest('idea_bid').idea_bid + 1 except models.ObjectDoesNotExist: print('No Movies found') finally: print('Next idea_bid in DB=' + str(next_bid)) progress = tqdm(total=n) for i in range(n): o = Movie() o.idea_bid = next_bid + i o.title = silly.a_thing() o.year = random.randint(1900, 2100) o.lang = random.choice(['Heb', 'Eng', 'Unknown']) o.full_clean() if not options['readonly']: o.save() progress.update(1) progress.close()
import pandas as pd import numpy as np from functools import partial, wraps, cache from collections import defaultdict, Counter, deque from itertools import accumulate, chain, combinations, combinations_with_replacement, compress, count, cycle, dropwhile, filterfalse, groupby, islice, permutations, product, repeat, starmap, takewhile, tee, zip_longest from operator import itemgetter, attrgetter try: import silly except: s = 'unable to import silly!' else: s = '{} {} has {}'.format(silly.title(), silly.name(), silly.a_thing()) banner = len(s) * '=' try: from rich import print, inspect, box help_orig = help help = partial(inspect, methods=True, help=True) from rich.table import Table from rich.style import Style except ModuleNotFoundError: s += '\nunable to import rich' else: s += '\n:tada: [green on purple]rich[/] [red bold]installed :tada:' print() print(banner) print(s)