Beispiel #1
0
def create_auction(request):
    admin_id = request.user.id
    name = request.POST['name']
    type = request.POST['type']
    contents = request.POST['contents']
    start_datetime = request.POST['start-datetime']
    end_datetime = request.POST['end-datetime']
    min_bid = request.POST['min-bid']
    max_bid = request.POST['max-bid']
    file1 = request.FILES['image1']
    file2 = request.FILES['image2']
    file3 = request.FILES['image3']

    auction = Auction(
        admin_id=admin_id,
        name=name,
        type=type,
        contents=contents,
        image1=file1,
        image2=file2,
        image3=file3,
        state='준비',
        start_datetime=start_datetime,
        end_datetime=end_datetime,
        min_bid=min_bid,
        max_bid=max_bid,
    )
    auction.save()

    return HttpResponseRedirect('/')
Beispiel #2
0
def saveAuction(request):
    option = request.POST.get('option', '')
    if option == 'Yes':
        title = request.POST.get('title', '')
        description = request.POST.get('description', '')
        minimum_price = request.POST.get('minimum_price', '')
        deadline_date = request.POST.get('deadline_date', '')
        deadline = datetime.strptime(
            deadline_date, '%Y-%m-%d %H:%M:%S')  #deadline in format required
        if deadline < (datetime.now() + timedelta(hours=72)
                       ):  #Checking that deadline meets requirements
            saveAuctionMessage = _(
                "Deadline must be at least 72 hours from now")
            return render(request, 'save_auction.html', {
                'title': title,
                'saveAuctionMessage': saveAuctionMessage
            })
        else:
            auct = Auction(seller=request.user,
                           title=title,
                           description=description,
                           minimum_price=minimum_price,
                           deadline_date=deadline_date)
            auct.save()
            send_mail(
                'Auction added successfully.',
                'Auction titled ' + str(auct.title) +
                ' added successfully. Description: ' + str(auct.description) +
                '. Link to your auction: http://127.0.0.1:8000/auction/' +
                str(auct.id), '*****@*****.**',
                [request.user.email])  #Sending link to auction
            return HttpResponseRedirect(reverse("auction:index"))
    else:
        return HttpResponseRedirect(reverse("auction:index"))
Beispiel #3
0
def confirmauction(request):
    if request.user.is_authenticated:
        option = request.POST.get('option', '')
        if option == 'Yes':
            seller = request.user
            title = request.POST.get('title', '')
            description = request.POST.get('description', '')
            minimum_price = request.POST.get('minimum_price').replace(',', '.')
            deadline_date = datetime.strptime(
                request.POST.get('deadline_date'), '%d.%m.%Y %H:%M:%S')
            edit_link = ''.join(
                random.choice(string.ascii_letters) for i in range(8))

            new_auction = Auction(seller=seller,
                                  title=title,
                                  description=description,
                                  minimum_price=minimum_price,
                                  deadline_date=deadline_date,
                                  edit_link=edit_link)
            new_auction.save()

            editlink = "http://127.0.0.1:8000/auction/edit/" + str(
                new_auction.id) + "/" + edit_link + "/"
            send_mail("Auction created",
                      "Your auction has been listed" +
                      "Edit your auction description here: " + editlink,
                      "*****@*****.**", [request.user.email],
                      fail_silently=False)

            return HttpResponseRedirect(reverse('index'))
        else:
            auction_form = CreateAuctionForm()
            return render(request, "createauction.html",
                          {'auction_form': auction_form})
Beispiel #4
0
def product_auction_create(request):

    if request.method == 'POST':
        data = JSONParser().parse(request)

        name = data['name']
        price = data['price']
        price_step = data['price_step']
        userId = data['userId']
        organizationId = data['organizationId']
        categoryId = data['categoryId']
        exp_time = data['exp_time']
        info = data['info']

        newProduct = Product(name=name,
                             detail=info,
                             price=price,
                             auction=1,
                             owner_id=userId,
                             organization_id=organizationId,
                             category_id=categoryId,
                             created_time=datetime.now())
        newProduct.save()

        serializerNewProduct = ProductSerializer(newProduct)

        newAuction = Auction(exp_time=datetime.fromtimestamp(float(exp_time)),
                             lastest_price=price,
                             price_step=price_step,
                             product_id=newProduct.pk)
        newAuction.save()

        return JsonResponse(serializerNewProduct.data, status=201)
Beispiel #5
0
    def test_auctionBid(self):

        client = Client()
        client.get(reverse('home'))

        login = client.login(username='******', password='******')
        self.assertTrue(login)

        auction = Auction(title="test",
                          description="description",
                          seller=User.objects.create(
                              first_name='seller',
                              email="*****@*****.**",
                              password="******"),
                          minPrice="2.0",
                          deadline="2019-01-01 12:00",
                          state="active",
                          version=0)
        auction.save()

        client.get(reverse("bid_auction", kwargs={"id": 1}))
        response = client.post(reverse("bid_auction", kwargs={"id": 1}), {
            "newBid": "50.0",
            "version": 0,
            "auction": auction
        },
                               follow=True)
        self.assertContains(response, "Highest bid:  50.0")
