Exemplo n.º 1
0
    def remove(self):
        photos = DBPhoto.get_by_key_name(self.photoslist)
        photo_keys = []
        blob_keys = []
        thumb_blob_keys = []
        comments_keys = []
        for photo in photos:
            photo_keys.append(photo.key())
            blob_keys.append(photo.blob_key)
            thumb_blob_keys.append(photo.thumb_blob_key)
            comments_keys = comments_keys + [
                comment.key() for comment in DBComment.get_comments(
                    photo.album_name, photo.photo_name)
            ]

        def txn():
            remove(photo_keys)
            remove(comments_keys)
            db.delete(comments_keys)
            SITE_SETTINGS.remove_album(self)
            db.delete(photo_keys)
            self.delete()

        db.run_in_transaction(txn)
        blobstore.delete(blob_keys)
        blobstore.delete(thumb_blob_keys)
Exemplo n.º 2
0
 def delete_images(self):
     '''
         Deletes the associated images to the image parameter
     '''
     for field in [self.image_blob_key, self.image_thumb_blob_key]:
         if field is not None and len(field.strip()) > 0:
             blobstore.delete(field)
     pass
Exemplo n.º 3
0
 def delete_images(self):
     '''
         Deletes the associated images to the image parameter
     '''
     for field in [self.image_blob_key, self.image_thumb_blob_key]:
         if field is not None and len(field.strip()) > 0:
             blobstore.delete(field)
     pass
Exemplo n.º 4
0
def admin_images(parent_id= -1):
    """
        List all images from within a category
    """
    category_id = parent_id
    form = ImageForm(prefix='image')
    if form.validate_on_submit():
        is_new = False
        if len(form.key_id.data) > 0 and long(form.key_id.data) > 0:
            image = ImageModel.get_by_id(long(form.key_id.data))
        else:
            image = ImageModel()
            is_new = True
        v2m(form, image)
        category_id = long(form.category_id.data)
        if type(form.image.data) == FileStorage and (is_new or form.update_image.data):
            blob_key = form.image.data.mimetype_params['blob-key']
            #create a small
            (image.image_thumb_blob_key, image.width, image.height) = create_thumbnail(blob_key, 50, 50)
            #and a slightly larger version 
            (image.image_blob_key, image.width, image.height) = create_thumbnail(blob_key)
            #delete the uploaded (possibly 'uge file)
            blobstore.delete(blob_key)
        elif not is_new and form.update_image.data: # we set to update with an empty image so we delete the one in the db
            image.delete_images()
            image.image_blob_key = ''
            image.image_thumb_blob_key = ''
            image.width = 0
            image.height = 0
        try:
            image.put()
            image_id = image.key().id()
            flash(u'Image %s successfully saved.' % image_id, 'success')
            return redirect(url_for('admin_images_in_category', parent_id=category_id))
        except CapabilityDisabledError:
            image.delete_images()
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('admin_images_in_category', parent_id=category_id))
        pass
    elif form.is_submitted():
        category_id = long(form.category_id.data)  
    images = sorted(ImageModel.all().filter('category_id', category_id), key=lambda i: i.order)
    (categories, category_path, all_categories) = CategoryModel.get_categories_info(category_id)
    form.category_id.data = category_path[-1].key().id()
    return render_template('image/admin_images.html', images=images,
                           form=form,
                           categories=categories,
                           category_path=category_path,
                           current_category=category_path[-1],
                           all_categories=all_categories,
                           reset_image=ImageModel(category_id=category_id),
                           upload_url=blobstore.create_upload_url(url_for('admin_images')))
Exemplo n.º 5
0
def drop_empty_files(filenames):
    """Deletes empty files and returns filenames minus the deleted ones."""
    non_empty_filenames = []
    empty_file_keys = []
    blobs_info = blobstore.BlobInfo.get([files.blobstore.get_blob_key(fn) for fn in filenames])
    for filename, blob_info in zip(filenames, blobs_info):
        if blob_info:
            if blob_info.size > 0:
                non_empty_filenames.append(filename)
            else:
                empty_file_keys.append(blob_info.key())
    blobstore_api.delete(empty_file_keys)
    return non_empty_filenames
Exemplo n.º 6
0
def drop_empty_files(filenames):
    """Deletes empty files and returns filenames minus the deleted ones."""
    non_empty_filenames = []
    empty_file_keys = []
    blobs_info = blobstore.BlobInfo.get(
        [files.blobstore.get_blob_key(fn) for fn in filenames])
    for filename, blob_info in itertools.izip(filenames, blobs_info):
        if blob_info:
            if blob_info.size > 0:
                non_empty_filenames.append(filename)
            else:
                empty_file_keys.append(blob_info.key())
    blobstore_api.delete(empty_file_keys)
    return non_empty_filenames
