Пример #1
0
    def GarbageCollectBlobs(self):
        keys_to_blobs = {}
        for blob in BlobInfo.all():
            keys_to_blobs[blob.key()] = blob

        for responder in Responder.all():
            image_blob = responder.image_data
            if image_blob:
                key = image_blob.key()
                if key in keys_to_blobs:
                    del keys_to_blobs[key]

        for product in Product.all():
            image_blob = product.image_data
            if image_blob:
                key = image_blob.key()
                if key in keys_to_blobs:
                    del keys_to_blobs[key]

        for key, blob_info in keys_to_blobs.iteritems():
            logging.info('deleting %s' % key)
            blob_info.delete()

        if keys_to_blobs:
            return 'Deleted blobs: \n%s' % '\n'.join(
                str(k) for k in keys_to_blobs)
        else:
            return 'No blobs to delete'
Пример #2
0
  def GarbageCollectBlobs(self):
    keys_to_blobs = {}
    for blob in BlobInfo.all():
      keys_to_blobs[blob.key()] = blob

    for responder in Responder.all():
      image_blob = responder.image_data
      if image_blob:
        key = image_blob.key()
        if key in keys_to_blobs:
          del keys_to_blobs[key]

    for product in Product.all():
      image_blob = product.image_data
      if image_blob:
        key = image_blob.key()
        if key in keys_to_blobs:
          del keys_to_blobs[key]

    for key, blob_info in keys_to_blobs.iteritems():
      logging.info('deleting %s' % key)
      blob_info.delete()

    if keys_to_blobs:
      return 'Deleted blobs: \n%s' % '\n'.join(str(k) for k in keys_to_blobs)
    else:
      return 'No blobs to delete'
Пример #3
0
 def ProductCount(self):
   """Return the number of product."""
   product_count = memcache.get(memcache_keys.PRODUCT_COUNT_KEY)
   if product_count is None:
     product_count = Responder.all().count() + Product.all().count()
     if not memcache.add(memcache_keys.PRODUCT_COUNT_KEY, product_count):
       logging.error("Memcache set failed.")
   return product_count
Пример #4
0
 def create_product(name, barcode, category):
     """ Create a product in datastore """
     query = Product.all()
     query.filter("barcode =", barcode)
     ret = query.get()
     if ret is None:
         ret = Product()
         ret.barcode = barcode
         ret.set_name(name)
         ret.category = category
         ret.put()
         AdminWorkerHandler.update_search_table(ret)
     return ret
Пример #5
0
    def InitiateImageFetch(self):
        """Add /fetch_image tasks for all responders missing image data."""
        urls = []
        for responder in Responder.all():
            if responder.image_url and not responder.image_data:
                url = '/tasks/fetch_image?key=%s' % responder.key()
                task = taskqueue.Task(method='GET', url=url)
                task.add()
                urls.append(responder.image_url)

        for product in Product.all():
            if product.image_url and not product.image_data:
                url = '/tasks/fetch_product_image?key=%s' % product.key()
                task = taskqueue.Task(method='GET', url=url)
                task.add()
                urls.append(product.image_url)

        if urls:
            return 'Fetching urls: \n%s' % '\n'.join(urls)
        else:
            return 'No images to fetch'
Пример #6
0
  def InitiateImageFetch(self):
    """Add /fetch_image tasks for all responders missing image data."""
    urls = []
    for responder in Responder.all():
      if responder.image_url and not responder.image_data:
        url = '/tasks/fetch_image?key=%s' % responder.key()
        task = taskqueue.Task(method='GET', url=url)
        task.add()
        urls.append(responder.image_url)

    for product in Product.all():
      if product.image_url and not product.image_data:
        url = '/tasks/fetch_product_image?key=%s' % product.key()
        task = taskqueue.Task(method='GET', url=url)
        task.add()
        urls.append(product.image_url)

    if urls:
      return 'Fetching urls: \n%s' % '\n'.join(urls)
    else:
      return 'No images to fetch'
Пример #7
0
 def get(self):
     query = Product.all()  #db.GqlQuery("SELECT * FROM BlogEntry")
     self.generatePagedFromQuery(query, "CreateProduct.html")
Пример #8
0
 def get(self):
     query = Product.all()
     self.generatePagedFromQuery(query, "ProductInfo.html")