示例#1
0
    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 = "%s %s" % (car.manuf, car.name)
        a.car = car
        a.tier = car.tier
        a.details = json.dumps(
            {"engine": str(car.engine_up), "product_type": "car", "hp": str(car.power_bhp), "year": str(car.year),
             "product_id": int(car.id)})
        a.start_price = int(car.tier) * 4000
        if int(car.tier) == 6:
            a.start_price = 50000
        a.current_price = a.start_price
        a.end_at = datetime.datetime.now() + datetime.timedelta(days=days, hours=random.randint(0, 12),
                                                                minutes=random.randint(0, 60))
        a.save()
示例#2
0
def sell(request, item_type, item_id):
    from auction.models import Auction
    from common.models import Car
    from job.models import Garage

    item = Car.objects.get_by_id(item_id)
    garage = Garage.objects.get_by_user(user=request.engine.user.user)

    if item is None or not garage.has_car(item.id):
        return request.engine.redirect(reverse('garage'))

    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.manuf, item.name)
            a.seller = request.engine.user.user
            a.car = item
            a.tier = item.tier
            a.start_price = form.cleaned_data.get('start_price') or 0
            a.buy_it_now_price = form.cleaned_data.get('buy_it_now_price') or 0
            a.current_price = form.cleaned_data['start_price']
            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.engine = request.engine
            garage.remove_car(item.id)
            request.engine.user.profile.cars = len(garage)
            request.engine.user.profile.save()

            return request.engine.redirect(reverse('auction'))

    return {
        'item_type': item_type,
        'item_id': item_id,
        'item': item,
        'form': form,
    }
示例#3
0
def sell(request, item_type, item_id):
    from auction.models import Auction
    from common.models import Car
    from job.models import Garage

    item = Car.objects.get_by_id(item_id)
    garage = Garage.objects.get_by_user(user=request.engine.user.user)

    if item is None or not garage.has_car(item.id):
        return request.engine.redirect(reverse('garage'))

    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.manuf, item.name)
            a.seller = request.engine.user.user
            a.car = item
            a.tier = item.tier
            a.start_price = form.cleaned_data.get('start_price') or 0
            a.buy_it_now_price = form.cleaned_data.get('buy_it_now_price') or 0
            a.current_price = form.cleaned_data['start_price']
            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.engine = request.engine
            garage.remove_car(item.id)
            request.engine.user.profile.cars = len(garage)
            request.engine.user.profile.save()

            return request.engine.redirect(reverse('auction'))

    return {
        'item_type': item_type,
        'item_id': item_id,
        'item': item,
        'form': form,
    }