Beispiel #1
0
def fixitems(cursor=None, num_updated=0):
    query = Item.all()
    if cursor:
        query.with_cursor(cursor)
    to_put = []
    for item  in query.fetch(limit=100):
      if (item.disable == None):
        item.disable = False
      if (item.ebayid == None):
        item.ebayid = ""
      if (item.ebayid == ""):
        item.disable = True
      img = item.getImage(0)
      if img:
        img = ImageData(image=item.picture,name=item.name,parent=item,idx=0) 
      item.picture = None
      to_put.append(item)
    if to_put:
        db.put(to_put)
        num_updated += len(to_put)
        logging.debug(
            'Scan %d entities to Datastore for a total of %d',
            len(to_put), num_updated)
        deferred.defer(
            fixitems, cursor=query.cursor(), num_updated=num_updated)
    else:
        logging.debug(
            'Scan items complete with %d updates!', num_updated)
        return None
Beispiel #2
0
def item(request, shop, key):
    stories = getCategoriesInfo()
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if item:
        upload_url = '/admin/blobimage/' + shop + "/" + key + "/0/"
        upload_url1 = '/admin/blobimage/' + shop + "/" + key + "/1/"
        upload_url2 = '/admin/blobimage/' + shop + "/" + key + "/2/"
        upload_url3 = '/admin/blobimage/' + shop + "/" + key + "/3/"
        dict = {
            'ITEM': item,
            'STORIES': stories,
            'BLOBURL': upload_url,
            'BLOBURL1': upload_url1,
            'BLOBURL2': upload_url2,
            'BLOBURL3': upload_url3
        }
        dict['STORIES'] = stories
        context = Context(dict)
        response = render_to_response("admin/itemfull.html",
                                      context,
                                      context_instance=RequestContext(request))
        response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
        return response
    else:
        return retailError(request, "item not found")
Beispiel #3
0
def fetchimage(request, shop, key, index="0"):
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    picture = None
    idx = int(index)
    if item:
        image = item.getImage(idx)
        if image:
            if ("sc" in request.GET):
                if image.small:
                    picture = image.small
                elif image.image:
                    image.small = createsc(image.image)
                    try:
                        image.put()
                    except RequestTooLargeError:
                        pic = rescale(image.image, 600, 600)
                        image.image = pic
                        image.put()
                        del pic
                    picture = image.small
                else:
                    picture = None
            else:
                picture = image.image
        else:
            picture = None
    else:
        picture = None
    if picture:
        return HttpResponse(picture, mimetype="image/jpeg")
    else:
        return HttpResponseRedirect('/static/res/picnotfound.jpg')
Beispiel #4
0
def blobimage(request, shop, key, index='0'):
    registerAdminAction(request, "blobimage", shop + "/" + key)
    #file = request.FILES['image'].read()
    #type = request.FILES['image'].content_type
    #image = request.FILES['image'].content_type_extra
    file = request.FILES['image'].read()
    picture = rescale(file, 600, 600)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    idx = int(index)
    if item:
        img = item.getImage(idx)
        if img:
            img.image = picture
        else:
            img = ImageData(image=picture,
                            name=item.name,
                            parent=item,
                            idx=idx)
            img.url = "http://" + request.META[
                'HTTP_HOST'] + "/admin/fetchimage/" + shop + "/" + key + "/" + str(
                    idx)
        img.small = createsc(picture)
        img.put()
        del picture
        item.galleryurl = img.url
        item.put()
        return HttpResponse("ok")
    else:
        return HttpResponse("fail")
Beispiel #5
0
def syncwithebay(request, shop, key):
    registerAdminAction(request, "ebayexport", shop + "/" + key)
    info = ebay.getEbayInfo(request)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if item:
        rslt = sync(info, item)
        return rslt
Beispiel #6
0
def fixitems(cursor=None, num_updated=0):
    query = Item.all()
    if cursor:
        query.with_cursor(cursor)
    to_put = []
    for item in query.fetch(limit=100):
        if (item.disable == None):
            item.disable = False
        if (item.ebayid == None):
            item.ebayid = ""
        if (item.ebayid == ""):
            item.disable = True
        img = item.getImage(0)
        if img:
            img = ImageData(image=item.picture,
                            name=item.name,
                            parent=item,
                            idx=0)
        item.picture = None
        to_put.append(item)
    if to_put:
        db.put(to_put)
        num_updated += len(to_put)
        logging.debug('Scan %d entities to Datastore for a total of %d',
                      len(to_put), num_updated)
        deferred.defer(fixitems,
                       cursor=query.cursor(),
                       num_updated=num_updated)
    else:
        logging.debug('Scan items complete with %d updates!', num_updated)
        return None
Beispiel #7
0
def syncwithebay(request,shop,key):
  registerAdminAction(request,"ebayexport",shop+"/"+key)
  info = ebay.getEbayInfo(request)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if item:
    rslt = sync(info,item)
    return rslt
