linkding/bookmarks/views/turbo.py
Sascha Ißbrücker ffaaf0521d
Speed up response times for certain actions (#829)
* return updated HTML from bookmark actions

* open details through URL

* fix details update

* improve modal behavior

* use a frame

* make behaviors properly destroy themselves

* remove page and details params from tag urls

* use separate behavior for details and tags

* remove separate details view

* make it work with other views

* add asset actions

* remove asset refresh for now

* remove details partial

* fix tests

* remove old partials

* update tests

* cache and reuse tags

* extract search autocomplete behavior

* remove details param from pagination

* fix tests

* only return details modal when navigating in frame

* fix link target

* remove unused behaviors

* use auto submit behavior for user select

* fix import
2024-09-16 12:48:19 +02:00

19 lines
694 B
Python

from django.http import HttpRequest, HttpResponse
from django.shortcuts import render as django_render
def accept(request: HttpRequest):
is_turbo_request = "text/vnd.turbo-stream.html" in request.headers.get("Accept", "")
disable_turbo = request.POST.get("disable_turbo", "false") == "true"
return is_turbo_request and not disable_turbo
def is_frame(request: HttpRequest, frame: str) -> bool:
return request.headers.get("Turbo-Frame") == frame
def stream(request: HttpRequest, template_name: str, context: dict) -> HttpResponse:
response = django_render(request, template_name, context)
response["Content-Type"] = "text/vnd.turbo-stream.html"
return response