def add_auth_host(request, domain_id, template='config/add_auth_host.html'): 'Add an external auth host' domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1) if request.method == 'POST': form = MailAuthHostForm(request.POST) if form.is_valid(): try: host = form.save() msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s was added successfully') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address} 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=[domain.id])) except IntegrityError: msg = _('Addition of external authentication failed') 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) else: form = MailAuthHostForm(initial = {'useraddress': domain.id}) return render_to_response(template, locals(), context_instance=RequestContext(request))
def add_auth_host(request, domain_id, template="config/add_auth_host.html"): "Add an external auth host" domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1) if request.method == "POST": form = MailAuthHostForm(request.POST) if form.is_valid(): try: host = form.save() msg = _( "External authentication %(auth)s: on host %(host)s" " for domain %(dom)s was added successfully" ) % {"auth": AUTH_TYPES[host.protocol], "host": host.address, "dom": host.useraddress.address} 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=[domain.id])) except IntegrityError: msg = _("Addition of external authentication failed") 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) else: form = MailAuthHostForm(initial={"useraddress": domain.id}) return render_to_response(template, locals(), context_instance=RequestContext(request))
def add_auth_host(request, domain_id, template='config/add_auth_host.html'): 'Add an external auth host' domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1) if request.method == 'POST': form = MailAuthHostForm(request.POST) if form.is_valid(): try: host = form.save() msg = ('External authentication %s: on host %s for domain %s was added successfully' % ( AUTH_TYPES[host.protocol], host.address, host.useraddress.address)) 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=[domain.id])) except: msg = 'Addition of external authentication failed' 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) else: form = MailAuthHostForm(initial = {'useraddress': domain.id}) return render_to_response(template, locals(), context_instance=RequestContext(request))
def add_auth_host(request, domain_id, template='config/add_auth_host.html'): 'Add an external auth host' domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1) if request.method == 'POST': form = MailAuthHostForm(request.POST) if form.is_valid(): try: host = form.save() msg = _('External authentication %(auth)s: on host %(host)s' ' for domain %(dom)s was added successfully') % { 'auth': AUTH_TYPES[host.protocol], 'host': host.address, 'dom': host.useraddress.address} 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=[domain.id])) except IntegrityError: msg = _('Addition of external authentication failed') 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) else: form = MailAuthHostForm(initial={'useraddress': domain.id}) return render_to_response(template, locals(), context_instance=RequestContext(request))