Beispiel #8
0
def fetchimage(request,shop,key,index="0"):
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  picture = None
  idx = int(index)
  if item:
    image = item.getImage(idx)
    if image:
      if ("sc" in request.GET):
         if image.small:
            picture = image.small
         elif image.image:
            image.small = createsc(image.image)
            try:
              image.put()
            except RequestTooLargeError:
              pic = rescale(image.image,600,600)
              image.image = pic
              image.put()
              del pic
            picture = image.small
         else:
            picture = None
      else:
         picture = image.image
    else:
      picture = None
  else:
    picture = None
  if picture:
    return HttpResponse(picture, mimetype="image/jpeg")
  else:
    return  HttpResponseRedirect('/static/res/picnotfound.jpg')
Beispiel #9
0
def relisttoebay(request, shop, key):
    registerAdminAction(request, "ebayrelist", shop + "/" + key)
    info = ebay.getEbayInfo(request)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if item:
        if (item.ebayid and (item.ebayid != '0')):
            rslt, item = relist(info, item)
            return rslt
    return (returnError("item not find or not exists in ebay"))
Beispiel #10
0
def relisttoebay(request,shop,key):
  registerAdminAction(request,"ebayrelist",shop+"/"+key)
  info = ebay.getEbayInfo(request)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if item:
    if (item.ebayid and (item.ebayid != '0')):
      rslt,item = relist(info,item)
      return rslt
  return (returnError("item not find or not exists in ebay"))
Beispiel #11
0
def clean(request):
  items = Item.all()
  for item in items:
    item.name = item.name.replace("\n","").replace("\t","").replace("\r","")
    item.put()
  items = SupplierItem.all()
  for item in items:
    item.description = item.description.replace("\n","").replace("\t","").replace("\r","")
    item.put()
  return HttpResponse("over")
Beispiel #12
0
def rotateimage(request,shop,key,index="0"):
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  idx = int(index)
  if item:
    image = item.getImage(int(idx))
    if image:
      gimg = images.Image(image.image)
      gimg.rotate(90)
      image.image = gimg.execute_transforms()
      image.put()
  return HttpResponse("ok")
Beispiel #13
0
def rotateimage(request, shop, key, index="0"):
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    idx = int(index)
    if item:
        image = item.getImage(int(idx))
        if image:
            gimg = images.Image(image.image)
            gimg.rotate(90)
            image.image = gimg.execute_transforms()
            image.put()
    return HttpResponse("ok")
Beispiel #14
0
def clean(request):
    items = Item.all()
    for item in items:
        item.name = item.name.replace("\n", "").replace("\t",
                                                        "").replace("\r", "")
        item.put()
    items = SupplierItem.all()
    for item in items:
        item.description = item.description.replace("\n", "").replace(
            "\t", "").replace("\r", "")
        item.put()
    return HttpResponse("over")
Beispiel #15
0
def saveitem(request, shop, key):
    registerAdminAction(request, "saveitem", shop + "/" + key)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if (item):
        item.name = request.POST['name']
        item.refid = request.POST['refid']
        item.price = float(request.POST['price'])
        item.cost = float(request.POST['cost'])
        item.description = request.POST['description']
        item.specification = request.POST['spec']
        item.category = request.POST['category']
        item.category2 = request.POST['sndcategory']
        item.ebaycategory = request.POST['ebaycategory']
        item.disable = (True, False)[request.POST['disabled'] == "False"]
        item.put()
        indexItem(item)
    response = HttpResponseRedirect('/admin/item/' + shop + '/' + key + "/")
    return response
Beispiel #16
0
def itemimage(request,shop,key):
  suppliers = Supplier.all()
  stories = {}
  items = []
  for supply in suppliers:
    stories[supply.name] = json.loads(supply.data)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if(item):
    upload_url = '/admin/blobimage/'+ shop + "/" + key +"/0/"
    upload_url1 = '/admin/blobimage/'+ shop + "/" + key +"/1/"
    upload_url2 = '/admin/blobimage/'+ shop + "/" + key +"/2/"
    upload_url3 = '/admin/blobimage/'+ shop + "/" + key +"/3/"
    dict = {'ITEM':item,'STORIES':stories,'BLOBURL':upload_url
        ,'BLOBURL1':upload_url1
        ,'BLOBURL2':upload_url2
        ,'BLOBURL3':upload_url3}
    context = Context(dict)
    return (render_to_response("admin/image.html",context,context_instance=RequestContext(request)))
Beispiel #17
0
def saveitem(request,shop,key):
  registerAdminAction(request,"saveitem",shop+"/"+key)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if(item):
    item.name = request.POST['name']
    item.refid = request.POST['refid']
    item.price = float(request.POST['price'])
    item.cost = float(request.POST['cost'])
    item.description = request.POST['description']
    item.specification = request.POST['spec']
    item.category = request.POST['category']
    item.category2 = request.POST['sndcategory']
    item.ebaycategory = request.POST['ebaycategory']
    item.disable = (True,False)[request.POST['disabled'] == "False"]
    item.put()
    indexItem(item)
  response =  HttpResponseRedirect('/admin/item/'+ shop + '/' + key +"/")
  return response
