Esempio n. 1
0
def editbook(request,id):
    b = get_object_or_404(Book,asin=id)
    set_up_dist(b)
    book_conds = ConditionForBook.objects.filter(book = b).all()

    if request.method == 'POST':
        if request.POST.get('submit',None) == "Update Price and Condition":
            b.price = request.POST.get('price','')
            b.location = request.POST.get('location',None)
            b.condition = request.POST.get('condition',None)
            b.owner = User.objects.get(id=request.POST.get('owner','').strip())
            request.user.message_set.create(message="Updated %s" % b.title)
        elif request.POST.get('submit',None) == "Update":
            #print "would update",b.halfid,"on Half.com"
            from booksell.production import EBAY_DEVID, EBAY_APPID, EBAY_CERTID, EBAY_XML_GATEWAY, EBAY_XML_DIR,EBAY_TOKEN
            from ebay import EbaySession
            ebay = EbaySession(EBAY_DEVID,EBAY_APPID,EBAY_CERTID,EBAY_XML_GATEWAY,EBAY_XML_DIR,EBAY_TOKEN)
            res = ebay.reviseItem(id= b.id, isbn = b.isbn, price=str(b.price), condition = b.condition, comments= b.condition_note)
            b.price = str(b.price)  # hack
            request.user.message_set.create(message="Updated %s at half.com" % b.title)
        elif request.POST.get('submit',None) == "Post":
            #print "post to Half.com"
            from booksell.production import EBAY_DEVID, EBAY_APPID, EBAY_CERTID, EBAY_XML_GATEWAY, EBAY_XML_DIR,EBAY_TOKEN
            from ebay import EbaySession
            ebay = EbaySession(EBAY_DEVID,EBAY_APPID,EBAY_CERTID,EBAY_XML_GATEWAY,EBAY_XML_DIR,EBAY_TOKEN)
            res = ebay.addItem(id= b.id, isbn = b.isbn, price=str(b.price), condition = b.condition, comments= b.condition_note)
            b.halfid = res['halfid']
            b.price = str(b.price)  # hack
            request.user.message_set.create(message="Posted %s to half.com" % b.title)
        b.save()
    form = BookForm(instance=b)
    tags = ['cover','spine', 'edge','pages','"other conditions"','extras','"generic age"','shipping',]
    return render_to_response('book_detail.html', \
        { 'book' : b, 'book_conds' : book_conds, 'form' : form, 'tags' : tags }, \
        context_instance=RequestContext(request))
Esempio n. 2
0
def bulk_update(request):
    BookFormSet = modelformset_factory(Book, fields=['title','location','condition', 'oldprice', 'price'], extra=0)
    if request.method == 'POST':
        formset = BookFormSet(request.POST)
        if formset.is_valid():
            print "valid"
            updated = formset.save()
            if request.POST.get('submit',None) == "Update":
                for b in updated:
                    if b.halfid:
                        from booksell.production import EBAY_DEVID, EBAY_APPID, EBAY_CERTID, EBAY_XML_GATEWAY, EBAY_XML_DIR,EBAY_TOKEN
                        from ebay import EbaySession
                        ebay = EbaySession(EBAY_DEVID,EBAY_APPID,EBAY_CERTID,EBAY_XML_GATEWAY,EBAY_XML_DIR,EBAY_TOKEN)
                        res = ebay.reviseItem(id= b.id, isbn = b.isbn, price=str(b.price), condition = b.condition, comments= b.condition_note)
                        request.user.message_set.create(message="Updated %s at half.com" % b.title)
            elif request.POST.get('submit',None) == "Post to half.com":
                for b in Book.objects.filter(solddate__isnull = True, halfid__isnull = True).all():
                    if str(b.price) != 'None' and str(b.condition) != 'None':
                        print "would post",b.title,' %s/%s to half.com' % (str(b.price),b.condition)
                        from booksell.production import EBAY_DEVID, EBAY_APPID, EBAY_CERTID, EBAY_XML_GATEWAY, EBAY_XML_DIR,EBAY_TOKEN
                        from ebay import EbaySession
                        ebay = EbaySession(EBAY_DEVID,EBAY_APPID,EBAY_CERTID,EBAY_XML_GATEWAY,EBAY_XML_DIR,EBAY_TOKEN)
                        res = ebay.addItem(id= b.id, isbn = b.isbn, price=str(b.price), condition = b.condition, comments= b.condition_note)
                        b.halfid = res['halfid']
                        b.price = str(b.price)  # hack
                        request.user.message_set.create(message="Posted %s to half.com" % b.title)
                        b.save()
            # do something.
            books = Book.objects.filter(solddate__isnull = True).order_by('location','title')
            for b in books:
                if b.condition != None:
                    set_up_dist(b,b.condition)
            formset = BookFormSet(queryset = books)
        else:
            print "was not valid"
    else:
        books = Book.objects.filter(solddate__isnull = True).order_by('location','title')
        for b in books:
            if b.condition != None:
                prices = b.pricelist_for_half(b.condition)
                print 'price',b.title
                if len(prices) >= 4:
                    already = False
                    for p,seller in prices[:4]:
                        print "  price",p,"seller",seller
                        if str(seller) == 'junshinco':
                            already = True
                    if not already:
                        p,s = prices[3]
                        if p > 0.75:
                            newprice = p - .01
                        else:
                            newprice = p
                        print '  update price',newprice
                        b.update_price(newprice)
                set_up_dist(b,b.condition)

        formset = BookFormSet(queryset = books)

    return render_to_response('bulk_update.html', \
        { 'formset' : formset}, \
        context_instance=RequestContext(request))