Beispiel #6
0
    def get(self, auction_id):
        auction = Auction.objects(auction_id=auction_id).first()
        server = auction.get_crypto_server()
        next_bidder_key = None
        if auction.current_state is None:
            auction.current_bid = 1
            first_bidder_key = \
                    auction.bidder_public_keys[0]
            blob = server.initialize(pickle.loads(first_bidder_key))
            auction.current_state = pickle.dumps(
                server.initialize(pickle.loads(first_bidder_key)))

        if auction.current_bid < len(auction.bidder_public_keys):
            next_bidder_key = auction.bidder_public_keys[auction.current_bid]

        payload = {
            'blob': auction.current_state,
            'bid_values': auction.bid_range,
            'seller_address': auction.account
        }

        auction.save()
        if next_bidder_key is not None:
            payload['next_bidder_key'] = next_bidder_key
        return json.dumps(payload)
Beispiel #7
0
 def post(self):
     bid_range = list(range(int(request.form['startingBid']), int(request.form['maxBid']) + 1))
     file = request.files['image']
     filename = None
     if file:
         filename = secure_filename(file.filename)
         full_path = os.path.join(get_upload_folder(), filename)
         file.save(full_path)
     while True:
         auction_id = random.randint(1,10**5)
         if not Auction.objects(auction_id=auction_id):
             break
     auction = Auction(name=request.form['name'],
             account=request.form['account'],
             description=request.form['description'], auction_id=auction_id,
             bid_range=bid_range, picture_filename=filename)
     auction.save()
     return render_template('create.html', message = 'Auction #{} successfully created'.format(auction_id))
Beispiel #8
0
 def post(self, auction_id):
     key = request.form['public_key']
     auction = Auction.objects(auction_id=auction_id).first()
     auction.bidder_public_keys.append(key)
     auction.save()
     bidder_id = len(auction.bidder_public_keys)
     server = auction.get_crypto_server()
     server_key = pickle.dumps(server.export_key())
     payload = {'server_key': server_key, 'bidder_id': bidder_id}
     return json.dumps(payload)
Beispiel #9
0
def create_auction(request):
    admin_id = request.user.id
    name = request.POST['name']
    contents = request.POST['contents']
    start_datetime = request.POST['start-datetime']
    end_datetime = request.POST['end-datetime']
    min_bid = request.POST['min-bid']
    max_bid = request.POST['max-bid']

    auction = Auction(admin_id=admin_id,
                      name=name,
                      contents=contents,
                      start_datetime=start_datetime,
                      end_datetime=end_datetime,
                      min_bid=min_bid,
                      max_bid=max_bid)
    auction.save()

    return HttpResponseRedirect('/')
Beispiel #10
0
 def post(self, auction_id):
     auction = Auction.objects(auction_id=auction_id).first()
     blob = request.form['blob']
     auction.current_state = blob
     auction.current_bid += 1
     auction.save()
     if auction.current_bid > len(auction.bidder_public_keys):
         server = auction.get_crypto_server()
         blob = server.finalize(pickle.loads(blob))
         auction.current_state = pickle.dumps(blob)
         return str(blob)
     return ''
Beispiel #11
0
 def post(self, auction_id):
     auction = Auction.objects(auction_id=auction_id).first()
     blob = request.form['blob']
     auction.current_state = blob
     auction.current_bid += 1
     auction.save()
     if auction.current_bid > len(auction.bidder_public_keys):
         server = auction.get_crypto_server()
         blob = server.finalize(pickle.loads(blob))
         auction.current_state = pickle.dumps(blob)
         return str(blob)
     return ''
Beispiel #12
0
 def post(self, auction_id):
     key = request.form['public_key']
     auction = Auction.objects(auction_id=auction_id).first()
     auction.bidder_public_keys.append(key)
     auction.save()
     bidder_id = len(auction.bidder_public_keys)
     server = auction.get_crypto_server()
     server_key = pickle.dumps(server.export_key())
     payload = {
             'server_key': server_key,
             'bidder_id': bidder_id
         }
     return json.dumps(payload)
Beispiel #13
0
 def post(self):
     bid_range = list(
         range(int(request.form['startingBid']),
               int(request.form['maxBid']) + 1))
     file = request.files['image']
     filename = None
     if file:
         filename = secure_filename(file.filename)
         full_path = os.path.join(get_upload_folder(), filename)
         file.save(full_path)
     while True:
         auction_id = random.randint(1, 10**5)
         if not Auction.objects(auction_id=auction_id):
             break
     auction = Auction(name=request.form['name'],
                       account=request.form['account'],
                       description=request.form['description'],
                       auction_id=auction_id,
                       bid_range=bid_range,
                       picture_filename=filename)
     auction.save()
     return render_template(
         'create.html',
         message='Auction #{} successfully created'.format(auction_id))
