• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python webutils.render_to_json_response函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中modoboa.lib.webutils.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: 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:Marx86,项目名称:modoboa,代码行数:28,代码来源:views.py


示例2: 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:JHei,项目名称:modoboa,代码行数:30,代码来源:views.py


示例3: 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:JHei,项目名称:modoboa,代码行数:7,代码来源:views.py


示例4: 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:JHei,项目名称:modoboa,代码行数:7,代码来源:views.py


示例5: send_spam

def send_spam(request):
    status, error = sendmail_simple(
        "[email protected]",
        request.user.username,
        content="""
This is the GTUBE, the
        Generic
        Test for
        Unsolicited
        Bulk
        Email

If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):

XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X

You should send this test mail from an account outside of your network.
""",
    )
    if status:
        return render_to_json_response(_("Message sent"))
    return render_to_json_response(respmsg=error, status=500)
开发者ID:JHei,项目名称:modoboa,代码行数:25,代码来源:views.py


示例6: 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:finid,项目名称:modoboa,代码行数:30,代码来源:views.py


示例7: 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(newfolder),
        "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:jmfield2,项目名称:modoboa,代码行数:28,代码来源:views.py


示例8: new_filters_set

def new_filters_set(request, tplname="common/generic_modal_form.html"):
    if request.method == "POST":
        form = FiltersSetForm(request.POST)
        if form.is_valid():
            sc = SieveClient(user=request.user.username, password=request.session["password"])
            sc.pushscript(form.cleaned_data["name"], "# Empty script", form.cleaned_data["active"])
            return render_to_json_response(
                {
                    "url": form.cleaned_data["name"],
                    "active": form.cleaned_data["active"],
                    "respmsg": _("Filters set created"),
                }
            )
        return render_to_json_response({"form_errors": form.errors}, status=400)

    ctx = {
        "title": _("Create a new filters set"),
        "formid": "newfiltersset",
        "action_label": _("Create"),
        "action_classes": "submit",
        "action": reverse(new_filters_set),
        "withmenu": False,
        "withunseen": False,
        "form": FiltersSetForm(),
    }
    return render(request, tplname, ctx)
开发者ID:JHei,项目名称:modoboa,代码行数:26,代码来源:views.py


示例9: editdomain

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)
开发者ID:Marx86,项目名称:modoboa,代码行数:31,代码来源:domain.py


示例10: edit

def edit(request, rdom_id, tplname='common/tabforms.html'):
    rdom = RelayDomain.objects.get(pk=rdom_id)
    if not request.user.can_access(rdom):
        raise PermDeniedException
    instances = {'general': rdom}
    events.raiseEvent("FillRelayDomainInstances", request.user, rdom, instances)
    if request.method == 'POST':
        rdom.oldname = rdom.name
        form = RelayDomainForm(request.user, request.POST, instances=instances)
        if form.is_valid():
            form.save(request.user)
            events.raiseEvent('RelayDomainModified', rdom)
            return render_to_json_response(_('Relay domain modified'))

        return render_to_json_response(
            {'form_errors': form.errors}, status=400
        )
    ctx = {
        'action': reverse(edit, args=[rdom.id]),
        'formid': 'rdomform',
        'title': rdom.name,
        'action_label': _("Update"),
        'action_classes': "submit",
        'tabs': RelayDomainForm(request.user, instances=instances)
    }
    return render(request, tplname, ctx)
开发者ID:SonRiab,项目名称:modoboa,代码行数:26,代码来源: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:Marx86,项目名称:modoboa,代码行数:8,代码来源:views.py


示例12: 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:SonRiab,项目名称:modoboa,代码行数:9,代码来源:views.py


示例13: 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:finid,项目名称:modoboa,代码行数:11,代码来源:admin.py


示例14: editfolder

def editfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username, password=request.session["password"])
    ctx = {
        "title": _("Edit mailbox"),
        "formid": "mboxform",
        "action": reverse(editfolder),
        "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(editfolder),
        "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:jmfield2,项目名称:modoboa,代码行数:53,代码来源:views.py


示例15: graphs

def graphs(request):
    gset = request.GET.get("gset", None)
    gsets = events.raiseDictEvent("GetGraphSets")
    if not gset in gsets:
        raise NotFound(_("Unknown graphic set"))
    searchq = request.GET.get("searchquery", None)
    period = request.GET.get("period", "day")
    tplvars = dict(graphs=[], period=period)
    if searchq in [None, "global"]:
        if not request.user.is_superuser:
            if not Domain.objects.get_for_admin(request.user).count():
                return render_to_json_response({})
            tplvars.update(
                domain=Domain.objects.get_for_admin(request.user)[0].name
            )
        else:
            tplvars.update(domain="global")
    else:
        domain = Domain.objects.filter(name__contains=searchq)
        if domain.count() != 1:
            return render_to_json_response({})
        if not request.user.can_access(domain[0]):
            raise PermDeniedException
        tplvars.update(domain=domain[0].name)

    if period == "custom":
        if not "start" in request.GET or not "end" in request.GET:
            raise BadRequest(_("Bad custom period"))
        start = request.GET["start"]
        end = request.GET["end"]
        G = Grapher()
        expr = re.compile(r'[:\- ]')
        period_name = "%s_%s" % (expr.sub('', start), expr.sub('', end))
        for tpl in gsets[gset].get_graphs():
            tplvars['graphs'].append(tpl.display_name)
            G.process(
                tplvars["domain"], period_name, str2Time(*expr.split(start)),
                str2Time(*expr.split(end)), tpl
            )
        tplvars["period_name"] = period_name
        tplvars["start"] = start
        tplvars["end"] = end
    else:
        tplvars['graphs'] = gsets[gset].get_graph_names()

    return render_to_json_response({
        'content': _render_to_string(request, "stats/graphs.html", tplvars)
    })
开发者ID:Marx86,项目名称:modoboa,代码行数:48,代码来源:views.py


示例16: viewparameters

def viewparameters(request, tplname='core/parameters.html'):
    return render_to_json_response({
        "left_selection": "parameters",
        "content": _render_to_string(request, tplname, {
            "forms": parameters.get_admin_forms
        })
    })
开发者ID:finid,项目名称:modoboa,代码行数:7,代码来源:admin.py


示例17: 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:finid,项目名称:modoboa,代码行数:7,代码来源:admin.py


示例18: submailboxes

def submailboxes(request):
    """Retrieve the sub mailboxes of a mailbox."""
    topmailbox = request.GET.get('topmailbox', '')
    with_unseen = request.GET.get('unseen', None)
    mboxes = get_imapconnector(request).getmboxes(
        request.user, topmailbox, unseen_messages=with_unseen == 'true')
    return render_to_json_response(mboxes)
开发者ID:finid,项目名称:modoboa,代码行数:7,代码来源:views.py


示例19: _validate_alias

def _validate_alias(request, form, successmsg, callback=None):
    """Alias validation

    Common function shared between creation and modification actions.
    """
    if form.is_valid():
        form.set_recipients()
        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:finid,项目名称:modoboa,代码行数:16,代码来源:alias.py


示例20: list_quotas

def list_quotas(request, tplname="admin/quotas.html"):
    from modoboa.lib.dbutils import db_type

    sort_order, sort_dir = get_sort_order(request.GET, "address")
    mboxes = Mailbox.objects.get_for_admin(
        request.user, request.GET.get("searchquery", None)
    )
    mboxes = mboxes.exclude(quota=0)
    if sort_order in ["address", "quota", "quota_value__bytes"]:
        mboxes = mboxes.order_by("%s%s" % (sort_dir, sort_order))
    elif sort_order == "quota_usage":
        if db_type() == "postgres":
            select = '(admin_quota.bytes::float / (CAST(admin_mailbox.quota AS BIGINT) * 1048576)) * 100'
        else:
            select = 'admin_quota.bytes / (admin_mailbox.quota * 1048576) * 100'
        mboxes = mboxes.extra(
            select={'quota_usage': select},
            where=["admin_quota.mbox_id=admin_mailbox.id"],
            tables=["admin_quota"],
            order_by=["%s%s" % (sort_dir, sort_order)]
        )
    else:
        raise BadRequest(_("Invalid request"))
    page = get_listing_page(mboxes, request.GET.get("page", 1))
    return render_to_json_response({
        "page": page.number,
        "paginbar": pagination_bar(page),
        "table": _render_to_string(request, tplname, {
            "mboxes": page
        })
    })
开发者ID:SonRiab,项目名称:modoboa,代码行数:31,代码来源:identity.py



注:本文中的modoboa.lib.webutils.render_to_json_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tools.get_global_parameter函数代码示例发布时间:2022-05-27
下一篇:
Python webutils.ajax_simple_response函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap