def media_confirm_delete(request, media): form = user_forms.ConfirmDeleteForm(request.form) if request.method == 'POST' and form.validate(): if form.confirm.data is True: username = media.get_uploader.username # Delete all the associated comments for comment in media.get_comments(): comment.delete() # Delete all files on the public storage try: delete_media_files(media) except OSError, error: _log.error('No such files from the user "{1}"' ' to delete: {0}'.format(str(error), username)) messages.add_message(request, messages.ERROR, _('Some of the files with this entry seem' ' to be missing. Deleting anyway.')) media.delete() messages.add_message( request, messages.SUCCESS, _('You deleted the media.')) return redirect(request, "mediagoblin.user_pages.user_home", user=username) else: messages.add_message( request, messages.ERROR, _("The media was not deleted because you didn't check that you were sure.")) return redirect(request, location=media.url_for_self(request.urlgen))
def delete(self, del_orphan_tags=True, **kwargs): """Delete MediaEntry and all related files/attachments/comments This will *not* automatically delete unused collections, which can remain empty... :param del_orphan_tags: True/false if we delete unused Tags too :param commit: True/False if this should end the db transaction""" # User's CollectionItems are automatically deleted via "cascade". # Comments on this Media are deleted by cascade, hopefully. # Delete all related files/attachments try: delete_media_files(self) except OSError as error: # Returns list of files we failed to delete _log.error('No such files from the user "{1}" to delete: ' '{0}'.format(str(error), self.get_uploader)) _log.info('Deleted Media entry id "{0}"'.format(self.id)) # Related MediaTag's are automatically cleaned, but we might # want to clean out unused Tag's too. if del_orphan_tags: # TODO: Import here due to cyclic imports!!! # This cries for refactoring from mediagoblin.db.util import clean_orphan_tags clean_orphan_tags(commit=False) # pass through commit=False/True in kwargs super(MediaEntry, self).delete(**kwargs)
def delete(self, del_orphan_tags=True, **kwargs): """Delete MediaEntry and all related files/attachments/comments This will *not* automatically delete unused collections, which can remain empty... :param del_orphan_tags: True/false if we delete unused Tags too :param commit: True/False if this should end the db transaction""" # User's CollectionItems are automatically deleted via "cascade". # Comments on this Media are deleted by cascade, hopefully. # Delete all related files/attachments try: delete_media_files(self) except OSError, error: # Returns list of files we failed to delete _log.error('No such files from the user "{1}" to delete: ' '{0}'.format(str(error), self.get_uploader))