Beispiel #1
0
def mass_add(request):
    c = {}
    c['tab'] = 'books'
    c['user'] = request.user
    c.update(csrf(request))

    if request.method == 'POST':
        post = request.POST
        isbn = post['isbn']
        amazon = AmazonController()

        product = None
        added = False

        #if len(isbn) == 10:
        #product = amazon.lookup(isbn)
        #elif len(isbn) == 13:
        product = amazon.lookup(isbn, 'ISBN', 'Books')

        if product:
            if type(product) is ListType:
                product_list = product
            else:
                product_list = []
                product_list.append(product)

            for product in product_list:
                if len(product_list) > 1:
                    try:
                        product.item.LargeImage['URL']
                    except AttributeError:
                        continue

                    details = get_details(product)
                    if not details['author']:
                        continue
                    if not details['desc']:
                        continue

                else:
                    details = get_details(product)

                book = Book.objects.create(
                    title=details['title'],
                    author=details['author'],
                    format=details['format'],
                    publisher=details['publisher'],
                    publication_year=details['year'],
                    isbn=isbn,
                    updated_by=request.user,
                    description=details['desc'],
                )
                if book:
                    added = True

                # Get image
                try:
                    image_url = str(product.item.LargeImage['URL'])
                    urllib.urlretrieve(
                        image_url,
                        settings.MEDIA_ROOT + "/book/" + str(book.id) + ".jpg")
                except AttributeError:
                    pass

                c['book'] = book
                return render_to_response('book/mass_add.html', c)

        else:
            c['error'] = "Unable to find ISBN %s." % (isbn)

    return render_to_response('book/mass_add.html', c)
Beispiel #2
0
def mass_add(request):
    c = {}
    c['tab'] = 'videogames'
    c['user'] = request.user
    c.update(csrf(request))

    if request.method == 'POST':
        post = request.POST
        upc = post['upc']
        amazon = AmazonController()

        product = None
        added = False

        if post['upc'][:1].isdigit():
            product = amazon.lookup("0" + upc, "EAN", "Blended")
        else:
            product = amazon.lookup(upc, "ASIN")

        if product:
            if type(product) is ListType:
                product_list = product
            else:
                product_list = []
                product_list.append(product)

            for product in product_list:
                if len(product_list) > 1:
                    try:
                        product.item.LargeImage['URL']
                    except AttributeError:
                        continue

                    details = get_details(product)
                    if not details['developer']:
                        continue
                    if not details['desc']:
                        continue

                else:
                    details = get_details(product)

                videogame = VideoGame.objects.create(
                    title=details['title'],
                    developer=details['developer'],
                    media_type=details['media_type'],
                    platform=details['platform'],
                    publisher=details['publisher'],
                    publication_year=details['year'],
                    upc=upc,
                    updated_by=request.user,
                    description=details['desc'],
                )
                if videogame:
                    added = True

                # Get image
                try:
                    image_url = str(product.item.LargeImage['URL'])
                    urllib.urlretrieve(
                        image_url, settings.MEDIA_ROOT + "/videogame/" +
                        str(videogame.id) + ".jpg")
                except AttributeError:
                    pass

                c['videogame'] = videogame
                return render_to_response('videogame/mass_add.html', c)

        else:
            c['error'] = "Unable to find UPC %s." % (upc)

    return render_to_response('videogame/mass_add.html', c)
Beispiel #3
0
def mass_add(request):
    c = {}
    c['tab'] = 'books'
    c['user'] = request.user
    c.update(csrf(request))

    if request.method == 'POST':
        post = request.POST
        isbn = post['isbn']
        amazon = AmazonController()

        product = None
        added = False

        #if len(isbn) == 10:
            #product = amazon.lookup(isbn)
        #elif len(isbn) == 13:
        product = amazon.lookup(isbn, 'ISBN', 'Books')

        if product:
            if type(product) is ListType:
                product_list = product
            else:
                product_list = []
                product_list.append(product)

            for product in product_list:
                if len(product_list) > 1:
                    try:
                        product.item.LargeImage['URL']
                    except AttributeError:
                        continue

                    details = get_details(product)
                    if not details['author']:
                        continue
                    if not details['desc']:
                        continue

                else:
                    details = get_details(product)

                book = Book.objects.create(
                    title = details['title'],
                    author = details['author'],
                    format = details['format'],
                    publisher = details['publisher'],
                    publication_year = details['year'],
                    isbn = isbn,
                    updated_by = request.user,
                    description = details['desc'],
                    )
                if book:
                    added = True

                # Get image
                try:
                    image_url = str(product.item.LargeImage['URL'])
                    urllib.urlretrieve(image_url, settings.MEDIA_ROOT + "/book/" + str(book.id) + ".jpg")
                except AttributeError:
                    pass

                c['book'] = book
                return render_to_response('book/mass_add.html', c)

        else:
            c['error'] = "Unable to find ISBN %s." % (isbn)

    return render_to_response('book/mass_add.html', c)
Beispiel #4
0
def mass_add(request):
    c = {}
    c['tab'] = 'videogames'
    c['user'] = request.user
    c.update(csrf(request))

    if request.method == 'POST':
        post = request.POST
        upc = post['upc']
        amazon = AmazonController()

        product = None
        added = False

        if post['upc'][:1].isdigit():
            product = amazon.lookup("0" + upc, "EAN", "Blended")
        else:
            product = amazon.lookup(upc, "ASIN")

        if product:
            if type(product) is ListType:
                product_list = product
            else:
                product_list = []
                product_list.append(product)

            for product in product_list:
                if len(product_list) > 1:
                    try:
                        product.item.LargeImage['URL']
                    except AttributeError:
                        continue

                    details = get_details(product)
                    if not details['developer']:
                        continue
                    if not details['desc']:
                        continue

                else:
                    details = get_details(product)

                videogame = VideoGame.objects.create(
                    title = details['title'],
                    developer = details['developer'],
                    media_type = details['media_type'],
                    platform = details['platform'],
                    publisher = details['publisher'],
                    publication_year = details['year'],
                    upc = upc,
                    updated_by = request.user,
                    description = details['desc'],
                    )
                if videogame:
                    added = True

                # Get image
                try:
                    image_url = str(product.item.LargeImage['URL'])
                    urllib.urlretrieve(image_url, settings.MEDIA_ROOT + "/videogame/" + str(videogame.id) + ".jpg")
                except AttributeError:
                    pass

                c['videogame'] = videogame
                return render_to_response('videogame/mass_add.html', c)

        else:
            c['error'] = "Unable to find UPC %s." % (upc)

    return render_to_response('videogame/mass_add.html', c)