Beispiel #18
0
def exporttoebay(request,shop,key):
  registerAdminAction(request,"ebayexport",shop+"/"+key)
  token = ebay.getToken(request)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if item:
    if (item.ebayid and (item.ebayid != '0')):
      info = ebay.getEbayInfo(request)
      rslt = sync(info,item)
      return HttpResponse(rslt,mimetype="text/xml")
    rslt = ebayapi.api.AddItem(token,item)
    xml_doc = etree.parse(StringIO(rslt))
    ack = xml_doc.xpath("//xs:Ack",
      namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0]
    if(not 'Failure' in ack.text):
      itemid = xml_doc.xpath("//xs:ItemID",
        namespaces={'xs':"urn:ebay:apis:eBLBaseComponents"})[0].text
      item.ebayid = itemid
      item.put()
    return HttpResponse(rslt,mimetype="text/xml")
Beispiel #19
0
def item(request,shop,key):
  stories = getCategoriesInfo()
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if item:
    upload_url = '/admin/blobimage/'+ shop + "/" + key +"/0/"
    upload_url1 = '/admin/blobimage/'+ shop + "/" + key +"/1/"
    upload_url2 = '/admin/blobimage/'+ shop + "/" + key +"/2/"
    upload_url3 = '/admin/blobimage/'+ shop + "/" + key +"/3/"
    dict = {'ITEM':item,'STORIES':stories,'BLOBURL':upload_url
        ,'BLOBURL1':upload_url1
        ,'BLOBURL2':upload_url2
        ,'BLOBURL3':upload_url3}
    dict['STORIES'] = stories
    context = Context(dict)
    response = render_to_response("admin/itemfull.html",context,context_instance=RequestContext(request))
    response['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    return response
  else:
    return retailError(request,"item not found")
Beispiel #20
0
def exporttoebay(request, shop, key):
    registerAdminAction(request, "ebayexport", shop + "/" + key)
    token = ebay.getToken(request)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if item:
        if (item.ebayid and (item.ebayid != '0')):
            info = ebay.getEbayInfo(request)
            rslt = sync(info, item)
            return HttpResponse(rslt, mimetype="text/xml")
        rslt = ebayapi.api.AddItem(token, item)
        xml_doc = etree.parse(StringIO(rslt))
        ack = xml_doc.xpath(
            "//xs:Ack", namespaces={'xs':
                                    "urn:ebay:apis:eBLBaseComponents"})[0]
        if (not 'Failure' in ack.text):
            itemid = xml_doc.xpath(
                "//xs:ItemID",
                namespaces={'xs': "urn:ebay:apis:eBLBaseComponents"})[0].text
            item.ebayid = itemid
            item.put()
        return HttpResponse(rslt, mimetype="text/xml")
Beispiel #21
0
def blobimage(request,shop,key,index='0'):
  registerAdminAction(request,"blobimage",shop+"/"+key)
  #file = request.FILES['image'].read()
  #type = request.FILES['image'].content_type
  #image = request.FILES['image'].content_type_extra
  file = request.FILES['image'].read()
  picture = rescale(file,600,600)
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  idx = int(index)
  if item:
    img = item.getImage(idx)
    if img:
      img.image = picture
    else:
      img = ImageData(image=picture,name=item.name,parent=item,idx=idx) 
      img.url = "http://" + request.META['HTTP_HOST'] + "/admin/fetchimage/" + shop + "/" + key + "/" + str(idx)
    img.small = createsc(picture)
    img.put()
    del picture
    item.galleryurl = img.url
    item.put()
    return HttpResponse("ok")
  else:
    return HttpResponse("fail")
Beispiel #22
0
def itemimage(request, shop, key):
    suppliers = Supplier.all()
    stories = {}
    items = []
    for supply in suppliers:
        stories[supply.name] = json.loads(supply.data)
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if (item):
        upload_url = '/admin/blobimage/' + shop + "/" + key + "/0/"
        upload_url1 = '/admin/blobimage/' + shop + "/" + key + "/1/"
        upload_url2 = '/admin/blobimage/' + shop + "/" + key + "/2/"
        upload_url3 = '/admin/blobimage/' + shop + "/" + key + "/3/"
        dict = {
            'ITEM': item,
            'STORIES': stories,
            'BLOBURL': upload_url,
            'BLOBURL1': upload_url1,
            'BLOBURL2': upload_url2,
            'BLOBURL3': upload_url3
        }
        context = Context(dict)
        return (render_to_response("admin/image.html",
                                   context,
                                   context_instance=RequestContext(request)))
Beispiel #23
0
def deleteitem(request,shop,key):
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  if item:
    deleteItemIndex(item)
    item.delete()
  return HttpResponseRedirect('/admin/items/'+shop)
Beispiel #24
0
def deleteitem(request, shop, key):
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    if item:
        deleteItemIndex(item)
        item.delete()
    return HttpResponseRedirect('/admin/items/' + shop)
Beispiel #25
0
def item(request, shop, key):
    stories = getCategoriesInfo()
    item = Item.get_by_id(int(key), parent=getSupplier(shop))
    return record.getItemResponse(request, item, stories)
Beispiel #26
0
def item(request,shop,key):
  stories = getCategoriesInfo()
  item = Item.get_by_id(int(key),parent = getSupplier(shop))
  return record.getItemResponse(request,item,stories)