def _create_deals(self): ads = Ad.objects.all() for i in range(10): ad = random.choice(ads) while True: try: creator_user = random.choice(self.users) amount = random.randint(1,ad.amount) factor = random.uniform(0.85, 1.15) unit_price = float(ad.price) * factor bid = unit_price * amount bid = Decimal(bid).quantize(Decimal('.00')) deal = Deal( ad=ad, creator=creator_user.get_userprofile(), owner=creator_user.get_business_profile(), bid=bid, currency=ad.currency, amount=amount ) deal.save() except IntegrityError: continue break self.deals = Deal.objects.all()
try: user = User.objects.using(database).get(id=user_id) except: print "[ERROR] Invalid user: %s" % user_id continue user_profile = user.get_userprofile() business_profile = BusinessProfile.objects.using(database).get(id=user_profile.active_profile_id) try: ad = Ad.objects.using(database).get(id=ad_id) except: print "[ERROR] Invalid ad: %s" % ad_id continue d = Deal() d.creator = user_profile d.owner = business_profile d.ad = ad if status == 'done': status = 'completed' elif status == 'aborted': status = 'canceled' d.state = status d.created = ts_to_datetime(created) d.updated = ts_to_datetime(updated) d.last_reminder = ts_to_datetime(last_reminder)