def delete(self, db): try: remove_image(self.cover) except Exception: pass for image in self.images: try: remove_image(image) except Exception: pass db.delete(self)
def do_edit_gallery(self, id=None, redirect_to_gallery=False): if not id: gallery = Gallery() else: gallery = Gallery.load(self.db, id) gallery.name = request.POST['name'] gallery.text = request.POST['text'] gallery.tags = [tag.strip().lower() for tag in request.POST['tags'].split(',')] gallery.tags = filter(lambda t: t != '', gallery.tags) # cover image if hasattr(request.POST['cover_image'], 'file'): if gallery.cover: remove_image(gallery.cover) gallery.cover = store_image(request.POST['cover_image'].file) # Video stuff for video in request.POST.getall('delete_video'): gallery.videos.remove(video) videos = [video.strip() for video in request.POST['videos'].split(',')] videos = filter(lambda v: v != '', videos) if gallery.videos: gallery.videos.extend(videos) else: gallery.videos = videos gallery.date = date(int(request.POST['year']), int(request.POST['month']), 1) gallery.store(self.db) flash("Gallery successfully edited.") if redirect_to_gallery: redirect(url(controller='admin', action='edit_gallery', id=gallery.id)) else: redirect(url(controller='admin', action='galleries'))
def remove_image(self, image): self.images.remove(image) remove_image(image)