def index(request, tplname="modoboa_sievefilters/index.html"):
    try:
        sc = SieveClient(user=request.user.username,
                         password=request.session["password"])
    except ConnectionError as e:
        return _render_error(request, user_context={"error": e})

    try:
        active_script, scripts = sc.listscripts()
    except Error as e:
        return _render_error(request, user_context={"error": e})

    if active_script is None:
        active_script = ""
        default_script = "%s/" % scripts[0] if len(scripts) else ""
    else:
        default_script = "%s/" % active_script
    return render(
        request, tplname, {
            "selection": "user",
            "active_script": active_script,
            "default_script": default_script,
            "scripts": sorted(scripts),
            "hdelimiter": get_imapconnector(request).hdelimiter
        })
Beispiel #2
0
    def process_exception(self, request, exception):
        if not isinstance(exception, ModoboaException):
            return None

        if request.is_ajax() or "/api/" in request.path:
            if exception.http_code is None:
                return ajax_response(request,
                                     status="ko",
                                     respmsg=unicode(exception),
                                     norefresh=True)
            return render_to_json_response(unicode(exception),
                                           status=exception.http_code)
        return _render_error(request, user_context=dict(error=str(exception)))
Beispiel #3
0
    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))
            )
        if exception.http_code is None:
            return ajax_response(
                request, status="ko", respmsg=unicode(exception), norefresh=True
            )
        return render_to_json_response(
            unicode(exception), status=exception.http_code
        )
def index(request, tplname="modoboa_sievefilters/index.html"):
    try:
        sc = SieveClient(user=request.user.username,
                         password=request.session["password"])
    except ConnectionError as e:
        return _render_error(request, user_context={"error": e})

    try:
        active_script, scripts = sc.listscripts()
    except Error as e:
        return _render_error(request, user_context={"error": e})

    if active_script is None:
        active_script = ""
        default_script = "%s/" % scripts[0] if len(scripts) else ""
    else:
        default_script = "%s/" % active_script
    return render(request, tplname, {
        "selection": "user",
        "active_script": active_script,
        "default_script": default_script,
        "scripts": sorted(scripts),
        "hdelimiter": get_imapconnector(request).hdelimiter
    })
Beispiel #5
0
    def process_exception(self, request, exception):
        if not isinstance(exception, ModoboaException):
            return None

        if request.is_ajax() or "/api/" in request.path:
            if exception.http_code is None:
                return ajax_response(
                    request, status="ko", respmsg=smart_text(exception),
                    norefresh=True
                )
            return render_to_json_response(
                smart_text(exception), status=exception.http_code
            )
        return _render_error(
            request, user_context={"error": smart_text(exception)}
        )