Beispiel #14
0
 def handle(self, *args, **options):
     first_id = 0
     for i in range(1, 51):
         User.objects.create_user('user' + str(i),
                                  'user' + str(i) + '@example.com',
                                  'very_easy_password').save()
         auction_user = AuctionUser(user=User.objects.get(username='******' +
                                                          str(i)))
         auction_user.save()
         auction = Auction(seller=auction_user.user.username,
                           title='auction' + str(i),
                           item_description='Item description.',
                           price=Decimal(0.00),
                           deadline=timezone.now() + timedelta(days=30))
         auction.save()
         if i == 1:
             first_id = auction.id
     for i in range(0, 10):
         auction = Auction.objects.get(pk=first_id + i)
         auction.price += Decimal('0.01')
         user = User.objects.get(username='******' + str(i + 2))
         auction.add_bidder(user.pk)
         auction.last_bidder = user.username
         auction.save()
Beispiel #15
0
def auction_save(request: HttpRequest, auction_id: int):
    if auction_id == 0:
        auction = Auction(user=request.user)
    else:
        try:
            auction = Auction.objects.get(pk=auction_id)
        except Auction.DoesNotExist:
            return redirect('auction_edit', auction_id=auction_id)
        if auction.user.id != request.user.id or auction.started:
            return redirect('home')

    form = AuctionForm(data=request.POST, instance=auction)
    if not form.is_valid():
        request.session['auction_form_data'] = request.POST
        return redirect('auction_edit', auction_id=auction_id)

    auction = form.save()
    if auction_id == 0 and not auction.started:
        request.session['open_gallery_tab'] = True
        return redirect('auction_edit', auction_id=auction.id)
    else:
        return redirect('auction', auction_id=auction.id)
Beispiel #16
0
    def get(self, auction_id):
        auction = Auction.objects(auction_id=auction_id).first()
        server = auction.get_crypto_server()
        next_bidder_key = None
        if auction.current_state is None:
            auction.current_bid = 1
            first_bidder_key = \
                    auction.bidder_public_keys[0]
            blob = server.initialize(pickle.loads(first_bidder_key))
            auction.current_state = pickle.dumps(server.initialize(pickle.loads(first_bidder_key)))

        if auction.current_bid < len(auction.bidder_public_keys):
            next_bidder_key = auction.bidder_public_keys[auction.current_bid]

        payload = {
                'blob': auction.current_state,
                'bid_values': auction.bid_range,
                'seller_address': auction.account
            }

        auction.save()
        if next_bidder_key is not None:
            payload['next_bidder_key'] = next_bidder_key
        return json.dumps(payload)
Beispiel #17
0
        image_src = row[1].strip()
        address = row[2].strip()
        town = row[3].strip()
        postcode = row[4].strip()
        description = row[5].strip()
        guide_price = row[6].strip()
        try:
            price = float(row[7].strip())
        except:
            price = None
        auctioneer = row[8].strip()
        auction_date = datetime.strptime(row[9], '%d %B %Y')
        lease_details = row[10].strip()
        vendor = row[11].strip()

        # exists = Geocode.objects.filter(postcode=postcode)
        # if not exists:
        A = Auction(lot=lot,
                    image_src=image_src,
                    address=address,
                    town=town,
                    postcode=postcode,
                    description=description,
                    guide_price=guide_price,
                    price=price,
                    auctioneer=auctioneer,
                    auction_date=auction_date,
                    lease_details=lease_details,
                    vendor=vendor)
        A.save()
Beispiel #18
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,
    }
Beispiel #19
0
def auction_list(request):
    auctions = Auction.objects.all().order_by('start_time')
    for auction in auctions:
        Auction.create_auctionReady(auction)
        Auction.end_of_auction(auction)
    return render(request, 'auction/auction_list.html', {'auctions': auctions})
Beispiel #20
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,
    }
Beispiel #21
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()
        town = row[3].strip()
        postcode = row[4].strip()
        description = row[5].strip()
        guide_price = row[6].strip()
        try:
            price = float(row[7].strip())
        except:
            price = None
        auctioneer = row[8].strip()
        auction_date = datetime.strptime(row[9], '%d %B %Y')
        lease_details = row[10].strip()
        vendor = row[11].strip()

        # exists = Geocode.objects.filter(postcode=postcode)
        # if not exists:
        A = Auction(
            lot=lot,
            image_src=image_src,
            address=address,
            town=town,
            postcode=postcode,
            description=description,
            guide_price=guide_price,
            price=price,
            auctioneer=auctioneer,
            auction_date=auction_date,
            lease_details=lease_details,
            vendor=vendor
        )
        A.save()