def delete_auth_host(request, host_id, template='config/delete_auth_host.html'): 'Deletes an external auth host' host = get_object_or_404(MailAuthHost, id=host_id) if request.method == 'POST': form = DeleteMailAuthHostForm(request.POST, instance=host) if form.is_valid(): try: go_id = host.useraddress.id msg = 'External authentication %s: on host %s for domain %s has been deleted' % ( AUTH_TYPES[host.protocol], host.address, host.useraddress.address) host.delete() if request.is_ajax(): response = simplejson.dumps({'success':True, 'html':msg}) return HttpResponse(response, content_type='application/javascript; charset=utf-8') request.user.message_set.create(message=msg) return HttpResponseRedirect(reverse('view-domain', args=[go_id])) except: msg = 'External authentication %s: on host %s for domain %s could not be deleted' % ( AUTH_TYPES[host.protocol], host.address, host.useraddress.address) if request.is_ajax(): response = simplejson.dumps({'success':False, 'html':msg}) return HttpResponse(response, content_type='application/javascript; charset=utf-8') request.user.message_set.create(message=msg) else: form = DeleteMailAuthHostForm(instance=host) return render_to_response(template, locals(), context_instance=RequestContext(request))
def delete_auth_host(request, host_id, template="config/delete_auth_host.html"): "Deletes an external auth host" host = get_object_or_404(MailAuthHost, id=host_id) if request.method == "POST": form = DeleteMailAuthHostForm(request.POST, instance=host) if form.is_valid(): try: go_id = host.useraddress.id msg = _("External authentication %(auth)s: on host %(host)s" " for domain %(dom)s has been deleted") % { "auth": AUTH_TYPES[host.protocol], "host": host.address, "dom": host.useraddress.address, } host.delete() if request.is_ajax(): response = anyjson.dumps({"success": True, "html": msg}) return HttpResponse(response, content_type="application/javascript; charset=utf-8") djmessages.info(request, msg) return HttpResponseRedirect(reverse("view-domain", args=[go_id])) except DatabaseError: msg = _( "External authentication %(auth)s: on host %(host)s" " for domain %(dom)s could not be deleted" ) % {"auth": AUTH_TYPES[host.protocol], "host": host.address, "dom": host.useraddress.address} if request.is_ajax(): response = anyjson.dumps({"success": False, "html": msg}) return HttpResponse(response, content_type="application/javascript; charset=utf-8") djmessages.info(request, msg) else: form = DeleteMailAuthHostForm(instance=host) return render_to_response(template, locals(), context_instance=RequestContext(request))
def delete_auth_host(request, host_id, template='config/delete_auth_host.html'): 'Deletes an external auth host' host = get_object_or_404(MailAuthHost, id=host_id) if request.method == 'POST': form = DeleteMailAuthHostForm(request.POST, instance=host) if form.is_valid(): try: go_id = host.useraddress.id msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s has been deleted') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address } host.delete() if request.is_ajax(): response = anyjson.dumps({'success': True, 'html': msg}) return HttpResponse( response, content_type='application/javascript; charset=utf-8') djmessages.info(request, msg) return HttpResponseRedirect( reverse('view-domain', args=[go_id])) except DatabaseError: msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s could not be deleted') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address } if request.is_ajax(): response = anyjson.dumps({'success': False, 'html': msg}) return HttpResponse( response, content_type='application/javascript; charset=utf-8') djmessages.info(request, msg) else: form = DeleteMailAuthHostForm(instance=host) return render_to_response(template, locals(), context_instance=RequestContext(request))
def delete_auth_host(request, host_id, template='config/delete_auth_host.html'): 'Deletes an external auth host' host = get_object_or_404(MailAuthHost, id=host_id) if request.method == 'POST': form = DeleteMailAuthHostForm(request.POST, instance=host) if form.is_valid(): try: go_id = host.useraddress.id msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s has been deleted') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address } host.delete() if request.is_ajax(): response = anyjson.dumps({'success': True, 'html': msg}) return HttpResponse(response, content_type='application/javascript; charset=utf-8') djmessages.info(request, msg) return HttpResponseRedirect(reverse('view-domain', args=[go_id])) except DatabaseError: msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s could not be deleted') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address } if request.is_ajax(): response = anyjson.dumps({'success': False, 'html': msg}) return HttpResponse(response, content_type='application/javascript; charset=utf-8') djmessages.info(request, msg) else: form = DeleteMailAuthHostForm(instance=host) return render_to_response(template, locals(), context_instance=RequestContext(request))