当前位置: 首页>>代码示例>>Python>>正文


Python webutils.ajax_simple_response函数代码示例

本文整理汇总了Python中modoboa.lib.webutils.ajax_simple_response函数的典型用法代码示例。如果您正苦于以下问题:Python ajax_simple_response函数的具体用法?Python ajax_simple_response怎么用?Python ajax_simple_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ajax_simple_response函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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 ajax_simple_response(dict(status="ok", respmsg=_("Message sent")))
    return ajax_simple_response(dict(status="ko", respmsg=error))
开发者ID:Tdey,项目名称:modoboa,代码行数:7,代码来源:views.py

示例2: profile

def profile(request, tplname='core/user_profile.html'):
    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"])
            return ajax_simple_response(dict(
                status="ok", respmsg=_("Profile updated")
            ))
        return ajax_simple_response({
            "status": "ko",
            "errors": form.errors
        })

    form = ProfileForm(update_password, instance=request.user)
    return ajax_simple_response({
        "status": "ok",
        "content": _render_to_string(request, tplname, {
            "form": form
        })
    })
开发者ID:schiiz1,项目名称:modoboa,代码行数:28,代码来源:user.py

示例3: 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 ajax_simple_response({"status": "ko", "prefix": form.app, "errors": form.errors})
    return ajax_simple_response(dict(status="ok", respmsg=_("Parameters saved")))
开发者ID:simonkern,项目名称:modoboa,代码行数:9,代码来源:admin.py

示例4: newaccount

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"]
        mailform.save(request.user, account)

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

示例5: graphs

def graphs(request):
    gset = request.GET.get("gset", None)
    gsets = events.raiseDictEvent("GetGraphSets")
    if not gset in gsets:
        raise ModoboaException(_("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 ajax_simple_response({"status": "ok"})
            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 ajax_simple_response({"status": "ok"})
        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 ModoboaException(_("Bad custom period"))
        start = request.GET["start"]
        end = request.GET["end"]
        G = Grapher()
        period_name = "%s_%s" % (start.replace('-', ''), end.replace('-', ''))
        for tpl in gsets[gset].get_graphs():
            tplvars['graphs'].append(tpl.display_name)
            G.process(
                tplvars["domain"], period_name, str2Time(*start.split('-')),
                str2Time(*end.split('-')), tpl
            )
        tplvars["period_name"] = period_name
        tplvars["start"] = start
        tplvars["end"] = end
    else:
        tplvars['graphs'] = gsets[gset].get_graph_names()

    return ajax_simple_response(dict(
        status="ok",
        content=_render_to_string(request, "stats/graphs.html", tplvars)
    ))
开发者ID:schiiz1,项目名称:modoboa,代码行数:48,代码来源:views.py

示例6: 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)
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:29,代码来源:views.py

示例7: delaccount

def delaccount(request, accountid):
    keepdir = True if request.POST.get("keepdir", "false") == "true" else False

    User.objects.get(pk=accountid).delete(request.user, keepdir)

    msg = ungettext("Account deleted", "Accounts deleted", 1)
    return ajax_simple_response({"status": "ok", "respmsg": msg})
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:7,代码来源:views.py

示例8: 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 = request.user.get_mailboxes(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 AdminError(_("Invalid request"))
    page = get_listing_page(mboxes, request.GET.get("page", 1))
    return ajax_simple_response({
        "status": "ok",
        "page": page.number,
        "paginbar": pagination_bar(page),
        "table": _render_to_string(request, tplname, {
            "mboxes": page
        })
    })
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:30,代码来源:views.py

示例9: 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)
开发者ID:schiiz1,项目名称:modoboa,代码行数:30,代码来源:views.py

示例10: remove_filters_set

def remove_filters_set(request, name):
    sc = SieveClient(user=request.user.username,
                     password=request.session["password"])
    try:
        sc.deletescript(name)
    except SieveClientError, e:
        return ajax_simple_response(dict(status="ko", respmsg=str(e)))
开发者ID:schiiz1,项目名称:modoboa,代码行数:7,代码来源:views.py

示例11: newdomain

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

示例12: viewparameters

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

示例13: empty

def empty(request, name):
    if name != parameters.get_user(request.user, "TRASH_FOLDER"):
        raise WebmailError(_("Invalid request"))
    get_imapconnector(request).empty(name)
    content = "<div class='alert alert-info'>%s</div>" % _("Empty mailbox")
    return ajax_simple_response(dict(
            status="ok", listing=content, mailbox=name
            ))
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:8,代码来源:views.py

示例14: move

def move(request):
    for arg in ["msgset", "to"]:
        if not arg in request.GET:
            raise WebmailError(_("Invalid request"))
    mbc = get_imapconnector(request)
    mbc.move(request.GET["msgset"], request.session["mbox"], request.GET["to"])
    resp = listmailbox(request, request.session["mbox"], update_session=False)
    resp.update(status="ok")
    return ajax_simple_response(resp)
开发者ID:ricardopadilha,项目名称:modoboa,代码行数:9,代码来源:views.py

示例15: delaccount

def delaccount(request):
    selection = request.GET["selection"].split(",")
    keepdir = True if request.GET.get("keepdir", "false") == "true" else False

    for account in User.objects.filter(id__in=selection):
        account.delete(request.user, keepdir)

    msg = ungettext("Account deleted", "Accounts deleted", len(selection))
    return ajax_simple_response({"status": "ok", "respmsg": msg})
开发者ID:juju2013,项目名称:modoboa,代码行数:9,代码来源:views.py


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