本文整理汇总了Python中modoboa.lib.webutils.ajax_response函数的典型用法代码示例。如果您正苦于以下问题:Python ajax_response函数的具体用法?Python ajax_response怎么用?Python ajax_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ajax_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submitfilter
def submitfilter(request, setname, okmsg, tplname, tplctx, update=False, sc=None):
form = build_filter_form_from_qdict(request)
if form.is_valid():
if sc is None:
sc = SieveClient(user=request.user.username,
password=request.session["password"])
fset = sc.getscript(setname, format="fset")
conditions, actions = form.tofilter()
match_type = form.cleaned_data["match_type"]
if match_type == "all":
match_type = "anyof"
conditions = [("true",)]
fltname = form.cleaned_data["name"].encode("utf-8")
if not update:
fset.addfilter(fltname, conditions, actions,
match_type)
else:
oldname = request.POST["oldname"].encode("utf-8")
fset.updatefilter(
oldname, fltname, conditions, actions, match_type
)
try:
sc.pushscript(fset.name, str(fset))
except SieveClientError as e:
return ajax_response(request, "ko", respmsg=str(e))
return ajax_response(request, respmsg=okmsg, ajaxnav=True)
tplctx = build_filter_ctx(tplctx, form)
return ajax_response(request, status="ko", template=tplname, **tplctx)
示例2: removefilter
def removefilter(request, setname, fname):
sc = SieveClient(user=request.user.username,
password=request.session["password"])
fset = sc.getscript(setname, format="fset")
if fset.removefilter(fname.encode("utf-8")):
sc.pushscript(fset.name, str(fset))
return ajax_response(request, respmsg=_("Filter removed"))
return ajax_response(request, "ko", respmsg=_("Failed to remove filter"))
示例3: release
def release(request, mail_id):
"""Release message selection.
:param str mail_id: message unique identifier
"""
mail_id = check_mail_id(request, mail_id)
msgrcpts = []
wrapper = get_wrapper()
mb = Mailbox.objects.get(user=request.user) \
if request.user.group == 'SimpleUsers' else None
for mid in mail_id:
r, i = mid.split()
if mb is not None and r != mb.full_address \
and not r in mb.alias_addresses:
continue
msgrcpts += [wrapper.get_recipient_message(r, i)]
if mb is not None and parameters.get_admin("USER_CAN_RELEASE") == "no":
# FIXME : can't use this syntax because extra SQL (using
# .extra() for postgres) is not propagated (the 'tables'
# parameter is lost somewhere...)
#
# msgrcpts.update(rs='p')
for msgrcpt in msgrcpts:
msgrcpt.rs = 'p'
msgrcpt.save()
message = ungettext("%(count)d request sent",
"%(count)d requests sent",
len(mail_id)) % {"count": len(mail_id)}
return ajax_response(
request, "ok", respmsg=message,
url=QuarantineNavigationParameters(request).back_to_listing()
)
amr = AMrelease()
error = None
for rcpt in msgrcpts:
result = amr.sendreq(rcpt.mail.mail_id, rcpt.mail.secret_id, rcpt.rid.email)
if result:
rcpt.rs = 'R'
rcpt.save()
else:
error = result
break
if not error:
message = ungettext("%(count)d message released successfully",
"%(count)d messages released successfully",
len(mail_id)) % {"count": len(mail_id)}
else:
message = error
return ajax_response(
request, "ko" if error else "ok", respmsg=message,
url=QuarantineNavigationParameters(request).back_to_listing()
)
示例4: release
def release(request, mail_id):
"""Release message selection.
:param str mail_id: message unique identifier
"""
mail_id = check_mail_id(request, mail_id)
msgrcpts = []
wrapper = get_wrapper()
mb = Mailbox.objects.get(user=request.user) \
if request.user.group == 'SimpleUsers' else None
for mid in mail_id:
r, i = mid.split()
if mb is not None and r != mb.full_address \
and not r in mb.alias_addresses:
continue
msgrcpts += [wrapper.get_recipient_message(r, i)]
if mb is not None and parameters.get_admin("USER_CAN_RELEASE") == "no":
for msgrcpt in msgrcpts:
wrapper.set_msgrcpt_status(
msgrcpt.rid.email, msgrcpt.mail.mail_id, 'p'
)
message = ungettext("%(count)d request sent",
"%(count)d requests sent",
len(mail_id)) % {"count": len(mail_id)}
return ajax_response(
request, "ok", respmsg=message,
url=QuarantineNavigationParameters(request).back_to_listing()
)
amr = AMrelease()
error = None
for rcpt in msgrcpts:
result = amr.sendreq(
rcpt.mail.mail_id, rcpt.mail.secret_id, rcpt.rid.email
)
if result:
wrapper.set_msgrcpt_status(rcpt.rid.email, rcpt.mail.mail_id, 'R')
else:
error = result
break
if not error:
message = ungettext("%(count)d message released successfully",
"%(count)d messages released successfully",
len(mail_id)) % {"count": len(mail_id)}
else:
message = error
return ajax_response(
request, "ko" if error else "ok", respmsg=message,
url=QuarantineNavigationParameters(request).back_to_listing()
)
示例5: delattachment
def delattachment(request):
if not "compose_mail" in request.session or not "name" in request.GET or not request.GET["name"]:
return ajax_response(request, "ko", respmsg=_("Bad query"))
error = None
for att in request.session["compose_mail"]["attachments"]:
if att["tmpname"] == request.GET["name"]:
request.session["compose_mail"]["attachments"].remove(att)
fullpath = os.path.join(settings.MEDIA_ROOT, "webmail", att["tmpname"])
try:
os.remove(fullpath)
except OSError, e:
error = _("Failed to remove attachment: ") + str(e)
break
request.session.modified = True
return ajax_response(request)
示例6: download_filters_set
def download_filters_set(request, name):
sc = SieveClient(user=request.user.username,
password=request.session["password"])
try:
script = sc.getscript(name)
except SieveClientError, e:
return ajax_response(request, "ko", respmsg=str(e))
示例7: new_filters_set
def new_filters_set(request, tplname="common/generic_modal_form.html"):
ctx = {"title": _("Create a new filters set"),
"formid": "newfiltersset",
"action_label": _("Create"),
"action_classes": "submit",
"action": reverse(new_filters_set),
"withmenu": False,
"withunseen": False}
if request.method == "POST":
form = FiltersSetForm(request.POST)
error = None
if form.is_valid():
sc = SieveClient(user=request.user.username,
password=request.session["password"])
try:
sc.pushscript(form.cleaned_data["name"], "# Empty script",
form.cleaned_data["active"])
except SieveClientError, e:
error = str(e)
else:
return ajax_simple_response({
"status": "ok",
"url": form.cleaned_data["name"],
"active": form.cleaned_data["active"],
"respmsg": _("Filters set created")
})
ctx["form"] = form
ctx["error"] = error
return ajax_response(request, status="ko", template=tplname, **ctx)
示例8: newfolder
def newfolder(request, tplname="webmail/folder.html"):
mbc = IMAPconnector(user=request.user.username,
password=request.session["password"])
ctx = {"title": _("Create a new mailbox"),
"formid": "mboxform",
"action": reverse(newfolder),
"action_label": _("Create"),
"action_classes": "submit",
"withunseen": False,
"selectonly": True,
"mboxes": mbc.getmboxes(request.user),
"hdelimiter": mbc.hdelimiter}
if request.method == "POST":
form = FolderForm(request.POST)
if form.is_valid():
pf = request.POST.get("parent_folder", None)
mbc.create_folder(form.cleaned_data["name"], pf)
return ajax_simple_response(dict(
status="ok", respmsg=_("Mailbox created"), newmb=form.cleaned_data["name"], parent=pf
))
ctx["form"] = form
ctx["selected"] = None
return ajax_response(request, status="ko", template=tplname, **ctx)
ctx["form"] = FolderForm()
ctx["selected"] = None
return _render(request, tplname, ctx)
示例9: process_exception
def process_exception(self, request, exception):
if not isinstance(exception, ModoboaException):
return None
if not request.is_ajax():
return _render_error(request, user_context=dict(error=str(exception)))
return ajax_response(request, status="ko", respmsg=unicode(exception), norefresh=True)
示例10: delfolder
def delfolder(request):
name = request.GET.get("name", None)
if name is None:
raise BadRequest(_("Invalid request"))
mbc = IMAPconnector(user=request.user.username, password=request.session["password"])
mbc.delete_folder(name)
WebmailNavigationParameters(request).remove("mbox")
return ajax_response(request)
示例11: release
def release(request, mail_id):
mail_id = check_mail_id(request, mail_id)
if request.user.group == 'SimpleUsers':
mb = Mailbox.objects.get(user=request.user)
msgrcpts = get_wrapper().get_recipient_messages(mb.full_address, mail_id)
if parameters.get_admin("USER_CAN_RELEASE") == "no":
# FIXME : can't use this syntax because extra SQL (using
# .extra() for postgres) is not propagated (the 'tables'
# parameter is lost somewhere...)
#
# msgrcpts.update(rs='p')
for msgrcpt in msgrcpts:
msgrcpt.rs = 'p'
msgrcpt.save()
message = ungettext("%(count)d request sent",
"%(count)d requests sent",
len(mail_id)) % {"count": len(mail_id)}
return ajax_response(request, "ok", respmsg=message,
url=__back_to_listing(request))
else:
msgrcpts = []
wrapper = get_wrapper()
for mid in mail_id:
r, i = mid.split()
msgrcpts += [wrapper.get_recipient_message(r, i)]
amr = AMrelease()
error = None
for rcpt in msgrcpts:
result = amr.sendreq(rcpt.mail.mail_id, rcpt.mail.secret_id, rcpt.rid.email)
if result:
rcpt.rs = 'R'
rcpt.save()
else:
error = result
break
if not error:
message = ungettext("%(count)d message released successfully",
"%(count)d messages released successfully",
len(mail_id)) % {"count": len(mail_id)}
else:
message = error
return ajax_response(request, "ko" if error else "ok", respmsg=message,
url=__back_to_listing(request))
示例12: move_filter
def move_filter(request, setname, fname, direction):
sc = SieveClient(user=request.user.username,
password=request.session["password"])
try:
fset = sc.getscript(setname, format="fset")
fset.movefilter(fname.encode("utf-8"), direction)
sc.pushscript(setname, str(fset))
except (SieveClientError), e:
return ajax_response(request, "ko", respmsg=str(e))
示例13: process_exception
def process_exception(self, request, exception):
if not isinstance(exception, (WebmailError, ImapError)):
return None
json = request.GET.get("json", False) if request.method == "GET" \
else request.POST.get("json", False)
if json:
return ajax_response(request, status="ko",
respmsg=str(exception), norefresh=True)
return _render_error(request, user_context=dict(error=str(exception)))
示例14: move_filter
def move_filter(request, setname, fname, direction):
sc = SieveClient(user=request.user.username,
password=request.session["password"])
fset = sc.getscript(setname, format="fset")
fset.movefilter(fname.encode("utf-8"), direction)
sc.pushscript(setname, str(fset))
return ajax_response(
request, template="sievefilters/guieditor.html", fs=fset
)
示例15: savefs
def savefs(request, name):
if not "scriptcontent" in request.POST:
return
sc = SieveClient(user=request.user.username, password=request.session["password"])
try:
sc.pushscript(name, request.POST["scriptcontent"])
except SieveClientError, e:
error = str(e)
return ajax_response(request, "ko", respmsg=error)