Exemplo n.º 7
0
def delete_backup_files(filesystem, backup_files):
    if backup_files:

        if filesystem == files.BLOBSTORE_FILESYSTEM:

            blob_keys = []
            for fname in backup_files:
                blob_key = files.blobstore.get_blob_key(fname)
                if blob_key:
                    blob_keys.append(blob_key)
                    if len(blob_keys) == MAX_BLOBS_PER_DELETE:
                        blobstore_api.delete(blob_keys)
                        blob_keys = []
            if blob_keys:
                blobstore_api.delete(blob_keys)
Exemplo n.º 8
0
def delete_backup_files(filesystem, backup_files):
  if backup_files:

    if filesystem == files.BLOBSTORE_FILESYSTEM:


      blob_keys = []
      for fname in backup_files:
        blob_key = files.blobstore.get_blob_key(fname)
        if blob_key:
          blob_keys.append(blob_key)
          if len(blob_keys) == MAX_BLOBS_PER_DELETE:
            blobstore_api.delete(blob_keys)
            blob_keys = []
      if blob_keys:
        blobstore_api.delete(blob_keys)
Exemplo n.º 9
0
    def delete_blobstore_files(self, kind_files):
        """delete files in blobstore"""
        keys = []
        for kind_file in kind_files:
            for file_name in kind_file.files:
                key = files.blobstore.get_blob_key(file_name)
                if key:
                    keys.append(key)

        delete_files = []
        for key in keys:
            delete_files.append(key)
            if len(delete_files) == 100:
                blobstore.delete(delete_files)
                delete_files = []
        if delete_files:
            blobstore.delete(delete_files)
Exemplo n.º 10
0
  def post(self):
    """Handler for post requests to datastore_admin/backup_delete.do.

    Jobs are executed and user is redirected to the base-path handler.
    """
    backup_ids = self.request.get_all('backup_id')
    token = self.request.get('xsrf_token')
    error = None
    if backup_ids and utils.ValidateXsrfToken(token, XSRF_ACTION):
      try:
        for backup_info in db.get(backup_ids):
          if backup_info:
            blobstore_api.delete([files.blobstore.get_blob_key(filename)
                                  for filename in backup_info.blob_files])
            backup_info.delete()
      except Exception, e:
        logging.exception('Failed to delete datastore backup.')
        error = str(e)
Exemplo n.º 11
0
    def post(self):
        """Handler for post requests to datastore_admin/backup_delete.do.

    Jobs are executed and user is redirected to the base-path handler.
    """
        backup_ids = self.request.get_all('backup_id')
        token = self.request.get('xsrf_token')
        error = None
        if backup_ids and utils.ValidateXsrfToken(token, XSRF_ACTION):
            try:
                for backup_info in db.get(backup_ids):
                    if backup_info:
                        blobstore_api.delete([
                            files.blobstore.get_blob_key(filename)
                            for filename in backup_info.blob_files
                        ])
                        backup_info.delete()
            except Exception, e:
                logging.exception('Failed to delete datastore backup.')
                error = str(e)
Exemplo n.º 12
0
    def remove(self):
        photos = DBPhoto.get_by_key_name(self.photoslist)
        photo_keys = []
        blob_keys = []
        thumb_blob_keys = []
        comments_keys = []
        for photo in photos:
            photo_keys.append(photo.key())
            blob_keys.append(photo.blob_key)
            thumb_blob_keys.append(photo.thumb_blob_key)
            comments_keys = comments_keys + [comment.key() for comment in
                                             DBComment.get_comments(photo.album_name, photo.photo_name)]

        def txn():
            remove(photo_keys)
            remove(comments_keys)
            db.delete(comments_keys)
            SITE_SETTINGS.remove_album(self)
            db.delete(photo_keys)
            self.delete()

        db.run_in_transaction(txn)
        blobstore.delete(blob_keys)
        blobstore.delete(thumb_blob_keys)
Exemplo n.º 13
0
 def remove(self):
     blobstore.delete(self.blod_key)
     blobstore.delete(self.thumb_blob_key)
     DBComment.del_comments(self.album_name, self.photo_name)
     self.remove()
Exemplo n.º 14
0
 def remove(self):
     blobstore.delete(self.blod_key)
     blobstore.delete(self.thumb_blob_key)
     DBComment.del_comments(self.album_name, self.photo_name)
     self.remove()
Exemplo n.º 15
0
 def delete_image(self):
     blobstore.delete(self.image)