'Removes a web-based image attachment if it is used by no view (template)
Returns a dict mapping attachments which would not be removed (if any)
mapped to the views preventing their removal'

@http.route('/web_editor/attachment/remove', type='json', auth='user')
def remove(self, ids, **kwargs):

    Attachment = attachments_to_remove = request.env['ir.attachment']
    Views = request.env['ir.ui.view']
    removal_blocked_by = {}
    for attachment in Attachment.browse(ids):
        url = tools.html_escape(attachment.local_url)
        views = Views.search(['|', ('arch_db', 'like', ('"%s"' % url)), ('arch_db', 'like', ("'%s'" % url))])
        if views:
            removal_blocked_by[attachment.id] = views.read(['name'])
        else:
            attachments_to_remove += attachment
    if attachments_to_remove:
        attachments_to_remove.unlink()
    return removal_blocked_by
