本文整理汇总了Python中modoboa.lib.web_utils.render_to_json_response函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_json_response函数的具体用法?Python render_to_json_response怎么用?Python render_to_json_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_json_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: profile
def profile(request, tplname='core/user_profile.html'):
"""Profile detail/update view."""
update_password = True
if True in events.raiseQueryEvent("PasswordChange", request.user):
update_password = False
if request.method == "POST":
form = ProfileForm(
update_password, request.POST, instance=request.user
)
if form.is_valid():
form.save()
if update_password and form.cleaned_data["confirmation"] != "":
request.session["password"] = encrypt(
form.cleaned_data["confirmation"])
translation.activate(request.user.language)
request.session[translation.LANGUAGE_SESSION_KEY] = (
request.user.language)
return render_to_json_response(_("Profile updated"))
return render_to_json_response(
{'form_errors': form.errors}, status=400)
form = ProfileForm(update_password, instance=request.user)
return render_to_json_response({
"content": _render_to_string(request, tplname, {
"form": form
})
})
开发者ID:haitao-wang,项目名称:modoboa,代码行数:28,代码来源:user.py
示例2: shared_calendar
def shared_calendar(request, pk):
"""Edit or remove a shared calendar."""
try:
scal = SharedCalendar.objects.select_related().get(pk=pk)
except SharedCalendar.DoesNotExist:
raise NotFound
if not request.user.can_access(scal.domain):
raise PermDeniedException
if request.method == "DELETE":
if not request.user.can_access(scal.domain):
raise PermDeniedException
scal.delete()
return render_to_json_response(_("Calendar removed"))
if request.method == "POST":
form = SharedCalendarForm(request.user, request.POST, instance=scal)
if form.is_valid():
form.save()
return render_to_json_response(_("Calendar updated"))
return render_to_json_response(
{"form_errors": form.errors}, status=400
)
form = SharedCalendarForm(request.user, instance=scal)
return render(request, "common/generic_modal_form.html", {
"form": form,
"formid": "sharedcal_form",
"title": scal.name,
"action": reverse("radicale:shared_calendar", args=[scal.pk]),
"action_classes": "submit",
"action_label": _("Submit")
})
开发者ID:kaxdev,项目名称:modoboa,代码行数:30,代码来源:views.py
示例3: graphs
def graphs(request):
gset = request.GET.get("gset", None)
gsets = events.raiseDictEvent("GetGraphSets")
if gset not in gsets:
raise NotFound(_("Unknown graphic set"))
searchq = request.GET.get("searchquery", None)
period = request.GET.get("period", "day")
tplvars = dict(graphs={}, period=period)
domain = check_domain_access(request.user, searchq)
if domain is None:
return render_to_json_response({})
tplvars["domain"] = domain
if period == "custom":
if "start" not in request.GET or "end" not in request.GET:
raise BadRequest(_("Bad custom period"))
start = request.GET["start"]
end = request.GET["end"]
expr = re.compile(r'[:\- ]')
period_name = "%s_%s" % (expr.sub('', start), expr.sub('', end))
start = date_to_timestamp(expr.split(start))
end = date_to_timestamp(expr.split(end))
else:
end = int(time.mktime(time.localtime()))
start = "-1%s" % period
period_name = period
tplvars["graphs"] = gsets[gset].export(tplvars["domain"], start, end)
tplvars["period_name"] = period_name
tplvars["start"] = start
tplvars["end"] = end
return render_to_json_response(tplvars)
开发者ID:Arvedui,项目名称:modoboa-stats,代码行数:33,代码来源:views.py
示例4: 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")
try:
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
)
except (BadArgument, BadValue) as inst:
raise BadRequest(str(inst))
sc.pushscript(fset.name, str(fset))
return render_to_json_response(okmsg)
return render_to_json_response({'form_errors': form.errors}, status=400)
开发者ID:bearstech,项目名称:modoboa-sievefilters,代码行数:29,代码来源:views.py
示例5: newfolder
def newfolder(request, tplname="webmail/folder.html"):
mbc = IMAPconnector(user=request.user.username,
password=request.session["password"])
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 render_to_json_response({
'respmsg': _("Mailbox created"),
'newmb': form.cleaned_data["name"], 'parent': pf
})
return render_to_json_response({'form_errors': form.errors}, status=400)
ctx = {"title": _("Create a new mailbox"),
"formid": "mboxform",
"action": reverse("webmail:folder_add"),
"action_label": _("Create"),
"action_classes": "submit",
"withunseen": False,
"selectonly": True,
"mboxes": mbc.getmboxes(request.user),
"hdelimiter": mbc.hdelimiter,
"form": FolderForm(),
"selected": None}
return render(request, tplname, ctx)
开发者ID:kaxdev,项目名称:modoboa,代码行数:28,代码来源:views.py
示例6: profile
def profile(request, tplname="core/user_profile.html"):
"""Profile detail/update view."""
update_password = True
results = signals.allow_password_change.send(
sender="profile", user=request.user)
if True in [result[1] for result in results]:
update_password = False
if request.method == "POST":
form = ProfileForm(
update_password, request.POST, instance=request.user
)
if form.is_valid():
form.save()
if update_password and form.cleaned_data["confirmation"] != "":
request.session["password"] = force_text(encrypt(
form.cleaned_data["confirmation"]
))
translation.activate(request.user.language)
request.session[translation.LANGUAGE_SESSION_KEY] = (
request.user.language)
return render_to_json_response(_("Profile updated"))
return render_to_json_response(
{"form_errors": form.errors}, status=400)
form = ProfileForm(update_password, instance=request.user)
return render_to_json_response({
"content": render_to_string(tplname, {
"form": form
}, request)
})
开发者ID:brucewu16899,项目名称:modoboa,代码行数:31,代码来源:user.py
示例7: autoreply
def autoreply(request, tplname="modoboa_postfix_autoreply/autoreply.html"):
mb = Mailbox.objects.get(user=request.user.id)
try:
arm = ARmessage.objects.get(mbox=mb.id)
except ARmessage.DoesNotExist:
arm = None
if request.method == "POST":
if arm:
form = ARmessageForm(mb, request.POST, instance=arm)
else:
form = ARmessageForm(mb, request.POST)
if form.is_valid():
form.save()
return render_to_json_response(
_("Auto reply message updated successfully.")
)
return render_to_json_response(
{"form_errors": form.errors}, status=400
)
form = ARmessageForm(mb, instance=arm)
return render_to_json_response({
"content": render_to_string(tplname, {"form": form}, request),
"onload_cb": "autoreply_cb"
})
开发者ID:bearstech,项目名称:modoboa-postfix-autoreply,代码行数:26,代码来源:views.py
示例8: forward
def forward(request, tplname="admin/forward.html"):
mb = request.user.mailbox
al = Alias.objects.filter(address=mb.full_address, internal=False).first()
if request.method == "POST":
form = ForwardForm(request.POST)
if form.is_valid():
if al is None:
al = Alias.objects.create(
address=mb.full_address, domain=mb.domain,
enabled=mb.user.is_active)
recipients = form.get_recipients()
if form.cleaned_data["keepcopies"]:
recipients.append(mb.full_address)
al.set_recipients(recipients)
al.post_create(request.user)
return render_to_json_response(_("Forward updated"))
return render_to_json_response(
{'form_errors': form.errors}, status=400
)
form = ForwardForm()
if al is not None and al.recipients:
form.fields["dest"].initial = al.recipients
if al.aliasrecipient_set.filter(r_mailbox=mb.pk).exists():
form.fields["keepcopies"].initial = True
return render_to_json_response({
"content": _render_to_string(request, tplname, {
"form": form
})
})
开发者ID:carriercomm,项目名称:modoboa,代码行数:31,代码来源:user.py
示例9: mark_messages
def mark_messages(request, selection, mtype, recipient_db=None):
"""Mark a selection of messages as spam.
:param str selection: message unique identifier
:param str mtype: type of marking (spam or ham)
"""
if not manual_learning_enabled(request.user):
return render_to_json_response({"status": "ok"})
if recipient_db is None:
recipient_db = (
"user" if request.user.group == "SimpleUsers" else "global"
)
selection = check_mail_id(request, selection)
connector = get_connector()
saclient = SpamassassinClient(request.user, recipient_db)
for item in selection:
rcpt, mail_id = item.split()
content = connector.get_mail_content(mail_id)
result = saclient.learn_spam(rcpt, content) if mtype == "spam" \
else saclient.learn_ham(rcpt, content)
if not result:
break
connector.set_msgrcpt_status(rcpt, mail_id, mtype[0].upper())
if saclient.error is None:
saclient.done()
message = ungettext("%(count)d message processed successfully",
"%(count)d messages processed successfully",
len(selection)) % {"count": len(selection)}
else:
message = saclient.error
status = 400 if saclient.error else 200
return render_to_json_response({
"message": message, "reload": True
}, status=status)
开发者ID:kaxdev,项目名称:modoboa,代码行数:34,代码来源:views.py
示例10: autoreply
def autoreply(request, tplname="postfix_autoreply/autoreply.html"):
mb = Mailbox.objects.get(user=request.user.id)
try:
arm = ARmessage.objects.get(mbox=mb.id)
except ARmessage.DoesNotExist:
arm = None
if request.method == "POST":
if arm:
form = ARmessageForm(request.POST, instance=arm)
else:
form = ARmessageForm(request.POST)
if form.is_valid():
arm = form.save(commit=False)
arm.fromdate = form.cleaned_data["fromdate"]
arm.untildate = form.cleaned_data["untildate"]
arm.mbox = mb
arm.save()
return render_to_json_response(
_("Auto reply message updated successfully.")
)
return render_to_json_response(
{"form_errors": form.errors}, status=400
)
form = ARmessageForm(instance=arm)
return render_to_json_response({
"content": _render_to_string(request, tplname, {"form": form}),
"onload_cb": "autoreply_cb"
})
开发者ID:kaxdev,项目名称:modoboa,代码行数:30,代码来源:views.py
示例11: get_templates
def get_templates(request, ftype):
if ftype == "condition":
return render_to_json_response(
FilterForm([], [], request).cond_templates
)
return render_to_json_response(
FilterForm([], [], request).action_templates
)
开发者ID:bearstech,项目名称:modoboa-sievefilters,代码行数:8,代码来源:views.py
示例12: 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 render_to_json_response(_("Filter removed"))
return render_to_json_response(_("Failed to remove filter"), status=500)
开发者ID:bearstech,项目名称:modoboa-sievefilters,代码行数:8,代码来源:views.py
示例13: send_virus
def send_virus(request):
status, error = sendmail_fromfile(
"[email protected]", request.user.username,
os.path.join(settings.MODOBOA_DIR, "tmp/virus.msg")
)
if status:
return render_to_json_response(_("Message sent"))
return render_to_json_response(error, status=500)
开发者ID:kaxdev,项目名称:modoboa,代码行数:8,代码来源:views.py
示例14: scan_for_services
def scan_for_services(request):
try:
Service.objects.load_from_master_cf()
except IOError as e:
return render_to_json_response([str(e)], status=500)
return render_to_json_response(
dict((srv.name, srv.id) for srv in Service.objects.all())
)
开发者ID:bearstech,项目名称:modoboa,代码行数:9,代码来源:views.py
示例15: saveparameters
def saveparameters(request):
for formdef in parameters.get_admin_forms(request.POST):
form = formdef["form"]
if form.is_valid():
form.save()
form.to_django_settings()
continue
return render_to_json_response(
{'form_errors': form.errors, 'prefix': form.app}, status=400
)
return render_to_json_response(_("Parameters saved"))
开发者ID:Norcoen,项目名称:modoboa,代码行数:11,代码来源:admin.py
示例16: editfolder
def editfolder(request, tplname="modoboa_webmail/folder.html"):
mbc = IMAPconnector(user=request.user.username,
password=request.session["password"])
ctx = {"title": _("Edit mailbox"),
"formid": "mboxform",
"action": reverse("modoboa_webmail:folder_change"),
"action_label": _("Update"),
"action_classes": "submit",
"withunseen": False,
"selectonly": True,
"hdelimiter": mbc.hdelimiter}
if request.method == "POST":
form = FolderForm(request.POST)
if form.is_valid():
pf = request.POST.get("parent_folder", None)
oldname, oldparent = separate_mailbox(
request.POST["oldname"], sep=mbc.hdelimiter
)
res = {'respmsg': _("Mailbox updated")}
if form.cleaned_data["name"] != oldname \
or (pf != oldparent):
newname = form.cleaned_data["name"] if pf is None \
else mbc.hdelimiter.join([pf, form.cleaned_data["name"]])
mbc.rename_folder(request.POST["oldname"], newname)
res["oldmb"] = oldname
res["newmb"] = form.cleaned_data["name"]
res["oldparent"] = oldparent
res["newparent"] = pf
WebmailNavigationParameters(request).remove('mbox')
return render_to_json_response(res)
return render_to_json_response(
{'form_errors': form.errors}, status=400)
name = request.GET.get("name", None)
if name is None:
raise BadRequest(_("Invalid request"))
shortname, parent = separate_mailbox(name, sep=mbc.hdelimiter)
ctx = {"title": _("Edit mailbox"),
"formid": "mboxform",
"action": reverse("modoboa_webmail:folder_change"),
"action_label": _("Update"),
"action_classes": "submit",
"withunseen": False,
"selectonly": True,
"hdelimiter": mbc.hdelimiter,
"mboxes": mbc.getmboxes(request.user, until_mailbox=parent),
"form": FolderForm(),
"selected": parent}
ctx["form"].fields["oldname"].initial = name
ctx["form"].fields["name"].initial = shortname
return render(request, tplname, ctx)
开发者ID:digideskio,项目名称:modoboa-webmail,代码行数:53,代码来源:views.py
示例17: 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 = []
connector = get_connector()
valid_addresses = get_user_valid_addresses(request.user)
for mid in mail_id:
r, i = mid.split()
if valid_addresses and r not in valid_addresses:
continue
msgrcpts += [connector.get_recipient_message(r, i)]
if request.user.group == "SimpleUsers" and \
parameters.get_admin("USER_CAN_RELEASE") == "no":
for msgrcpt in msgrcpts:
connector.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 render_to_json_response({
"message": 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:
connector.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
status = 400 if error else 200
return render_to_json_response({
"message": message,
"url": QuarantineNavigationParameters(request).back_to_listing()
}, status=status)
开发者ID:kaxdev,项目名称:modoboa,代码行数:51,代码来源:views.py
示例18: _validate_alias
def _validate_alias(request, form, successmsg, callback=None):
"""Alias validation
Common function shared between creation and modification actions.
"""
if form.is_valid():
try:
alias = form.save()
except IntegrityError:
raise Conflict(_("Alias with this name already exists"))
if callback:
callback(request.user, alias)
return render_to_json_response(successmsg)
return render_to_json_response({'form_errors': form.errors}, status=400)
开发者ID:cubicuboctahedron,项目名称:modoboa,代码行数:15,代码来源:alias.py
示例19: learning_recipient
def learning_recipient(request):
"""A view to select the recipient database of a learning action."""
if request.method == "POST":
form = LearningRecipientForm(request.user, request.POST)
if form.is_valid():
return mark_messages(
request,
form.cleaned_data["selection"].split(","),
form.cleaned_data["ltype"],
form.cleaned_data["recipient"]
)
return render_to_json_response(
{"form_errors": form.errors}, status=400
)
ltype = request.GET.get("type", None)
selection = request.GET.get("selection", None)
if ltype is None or selection is None:
raise BadRequest
form = LearningRecipientForm(request.user)
form.fields["ltype"].initial = ltype
form.fields["selection"].initial = selection
return render(request, "common/generic_modal_form.html", {
"title": _("Select a database"),
"formid": "learning_recipient_form",
"action": reverse("amavis:learning_recipient_set"),
"action_classes": "submit",
"action_label": _("Validate"),
"form": form
})
开发者ID:kaxdev,项目名称:modoboa,代码行数:29,代码来源:views.py
示例20: check_top_notifications
def check_top_notifications(request):
"""
AJAX service to check for new top notifications to display.
"""
return render_to_json_response(
events.raiseQueryEvent("TopNotifications", request, True)
)
开发者ID:whyscream,项目名称:modoboa,代码行数:7,代码来源:admin.py
注:本文中的modoboa.lib.web_utils.render_to_json_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论