def newdomain(request, tplname="common/wizard_forms.html"): events.raiseEvent("CanCreate", request.user, "domains") def newdomain_cb(steps): genform = steps[0]["form"] genform.is_valid() domain = genform.save(request.user) domain.post_create(request.user) steps[1]["form"].save(request.user, domain) commonctx = {"title": _("New domain"), "action_label": _("Create"), "action_classes": "submit", "action": reverse(newdomain), "formid": "domform"} cwizard = CreationWizard(newdomain_cb) cwizard.add_step(DomainFormGeneral, _("General"), [dict(classes="btn-inverse next", label=_("Next"))], formtpl="admin/domain_general_form.html") cwizard.add_step(DomainFormOptions, _("Options"), [dict(classes="btn-primary submit", label=_("Create")), dict(classes="btn-inverse prev", label=_("Previous"))], formtpl="admin/domain_options_form.html") if request.method == "POST": retcode, data = cwizard.validate_step(request) if retcode == -1: raise AdminError(data) if retcode == 1: return ajax_simple_response(dict( status="ok", title=cwizard.get_title(data + 1), stepid=data )) if retcode == 2: return ajax_simple_response( dict(status="ok", respmsg=_("Domain created")) ) from modoboa.lib.templatetags.lib_tags import render_form return ajax_simple_response(dict( status="ko", stepid=data, form=render_form(cwizard.steps[data]["form"]) )) cwizard.create_forms() commonctx.update(steps=cwizard.steps) commonctx.update(subtitle="1. %s" % cwizard.steps[0]['title']) return render(request, tplname, commonctx)
def newaccount(request, tplname='common/wizard_forms.html'): def create_account(steps): """Account creation callback Called when all creation steps have been validated. :param steps: the steps data """ genform = steps[0]["form"] genform.is_valid() account = genform.save() account.post_create(request.user) mailform = steps[1]["form"] try: mailform.save(request.user, account) except AdminError: # A bit uggly: transaction management doesn't work very # well with nested functions. Need to wait for django 1.6 # and atomicity. account.delete(request.user, False) raise ctx = dict(title=_("New account"), action=reverse(newaccount), formid="newaccount_form", submit_label=_("Create")) cwizard = CreationWizard(create_account) cwizard.add_step(AccountFormGeneral, _("General"), [dict(classes="btn-inverse next", label=_("Next"))], new_args=[request.user]) cwizard.add_step(AccountFormMail, _("Mail"), [ dict(classes="btn-primary submit", label=_("Create")), dict(classes="btn-inverse prev", label=_("Previous")) ], formtpl="admin/mailform.html") if request.method == "POST": retcode, data = cwizard.validate_step(request) if retcode == -1: raise AdminError(data) if retcode == 1: return ajax_simple_response( dict(status="ok", title=cwizard.get_title(data + 1), stepid=data)) if retcode == 2: return ajax_simple_response( dict(status="ok", respmsg=_("Account created"))) from modoboa.lib.templatetags.lib_tags import render_form return ajax_simple_response( dict(status="ko", stepid=data, form=render_form(cwizard.steps[data]["form"]))) cwizard.create_forms() ctx.update(steps=cwizard.steps) ctx.update(subtitle="1. %s" % cwizard.steps[0]['title']) return render(request, tplname, ctx)
def newaccount(request, tplname='common/wizard_forms.html'): def create_account(steps): """Account creation callback Called when all creation steps have been validated. :param steps: the steps data """ genform = steps[0]["form"] genform.is_valid() account = genform.save() account.post_create(request.user) mailform = steps[1]["form"] try: mailform.save(request.user, account) except AdminError: # A bit uggly: transaction management doesn't work very # well with nested functions. Need to wait for django 1.6 # and atomicity. account.delete(request.user, False) raise ctx = dict( title=_("New account"), action=reverse(newaccount), formid="newaccount_form", submit_label=_("Create") ) cwizard = CreationWizard(create_account) cwizard.add_step(AccountFormGeneral, _("General"), [dict(classes="btn-inverse next", label=_("Next"))], new_args=[request.user]) cwizard.add_step(AccountFormMail, _("Mail"), [dict(classes="btn-primary submit", label=_("Create")), dict(classes="btn-inverse prev", label=_("Previous"))], formtpl="admin/mailform.html") if request.method == "POST": retcode, data = cwizard.validate_step(request) if retcode == -1: raise AdminError(data) if retcode == 1: return ajax_simple_response(dict( status="ok", title=cwizard.get_title(data + 1), stepid=data )) if retcode == 2: return ajax_simple_response(dict( status="ok", respmsg=_("Account created") )) from modoboa.lib.templatetags.lib_tags import render_form return ajax_simple_response(dict( status="ko", stepid=data, form=render_form(cwizard.steps[data]["form"]) )) cwizard.create_forms() ctx.update(steps=cwizard.steps) ctx.update(subtitle="1. %s" % cwizard.steps[0]['title']) return render(request, tplname, ctx)