Beispiel #1
0
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    if request.method == "POST":
        domain.oldname = domain.name
        form = DomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            form.save(request.user)
            events.raiseEvent("DomainModified", domain)
            return render_to_json_response(_("Domain modified"))
        return render_to_json_response({
            'form_errors': form.errors
        }, status=400)

    domadmins = [u for u in domain.admins
                 if request.user.can_access(u) and not u.is_superuser]
    if not request.user.is_superuser:
        domadmins = [u for u in domadmins if u.group == "DomainAdmins"]
    ctx = {"title": domain.name,
           "action_label": _("Update"),
           "action_classes": "submit",
           "action": reverse(editdomain, args=[dom_id]),
           "formid": "domform",
           "domain": domain,
           "tabs": DomainForm(request.user, instances=instances),
           "domadmins": domadmins}
    return render(request, tplname, ctx)
Beispiel #2
0
def editdomain(request, dom_id):
    """Edit domain view."""
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    return DomainForm(request, instances=instances).process()
Beispiel #3
0
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)
    if request.method == "POST":
        domain.oldname = domain.name
        form = DomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            form.save(request.user)
            events.raiseEvent("DomainModified", domain)
            return render_to_json_response(_("Domain modified"))
        return render_to_json_response({
            'form_errors': form.errors
        }, status=400)

    domadmins = [u for u in domain.admins
                 if request.user.can_access(u) and not u.is_superuser]
    if not request.user.is_superuser:
        domadmins = [u for u in domadmins if u.group == "DomainAdmins"]
    ctx = {"title": domain.name,
           "action_label": _("Update"),
           "action_classes": "submit",
           "action": reverse(editdomain, args=[dom_id]),
           "formid": "domform",
           "domain": domain,
           "tabs": DomainForm(request.user, instances=instances),
           "domadmins": domadmins}
    return render(request, tplname, ctx)
Beispiel #4
0
def editdomain(request, dom_id, tplname="admin/editdomainform.html"):
    domain = Domain.objects.get(pk=dom_id)
    if not request.user.can_access(domain):
        raise PermDeniedException

    domadmins = [u for u in domain.admins
                 if request.user.can_access(u) and not u.is_superuser]
    if not request.user.is_superuser:
        domadmins = [u for u in domadmins if u.group == "DomainAdmins"]

    instances = dict(general=domain)
    events.raiseEvent("FillDomainInstances", request.user, domain, instances)

    commonctx = {"title": domain.name,
                 "action_label": _("Update"),
                 "action_classes": "submit",
                 "action": reverse(editdomain, args=[dom_id]),
                 "formid": "domform",
                 "domain": domain}
    if request.method == "POST":
        error = None
        domain.oldname = domain.name
        form = DomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            try:
                form.save(request.user)
            except AdminError, e:
                error = str(e)
            else:
                events.raiseEvent("DomainModified", domain)
                return ajax_simple_response({
                    "status": "ok", "respmsg": _("Domain modified")
                })

        commonctx["tabs"] = form
        return ajax_simple_response({
            "status": "ko", "respmsg": error,
            "content": _render_to_string(request, tplname, commonctx)
        })