def test_delete(self): bucket = Bucket(self.path, self.ids.pop) self.assertEqual(bucket.put(b'some data'), 'id_0000') self.assertEqual(bucket.put(b'some more data'), 'id_0001') self.assertEqual(sorted(bucket.keys()), ['id_0000', 'id_0001']) for item_id in bucket.keys(): bucket.delete(item_id) self.assertEqual(sorted(bucket.keys()), [])
def remove_image(self, *a, **k): """remove a ImagesField image""" path = os.path.join(system.site.data_path, 'buckets') bucket = Bucket(path) items = bucket.keys() item_id = k.get('id', None) if item_id in bucket.keys(): bucket.delete(item_id) return 'ok' return 'empty'
def remove_image(self, *_, **kwargs): """remove a dropzone image""" # k contains item_id and filename for file to be removed item_id = kwargs.get('id', None) # detach the image from the record if item_id: images = zoom.store.store_of(Image) key = images.first(image_id=item_id) if key: images.delete(key) # delete the bucket path = os.path.join(zoom.system.site.data_path, 'buckets') bucket = Bucket(path) if item_id in bucket.keys(): bucket.delete(item_id) return 'ok' return 'empty'
def clear(self): bucket = Bucket(self.path, self.ids.pop) for item_id in bucket.keys(): bucket.delete(item_id)