def __add_auction(self, car): if car.tier in (1, 2): days = 1 elif car.tier in (3, 4): days = 2 else: days = 3 a = Auction() a.seller = SELLER a.title = car.name[:50] det = json.loads(car.details) if det.has_key('bhp'): det['hp'] = det['bhp'] if not det.has_key('look'): det['look'] = 5 a.details = json.dumps( {"engine": det['engine'], "product_type": "car", "look": det['look'], "hp": det['hp'], "year": det['year'], "product_id": int(car.id)}) a.respect = car.respect a.start_price = car.price a.current_price = car.price a.end_at = datetime.datetime.now() + datetime.timedelta(days=days, hours=random.randint(0, 12), minutes=random.randint(0, 60)) a.save()
def sell(request, item_type, item_id): import simplejson as json from crims.auction.models import Auction from crims.item.models import Item, Garage item = Item.objects.get_by_id(item_id) garage = Garage.objects.get_by_user(user=request.engine.user.user) if item is None or str(item.id) not in garage.items: return request.engine.redirect(reverse('garage')) details = json.loads(item.details) details['product_id'] = item.id item.details = json.dumps(details) form = SellForm() if request.method == 'POST' and request.POST.has_key('duration'): form = SellForm(request.POST) if form.is_valid(): a = Auction() a.title = "%s / %s" % (item.name, request.engine.user.user) a.details = item.details a.respect = item.respect a.image_filename = item.image_filename a.seller = request.engine.user.user a.start_price = form.cleaned_data['start_price'] a.current_price = form.cleaned_data['start_price'] a.image_filename = item.image_filename a.is_for_credits = False a.is_refunded = False a.start_at = datetime.datetime.now() a.end_at = datetime.datetime.now() + datetime.timedelta(days=int(form.cleaned_data['duration'])) a.save() garage.sell_item(item.id) request.engine.user.recalculate_total() return request.engine.redirect(reverse('auction')) return render_to_response( 'auction/sell.html', { 'item_type': item_type, 'item_id': item_id, 'item': item, 'details': json.loads(item.details), 'form': form, }, context_instance=RequestContext(request) )