mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-13 13:39:27 +02:00
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
This commit is contained in:
@@ -11,7 +11,7 @@ from django.http import (
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
|
||||
from bookmarks import queries
|
||||
from bookmarks import queries, utils
|
||||
from bookmarks.models import (
|
||||
Bookmark,
|
||||
BookmarkAsset,
|
||||
@@ -19,6 +19,7 @@ from bookmarks.models import (
|
||||
BookmarkSearch,
|
||||
build_tag_string,
|
||||
)
|
||||
from bookmarks.services import bookmarks as bookmark_actions, tasks
|
||||
from bookmarks.services.bookmarks import (
|
||||
create_bookmark,
|
||||
update_bookmark,
|
||||
@@ -34,9 +35,8 @@ from bookmarks.services.bookmarks import (
|
||||
share_bookmarks,
|
||||
unshare_bookmarks,
|
||||
)
|
||||
from bookmarks.services import bookmarks as bookmark_actions, tasks
|
||||
from bookmarks.utils import get_safe_return_url
|
||||
from bookmarks.views.partials import contexts
|
||||
from bookmarks.views import contexts, partials, turbo
|
||||
|
||||
_default_page_size = 30
|
||||
|
||||
@@ -48,12 +48,17 @@ def index(request):
|
||||
|
||||
bookmark_list = contexts.ActiveBookmarkListContext(request)
|
||||
tag_cloud = contexts.ActiveTagCloudContext(request)
|
||||
return render(
|
||||
bookmark_details = contexts.get_details_context(
|
||||
request, contexts.ActiveBookmarkDetailsContext
|
||||
)
|
||||
|
||||
return render_bookmarks_view(
|
||||
request,
|
||||
"bookmarks/index.html",
|
||||
{
|
||||
"bookmark_list": bookmark_list,
|
||||
"tag_cloud": tag_cloud,
|
||||
"details": bookmark_details,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -65,12 +70,17 @@ def archived(request):
|
||||
|
||||
bookmark_list = contexts.ArchivedBookmarkListContext(request)
|
||||
tag_cloud = contexts.ArchivedTagCloudContext(request)
|
||||
return render(
|
||||
bookmark_details = contexts.get_details_context(
|
||||
request, contexts.ArchivedBookmarkDetailsContext
|
||||
)
|
||||
|
||||
return render_bookmarks_view(
|
||||
request,
|
||||
"bookmarks/archive.html",
|
||||
{
|
||||
"bookmark_list": bookmark_list,
|
||||
"tag_cloud": tag_cloud,
|
||||
"details": bookmark_details,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -81,14 +91,37 @@ def shared(request):
|
||||
|
||||
bookmark_list = contexts.SharedBookmarkListContext(request)
|
||||
tag_cloud = contexts.SharedTagCloudContext(request)
|
||||
bookmark_details = contexts.get_details_context(
|
||||
request, contexts.SharedBookmarkDetailsContext
|
||||
)
|
||||
public_only = not request.user.is_authenticated
|
||||
users = queries.query_shared_bookmark_users(
|
||||
request.user_profile, bookmark_list.search, public_only
|
||||
)
|
||||
return render(
|
||||
return render_bookmarks_view(
|
||||
request,
|
||||
"bookmarks/shared.html",
|
||||
{"bookmark_list": bookmark_list, "tag_cloud": tag_cloud, "users": users},
|
||||
{
|
||||
"bookmark_list": bookmark_list,
|
||||
"tag_cloud": tag_cloud,
|
||||
"details": bookmark_details,
|
||||
"users": users,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def render_bookmarks_view(request, template_name, context):
|
||||
if turbo.is_frame(request, "details-modal"):
|
||||
return render(
|
||||
request,
|
||||
"bookmarks/updates/details-modal-frame.html",
|
||||
context,
|
||||
)
|
||||
|
||||
return render(
|
||||
request,
|
||||
template_name,
|
||||
context,
|
||||
)
|
||||
|
||||
|
||||
@@ -111,76 +144,6 @@ def search_action(request):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
def _details(request, bookmark_id: int, template: str):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id)
|
||||
except Bookmark.DoesNotExist:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
is_owner = bookmark.owner == request.user
|
||||
is_shared = (
|
||||
request.user.is_authenticated
|
||||
and bookmark.shared
|
||||
and bookmark.owner.profile.enable_sharing
|
||||
)
|
||||
is_public_shared = bookmark.shared and bookmark.owner.profile.enable_public_sharing
|
||||
if not is_owner and not is_shared and not is_public_shared:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
if request.method == "POST":
|
||||
if not is_owner:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
return_url = get_safe_return_url(
|
||||
request.GET.get("return_url"),
|
||||
reverse("bookmarks:details", args=[bookmark.id]),
|
||||
)
|
||||
|
||||
if "remove_asset" in request.POST:
|
||||
asset_id = request.POST["remove_asset"]
|
||||
try:
|
||||
asset = bookmark.bookmarkasset_set.get(pk=asset_id)
|
||||
except BookmarkAsset.DoesNotExist:
|
||||
raise Http404("Asset does not exist")
|
||||
asset.delete()
|
||||
if "create_snapshot" in request.POST:
|
||||
tasks.create_html_snapshot(bookmark)
|
||||
if "upload_asset" in request.POST:
|
||||
file = request.FILES.get("upload_asset_file")
|
||||
if not file:
|
||||
return HttpResponseBadRequest("No file uploaded")
|
||||
bookmark_actions.upload_asset(bookmark, file)
|
||||
else:
|
||||
bookmark.is_archived = request.POST.get("is_archived") == "on"
|
||||
bookmark.unread = request.POST.get("unread") == "on"
|
||||
bookmark.shared = request.POST.get("shared") == "on"
|
||||
bookmark.save()
|
||||
|
||||
return HttpResponseRedirect(return_url)
|
||||
|
||||
details_context = contexts.BookmarkDetailsContext(request, bookmark)
|
||||
|
||||
return render(
|
||||
request,
|
||||
template,
|
||||
{
|
||||
"details": details_context,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def details(request, bookmark_id: int):
|
||||
return _details(request, bookmark_id, "bookmarks/details.html")
|
||||
|
||||
|
||||
def details_modal(request, bookmark_id: int):
|
||||
return _details(request, bookmark_id, "bookmarks/details_modal.html")
|
||||
|
||||
|
||||
def details_assets(request, bookmark_id: int):
|
||||
return _details(request, bookmark_id, "bookmarks/details/assets.html")
|
||||
|
||||
|
||||
def convert_tag_string(tag_string: str):
|
||||
# Tag strings coming from inputs are space-separated, however services.bookmarks functions expect comma-separated
|
||||
# strings
|
||||
@@ -307,26 +270,87 @@ def mark_as_read(request, bookmark_id: int):
|
||||
bookmark.save()
|
||||
|
||||
|
||||
def create_html_snapshot(request, bookmark_id: int):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id, owner=request.user)
|
||||
except Bookmark.DoesNotExist:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
tasks.create_html_snapshot(bookmark)
|
||||
|
||||
|
||||
def upload_asset(request, bookmark_id: int):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id, owner=request.user)
|
||||
except Bookmark.DoesNotExist:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
file = request.FILES.get("upload_asset_file")
|
||||
if not file:
|
||||
raise ValueError("No file uploaded")
|
||||
|
||||
bookmark_actions.upload_asset(bookmark, file)
|
||||
|
||||
|
||||
def remove_asset(request, asset_id: int):
|
||||
try:
|
||||
asset = BookmarkAsset.objects.get(pk=asset_id, bookmark__owner=request.user)
|
||||
except BookmarkAsset.DoesNotExist:
|
||||
raise Http404("Asset does not exist")
|
||||
|
||||
asset.delete()
|
||||
|
||||
|
||||
def update_state(request, bookmark_id: int):
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id, owner=request.user)
|
||||
except Bookmark.DoesNotExist:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
bookmark.is_archived = request.POST.get("is_archived") == "on"
|
||||
bookmark.unread = request.POST.get("unread") == "on"
|
||||
bookmark.shared = request.POST.get("shared") == "on"
|
||||
bookmark.save()
|
||||
|
||||
|
||||
@login_required
|
||||
def index_action(request):
|
||||
search = BookmarkSearch.from_request(request.GET)
|
||||
query = queries.query_bookmarks(request.user, request.user_profile, search)
|
||||
return action(request, query)
|
||||
handle_action(request, query)
|
||||
|
||||
if turbo.accept(request):
|
||||
return partials.active_bookmark_update(request)
|
||||
|
||||
return utils.redirect_with_query(request, reverse("bookmarks:index"))
|
||||
|
||||
|
||||
@login_required
|
||||
def archived_action(request):
|
||||
search = BookmarkSearch.from_request(request.GET)
|
||||
query = queries.query_archived_bookmarks(request.user, request.user_profile, search)
|
||||
return action(request, query)
|
||||
handle_action(request, query)
|
||||
|
||||
if turbo.accept(request):
|
||||
return partials.archived_bookmark_update(request)
|
||||
|
||||
return utils.redirect_with_query(request, reverse("bookmarks:archived"))
|
||||
|
||||
|
||||
@login_required
|
||||
def shared_action(request):
|
||||
return action(request)
|
||||
if "bulk_execute" in request.POST:
|
||||
return HttpResponseBadRequest("View does not support bulk actions")
|
||||
|
||||
handle_action(request)
|
||||
|
||||
if turbo.accept(request):
|
||||
return partials.shared_bookmark_update(request)
|
||||
|
||||
return utils.redirect_with_query(request, reverse("bookmarks:shared"))
|
||||
|
||||
|
||||
def action(request, query: QuerySet[Bookmark] = None):
|
||||
def handle_action(request, query: QuerySet[Bookmark] = None):
|
||||
# Single bookmark actions
|
||||
if "archive" in request.POST:
|
||||
archive(request, request.POST["archive"])
|
||||
@@ -338,11 +362,21 @@ def action(request, query: QuerySet[Bookmark] = None):
|
||||
mark_as_read(request, request.POST["mark_as_read"])
|
||||
if "unshare" in request.POST:
|
||||
unshare(request, request.POST["unshare"])
|
||||
if "create_html_snapshot" in request.POST:
|
||||
create_html_snapshot(request, request.POST["create_html_snapshot"])
|
||||
if "upload_asset" in request.POST:
|
||||
upload_asset(request, request.POST["upload_asset"])
|
||||
if "remove_asset" in request.POST:
|
||||
remove_asset(request, request.POST["remove_asset"])
|
||||
|
||||
# State updates
|
||||
if "update_state" in request.POST:
|
||||
update_state(request, request.POST["update_state"])
|
||||
|
||||
# Bulk actions
|
||||
if "bulk_execute" in request.POST:
|
||||
if query is None:
|
||||
return HttpResponseBadRequest("View does not support bulk actions")
|
||||
raise ValueError("Query must be provided for bulk actions")
|
||||
|
||||
bulk_action = request.POST["bulk_action"]
|
||||
|
||||
@@ -375,11 +409,6 @@ def action(request, query: QuerySet[Bookmark] = None):
|
||||
if "bulk_unshare" == bulk_action:
|
||||
unshare_bookmarks(bookmark_ids, request.user)
|
||||
|
||||
return_url = get_safe_return_url(
|
||||
request.GET.get("return_url"), reverse("bookmarks:index")
|
||||
)
|
||||
return HttpResponseRedirect(return_url)
|
||||
|
||||
|
||||
@login_required
|
||||
def close(request):
|
||||
|
@@ -6,6 +6,7 @@ from django.conf import settings
|
||||
from django.core.handlers.wsgi import WSGIRequest
|
||||
from django.core.paginator import Paginator
|
||||
from django.db import models
|
||||
from django.http import Http404
|
||||
from django.urls import reverse
|
||||
|
||||
from bookmarks import queries
|
||||
@@ -27,17 +28,11 @@ CJK_RE = re.compile(r"[\u4e00-\u9fff]+")
|
||||
class RequestContext:
|
||||
index_view = "bookmarks:index"
|
||||
action_view = "bookmarks:index.action"
|
||||
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.active"
|
||||
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.active"
|
||||
tag_modal_partial_view = "bookmarks:partials.tag_modal.active"
|
||||
|
||||
def __init__(self, request: WSGIRequest):
|
||||
self.request = request
|
||||
self.index_url = reverse(self.index_view)
|
||||
self.action_url = reverse(self.action_view)
|
||||
self.bookmark_list_partial_url = reverse(self.bookmark_list_partial_view)
|
||||
self.tag_cloud_partial_url = reverse(self.tag_cloud_partial_view)
|
||||
self.tag_modal_partial_url = reverse(self.tag_modal_partial_view)
|
||||
self.query_params = request.GET.copy()
|
||||
self.query_params.pop("details", None)
|
||||
|
||||
@@ -51,34 +46,25 @@ class RequestContext:
|
||||
encoded_params = query_params.urlencode()
|
||||
return view_url + "?" + encoded_params if encoded_params else view_url
|
||||
|
||||
def index(self) -> str:
|
||||
return self.get_url(self.index_url)
|
||||
def index(self, add: dict = None, remove: dict = None) -> str:
|
||||
return self.get_url(self.index_url, add=add, remove=remove)
|
||||
|
||||
def action(self, return_url: str) -> str:
|
||||
return self.get_url(self.action_url, add={"return_url": return_url})
|
||||
def action(self, add: dict = None, remove: dict = None) -> str:
|
||||
return self.get_url(self.action_url, add=add, remove=remove)
|
||||
|
||||
def bookmark_list_partial(self) -> str:
|
||||
return self.get_url(self.bookmark_list_partial_url)
|
||||
|
||||
def tag_cloud_partial(self) -> str:
|
||||
return self.get_url(self.tag_cloud_partial_url)
|
||||
|
||||
def tag_modal_partial(self) -> str:
|
||||
return self.get_url(self.tag_modal_partial_url)
|
||||
def details(self, bookmark_id: int) -> str:
|
||||
return self.get_url(self.index_url, add={"details": bookmark_id})
|
||||
|
||||
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||
raise Exception("Must be implemented by subclass")
|
||||
raise NotImplementedError("Must be implemented by subclass")
|
||||
|
||||
def get_tag_query_set(self, search: BookmarkSearch):
|
||||
raise Exception("Must be implemented by subclass")
|
||||
raise NotImplementedError("Must be implemented by subclass")
|
||||
|
||||
|
||||
class ActiveBookmarksContext(RequestContext):
|
||||
index_view = "bookmarks:index"
|
||||
action_view = "bookmarks:index.action"
|
||||
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.active"
|
||||
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.active"
|
||||
tag_modal_partial_view = "bookmarks:partials.tag_modal.active"
|
||||
|
||||
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||
return queries.query_bookmarks(
|
||||
@@ -94,9 +80,6 @@ class ActiveBookmarksContext(RequestContext):
|
||||
class ArchivedBookmarksContext(RequestContext):
|
||||
index_view = "bookmarks:archived"
|
||||
action_view = "bookmarks:archived.action"
|
||||
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.archived"
|
||||
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.archived"
|
||||
tag_modal_partial_view = "bookmarks:partials.tag_modal.archived"
|
||||
|
||||
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||
return queries.query_archived_bookmarks(
|
||||
@@ -112,9 +95,6 @@ class ArchivedBookmarksContext(RequestContext):
|
||||
class SharedBookmarksContext(RequestContext):
|
||||
index_view = "bookmarks:shared"
|
||||
action_view = "bookmarks:shared.action"
|
||||
bookmark_list_partial_view = "bookmarks:partials.bookmark_list.shared"
|
||||
tag_cloud_partial_view = "bookmarks:partials.tag_cloud.shared"
|
||||
tag_modal_partial_view = "bookmarks:partials.tag_modal.shared"
|
||||
|
||||
def get_bookmark_query_set(self, search: BookmarkSearch):
|
||||
user = User.objects.filter(username=search.user).first()
|
||||
@@ -132,7 +112,13 @@ class SharedBookmarksContext(RequestContext):
|
||||
|
||||
|
||||
class BookmarkItem:
|
||||
def __init__(self, bookmark: Bookmark, user: User, profile: UserProfile) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
context: RequestContext,
|
||||
bookmark: Bookmark,
|
||||
user: User,
|
||||
profile: UserProfile,
|
||||
) -> None:
|
||||
self.bookmark = bookmark
|
||||
|
||||
is_editable = bookmark.owner == user
|
||||
@@ -154,6 +140,7 @@ class BookmarkItem:
|
||||
self.is_archived = bookmark.is_archived
|
||||
self.unread = bookmark.unread
|
||||
self.owner = bookmark.owner
|
||||
self.details_url = context.details(bookmark.id)
|
||||
|
||||
css_classes = []
|
||||
if bookmark.unread:
|
||||
@@ -200,16 +187,15 @@ class BookmarkListContext:
|
||||
models.prefetch_related_objects(bookmarks_page.object_list, "owner", "tags")
|
||||
|
||||
self.items = [
|
||||
BookmarkItem(bookmark, user, user_profile) for bookmark in bookmarks_page
|
||||
BookmarkItem(request_context, bookmark, user, user_profile)
|
||||
for bookmark in bookmarks_page
|
||||
]
|
||||
self.is_empty = paginator.count == 0
|
||||
self.bookmarks_page = bookmarks_page
|
||||
self.bookmarks_total = paginator.count
|
||||
|
||||
self.return_url = request_context.index()
|
||||
self.action_url = request_context.action(return_url=self.return_url)
|
||||
self.refresh_url = request_context.bookmark_list_partial()
|
||||
self.tag_modal_url = request_context.tag_modal_partial()
|
||||
self.action_url = request_context.action()
|
||||
|
||||
self.link_target = user_profile.bookmark_link_target
|
||||
self.date_display = user_profile.bookmark_date_display
|
||||
@@ -344,8 +330,6 @@ class TagCloudContext:
|
||||
self.selected_tags = unique_selected_tags
|
||||
self.has_selected_tags = has_selected_tags
|
||||
|
||||
self.refresh_url = request_context.tag_cloud_partial()
|
||||
|
||||
def get_selected_tags(self, tags: List[Tag]):
|
||||
parsed_query = queries.parse_query_string(self.search.q)
|
||||
tag_names = parsed_query["tag_names"]
|
||||
@@ -396,17 +380,18 @@ class BookmarkAssetItem:
|
||||
|
||||
|
||||
class BookmarkDetailsContext:
|
||||
request_context = RequestContext
|
||||
|
||||
def __init__(self, request: WSGIRequest, bookmark: Bookmark):
|
||||
request_context = self.request_context(request)
|
||||
|
||||
user = request.user
|
||||
user_profile = request.user_profile
|
||||
|
||||
self.edit_return_url = utils.get_safe_return_url(
|
||||
request.GET.get("return_url"),
|
||||
reverse("bookmarks:details", args=[bookmark.id]),
|
||||
)
|
||||
self.delete_return_url = utils.get_safe_return_url(
|
||||
request.GET.get("return_url"), reverse("bookmarks:index")
|
||||
)
|
||||
self.edit_return_url = request_context.details(bookmark.id)
|
||||
self.action_url = request_context.action(add={"details": bookmark.id})
|
||||
self.delete_url = request_context.action()
|
||||
self.close_url = request_context.index()
|
||||
|
||||
self.bookmark = bookmark
|
||||
self.profile = request.user_profile
|
||||
@@ -438,3 +423,44 @@ class BookmarkDetailsContext:
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
class ActiveBookmarkDetailsContext(BookmarkDetailsContext):
|
||||
request_context = ActiveBookmarksContext
|
||||
|
||||
|
||||
class ArchivedBookmarkDetailsContext(BookmarkDetailsContext):
|
||||
request_context = ArchivedBookmarksContext
|
||||
|
||||
|
||||
class SharedBookmarkDetailsContext(BookmarkDetailsContext):
|
||||
request_context = SharedBookmarksContext
|
||||
|
||||
|
||||
def get_details_context(
|
||||
request: WSGIRequest, context_type
|
||||
) -> BookmarkDetailsContext | None:
|
||||
bookmark_id = request.GET.get("details")
|
||||
if not bookmark_id:
|
||||
return None
|
||||
|
||||
try:
|
||||
bookmark = Bookmark.objects.get(pk=int(bookmark_id))
|
||||
except Bookmark.DoesNotExist:
|
||||
# just ignore, might end up in a situation where the bookmark was deleted
|
||||
# in between navigating back and forth
|
||||
return None
|
||||
|
||||
is_owner = bookmark.owner == request.user
|
||||
is_shared = (
|
||||
request.user.is_authenticated
|
||||
and bookmark.shared
|
||||
and bookmark.owner.profile.enable_sharing
|
||||
)
|
||||
is_public_shared = bookmark.shared and bookmark.owner.profile.enable_public_sharing
|
||||
if not is_owner and not is_shared and not is_public_shared:
|
||||
raise Http404("Bookmark does not exist")
|
||||
if request.method == "POST" and not is_owner:
|
||||
raise Http404("Bookmark does not exist")
|
||||
|
||||
return context_type(request, bookmark)
|
40
bookmarks/views/partials.py
Normal file
40
bookmarks/views/partials.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from bookmarks.views import contexts, turbo
|
||||
|
||||
|
||||
def render_bookmark_update(request, bookmark_list, tag_cloud, details):
|
||||
return turbo.stream(
|
||||
request,
|
||||
"bookmarks/updates/bookmark_view_stream.html",
|
||||
{
|
||||
"bookmark_list": bookmark_list,
|
||||
"tag_cloud": tag_cloud,
|
||||
"details": details,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def active_bookmark_update(request):
|
||||
bookmark_list = contexts.ActiveBookmarkListContext(request)
|
||||
tag_cloud = contexts.ActiveTagCloudContext(request)
|
||||
details = contexts.get_details_context(
|
||||
request, contexts.ActiveBookmarkDetailsContext
|
||||
)
|
||||
return render_bookmark_update(request, bookmark_list, tag_cloud, details)
|
||||
|
||||
|
||||
def archived_bookmark_update(request):
|
||||
bookmark_list = contexts.ArchivedBookmarkListContext(request)
|
||||
tag_cloud = contexts.ArchivedTagCloudContext(request)
|
||||
details = contexts.get_details_context(
|
||||
request, contexts.ArchivedBookmarkDetailsContext
|
||||
)
|
||||
return render_bookmark_update(request, bookmark_list, tag_cloud, details)
|
||||
|
||||
|
||||
def shared_bookmark_update(request):
|
||||
bookmark_list = contexts.SharedBookmarkListContext(request)
|
||||
tag_cloud = contexts.SharedTagCloudContext(request)
|
||||
details = contexts.get_details_context(
|
||||
request, contexts.SharedBookmarkDetailsContext
|
||||
)
|
||||
return render_bookmark_update(request, bookmark_list, tag_cloud, details)
|
@@ -1,76 +0,0 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import render
|
||||
|
||||
from bookmarks.views.partials import contexts
|
||||
|
||||
|
||||
@login_required
|
||||
def active_bookmark_list(request):
|
||||
bookmark_list_context = contexts.ActiveBookmarkListContext(request)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"bookmarks/bookmark_list.html",
|
||||
{"bookmark_list": bookmark_list_context},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def active_tag_cloud(request):
|
||||
tag_cloud_context = contexts.ActiveTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
||||
|
||||
|
||||
@login_required
|
||||
def active_tag_modal(request):
|
||||
tag_cloud_context = contexts.ActiveTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
||||
|
||||
|
||||
@login_required
|
||||
def archived_bookmark_list(request):
|
||||
bookmark_list_context = contexts.ArchivedBookmarkListContext(request)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"bookmarks/bookmark_list.html",
|
||||
{"bookmark_list": bookmark_list_context},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def archived_tag_cloud(request):
|
||||
tag_cloud_context = contexts.ArchivedTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
||||
|
||||
|
||||
@login_required
|
||||
def archived_tag_modal(request):
|
||||
tag_cloud_context = contexts.ArchivedTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
||||
|
||||
|
||||
def shared_bookmark_list(request):
|
||||
bookmark_list_context = contexts.SharedBookmarkListContext(request)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"bookmarks/bookmark_list.html",
|
||||
{"bookmark_list": bookmark_list_context},
|
||||
)
|
||||
|
||||
|
||||
def shared_tag_cloud(request):
|
||||
tag_cloud_context = contexts.SharedTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_cloud.html", {"tag_cloud": tag_cloud_context})
|
||||
|
||||
|
||||
def shared_tag_modal(request):
|
||||
tag_cloud_context = contexts.SharedTagCloudContext(request)
|
||||
|
||||
return render(request, "bookmarks/tag_modal.html", {"tag_cloud": tag_cloud_context})
|
19
bookmarks/views/turbo.py
Normal file
19
bookmarks/views/turbo.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
Reference in New Issue
Block a user