def handle(self, *args, **options): # Product.objects.all().delete() cats = [ Category.objects.create( title="{} {}".format(silly.adjective(), silly.noun().title()), description=silly.paragraph(length=2) + "\n" + silly.paragraph(length=2), image_url=silly.image(), ) for i in range(8) ] for i in range(100): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph(length=2) price = silly.number() + silly.number() / 10 Product.objects.create( category=random.choice(cats), title=title, description=desc, price=price, image_url=silly.image(), ) print("OK")
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 handle(self, *args, **options): # Product.objects.all().delete() cats = [ Category.objects.create( title="{} {}".format(silly.adjective(), silly.noun().title()), description=silly.paragraph(length=2) + "\n" + silly.paragraph( length=2), image_url=silly.image(), ) for i in range(8)] for i in range(100): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph(length=2) price = silly.number() + silly.number() / 10 Product.objects.create( category=random.choice(cats), title=title, description=desc, price=price, image_url=silly.image(), ) print("OK")
def handle(self, *args, **options): # Product.objects.all().delete() for i in range(5): parent_title = "{} {}".format(silly.adjective(), silly.noun()) parent_desc = silly.paragraph(length=2) + "\n" + silly.paragraph( length=2) parent = Category.objects.create( title=parent_title, description=parent_desc, ) for j in range(5): title = "{} {}".format(silly.adjective(), silly.noun()) desc = silly.paragraph(length=2) + "\n" + silly.paragraph( length=2) price = silly.number() + silly.number() / 10 image_url = silly.image() Category.objects.create(title=title, description=desc, price=price, image_url=image_url, parent=parent)
def handle(self, *args, **options): n = options['n'] for i in range(n): o = models.Expense( date="201{}-{:02}-{}".format( random.randint(0, 9), random.randint(1, 12), random.randint(1, 30) ), amount="{:.2f}".format(random.uniform(1, 100)), title="{} {}".format(silly.adjective(), silly.noun()).title(), description=silly.paragraph(length=random.randint(1, 3)), ) o.full_clean() o.save()
def create_db(): if os.path.exists(app.config['DB_DIR']): click.echo("Found an existing database") click.echo("Destroying old database") os.remove(app.config['DB_DIR']) click.echo("Creating new database") db.create_all() print("Adding a new Site...") s = Site(name="Singularity Website", is_active=True) click.echo("Adding admin user") admin_role = Role(name="admin") db.session.add(admin_role) user = user_datastore.create_user(user_name='admin', email='admin@localhost', password='******', roles=[admin_role]) profile = Profile(first_name='Canella', last_name='User', user=user) db.session.add(profile) db.session.add(s) click.echo("Adding blog page") db.session.add(Page(title="Blog", content="<p>Blog</p>")) db.session.add(Page(title="Home", content="<h1>Home</h1>", slug='index')) click.echo("adding default category") db.session.add(Category(title="Uncategorized")) click.echo("Adding posts") cats = [ Category(title=t) for t in ['Life', 'Programming', 'Accessibility', 'Music', 'Books'] ] tags = [ Tag(title=t) for t in ['Python', 'Flask', 'Open-Source', 'H2G2', 'Armik', 'Aria'] ] for i, post in enumerate([ Post(title=t) for t in [ 'Who is Me?', 'Aria and HTML Standards', 'Mostly Harmless', 'Lost In Guitar', 'An Anatomy of The Life' ] ]): post.category = cats[i] post.body = '<p>'.join([silly.paragraph() for i in range(20)]) post.status = 'published' post.tags.update(set([random.choice(tags) for i in range(5)])) db.session.add(post) db.session.commit() click.echo("Process Completed!")
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 user_info(user: str = None, id: str = None): if id == None: set_id = uuid.uuid1() else: set_id = id if user is None: username: str = silly.name(capitalize=True) else: username = user title: str = silly.title(capitalize=True) company: str = silly.company(capitalize=True) address: str = silly.address(capitalize=True) city: str = silly.city(capitalize=True) country: str = silly.country(capitalize=True) postal_code: str = silly.postal_code() email = silly.email() phone = silly.phone_number() description: str = silly.paragraph(length=3) website = f'http://www.{silly.domain()}' create_date = f'{silly.datetime().year}/{silly.datetime().month}/{silly.datetime().day}' result = { 'useId': str(set_id), 'username': username, 'title': title, 'company': company, 'address': address, 'city': city, 'country': country, 'postal': postal_code, 'email': email, 'phone': phone, 'website': website, 'description': description, 'dateCreate': create_date } return result
def user_test_info(): set_id = str(uuid.uuid1()) rand_name: str = silly.noun() rand_num: int = random.randint(1, 10000) username: str = f"{rand_name}-{rand_num}" first_name: str = silly.verb() last_name: str = rand_name password: str = f"{silly.verb()}-{silly.noun()}" title: str = silly.title(capitalize=True) company: str = silly.company(capitalize=True) address: str = silly.address(capitalize=True) city: str = silly.city(capitalize=True) country: str = silly.country(capitalize=True) postal_code: str = silly.postal_code() email = silly.email() phone = silly.phone_number() description: str = silly.paragraph(length=1) website = f"https://www.{silly.domain()}" result = { "user_id": set_id, "user_name": username, "first_name": first_name, "last_name": last_name, "password": password, "title": title, "company": company, "address": address, "city": city, "country": country, "postal": postal_code, "email": email, "phone": phone, "website": website, "description": description, "is_active": random.choice([True, False]), } return result
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)