def editaccount(request, accountid, tplname="common/tabforms.html"): account = User.objects.get(pk=accountid) if not request.user.can_access(account): raise PermDeniedException mb = None if account.mailbox_set.count(): mb = account.mailbox_set.all()[0] instances = dict(general=account, mail=mb, perms=account) events.raiseEvent("FillAccountInstances", request.user, account, instances) return AccountForm(request, instances=instances).process()
def editaccount(request, accountid, tplname="common/tabforms.html"): account = User.objects.get(pk=accountid) if not request.user.can_access(account): raise PermDeniedException mb = None if account.mailbox_set.count(): mb = account.mailbox_set.all()[0] instances = dict(general=account, mail=mb, perms=account) events.raiseEvent("FillAccountInstances", request.user, account, instances) ctx = dict( title=account.username, formid="accountform", action=reverse(editaccount, args=[accountid]), action_label=_("Update"), action_classes="submit" ) if request.method == "POST": classes = {} form = AccountForm(request.user, request.POST, instances=instances, classes=classes) account.oldgroup = account.group if form.is_valid(mandatory_only=True): form.save_general_form() if form.is_valid(optional_only=True): events.raiseEvent("AccountModified", account, form.account) form.save() return ajax_simple_response( dict(status="ok", respmsg=_("Account updated")) ) transaction.rollback() ctx["tabs"] = form return ajax_response(request, status="ko", template=tplname, **ctx) ctx["tabs"] = AccountForm(request.user, instances=instances) active_tab_id = request.GET.get("active_tab", "default") if active_tab_id != "default": ctx["tabs"].active_id = active_tab_id return render(request, tplname, ctx)
def editaccount(request, accountid, tplname="common/tabforms.html"): account = User.objects.get(pk=accountid) if not request.user.can_access(account): raise PermDeniedException mb = None if account.mailbox_set.count(): mb = account.mailbox_set.all()[0] instances = dict(general=account, mail=mb, perms=account) events.raiseEvent("FillAccountInstances", request.user, account, instances) if request.method == "POST": classes = {} form = AccountForm(request.user, request.POST, instances=instances, classes=classes) account.oldgroup = account.group if form.is_valid(mandatory_only=True): form.save_general_form() if form.is_valid(optional_only=True): events.raiseEvent("AccountModified", account, form.account) form.save() return render_to_json_response(_("Account updated")) return render_to_json_response({'form_errors': form.errors}, status=400) ctx = { 'title': account.username, 'formid': 'accountform', 'action': reverse(editaccount, args=[accountid]), 'action_label': _('Update'), 'action_classes': 'submit', 'tabs': AccountForm(request.user, instances=instances) } active_tab_id = request.GET.get("active_tab", "default") if active_tab_id != "default": ctx["tabs"].active_id = active_tab_id return render(request, tplname, ctx)
def editaccount(request, accountid, tplname="common/tabforms.html"): account = User.objects.get(pk=accountid) if not request.user.can_access(account): raise PermDeniedException mb = None if account.mailbox_set.count(): mb = account.mailbox_set.all()[0] instances = dict(general=account, mail=mb, perms=account) events.raiseEvent("FillAccountInstances", request.user, account, instances) ctx = dict(title=account.username, formid="accountform", action=reverse(editaccount, args=[accountid]), action_label=_("Update"), action_classes="submit") if request.method == "POST": classes = {} form = AccountForm(request.user, request.POST, instances=instances, classes=classes) account.oldgroup = account.group if form.is_valid(mandatory_only=True): form.save_general_form() if form.is_valid(optional_only=True): events.raiseEvent("AccountModified", account, form.account) form.save() return ajax_simple_response( dict(status="ok", respmsg=_("Account updated"))) transaction.rollback() ctx["tabs"] = form return ajax_response(request, status="ko", template=tplname, **ctx) ctx["tabs"] = AccountForm(request.user, instances=instances) active_tab_id = request.GET.get("active_tab", "default") if active_tab_id != "default": ctx["tabs"].active_id = active_tab_id return render(request, tplname, ctx)