Esempio n. 1
0
def edit_auth_host(request, host_id, template='config/edit_auth_host.html'):
    'Edits an external auth host'

    host = get_object_or_404(MailAuthHost, id=host_id)

    if request.method == 'POST':
        form = EditMailAuthHostForm(request.POST, instance=host)
        if form.is_valid():
            try:
                saved_host = form.save()
                msg = _('External authentication %(auth)s: on host %(host)s for'
                        ' domain %(dom)s has been updated successfully') % {
                    'auth': AUTH_TYPES[saved_host.protocol], 
                    'host': saved_host.address, 
                    'dom': saved_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=[saved_host.useraddress.id]))
            except IntegrityError:
                msg = _('Update 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 = EditMailAuthHostForm(instance=host)
    return render_to_response(template, locals(), 
        context_instance=RequestContext(request))
Esempio n. 2
0
def edit_auth_host(request, host_id, template="config/edit_auth_host.html"):
    "Edits an external auth host"

    host = get_object_or_404(MailAuthHost, id=host_id)

    if request.method == "POST":
        form = EditMailAuthHostForm(request.POST, instance=host)
        if form.is_valid():
            try:
                saved_host = form.save()
                msg = _(
                    "External authentication %(auth)s: on host %(host)s for"
                    " domain %(dom)s has been updated successfully"
                ) % {
                    "auth": AUTH_TYPES[saved_host.protocol],
                    "host": saved_host.address,
                    "dom": saved_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=[saved_host.useraddress.id]))
            except IntegrityError:
                msg = _("Update 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 = EditMailAuthHostForm(instance=host)
    return render_to_response(template, locals(), context_instance=RequestContext(request))
Esempio n. 3
0
def edit_auth_host(request, host_id, template='config/edit_auth_host.html'):
    'Edits an external auth host'
    
    host = get_object_or_404(MailAuthHost, id=host_id)
    
    if request.method == 'POST':
        form = EditMailAuthHostForm(request.POST, instance=host)
        if form.is_valid():
            try:
                saved_host = form.save()
                msg = 'External authentication %s: on host %s for domain %s has been updated successfully' % (
                    AUTH_TYPES[saved_host.protocol], saved_host.address, 
                    saved_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=[saved_host.useraddress.id]))
            except:
                msg = 'Update 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 = EditMailAuthHostForm(instance=host)
    return render_to_response(template, locals(), 
        context_instance=RequestContext(request))
Esempio n. 4
0
def edit_auth_host(request, host_id, template='config/edit_auth_host.html'):
    'Edits an external auth host'

    host = get_object_or_404(MailAuthHost, id=host_id)

    if request.method == 'POST':
        form = EditMailAuthHostForm(request.POST, instance=host)
        if form.is_valid():
            try:
                saved_host = form.save()
                msg = _('External authentication %(auth)s: on host %(host)s for'
                        ' domain %(dom)s has been updated successfully') % {
                    'auth': AUTH_TYPES[saved_host.protocol],
                    'host': saved_host.address,
                    'dom': saved_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=[saved_host.useraddress.id]))
            except IntegrityError:
                msg = _('Update 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 = EditMailAuthHostForm(instance=host)
    return render_to_response(template, locals(),
        context_instance=RequestContext(request))