mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-25 16:51:00 +00:00
Add initial delete UI
This commit is contained in:
parent
df5493dd2a
commit
79002e1eaf
5 changed files with 67 additions and 7 deletions
|
@ -138,6 +138,7 @@ class Post(StatorModel):
|
|||
action_unlike = "{view}unlike/"
|
||||
action_boost = "{view}boost/"
|
||||
action_unboost = "{view}unboost/"
|
||||
action_delete = "{view}delete/"
|
||||
action_reply = "/compose/?reply_to={self.id}"
|
||||
|
||||
def get_scheme(self, url):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django import forms
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic import FormView, TemplateView, View
|
||||
|
@ -7,8 +8,10 @@ from activities.models import (
|
|||
Post,
|
||||
PostInteraction,
|
||||
PostInteractionStates,
|
||||
PostStates,
|
||||
TimelineEvent,
|
||||
)
|
||||
from core.ld import canonicalise
|
||||
from core.models import Config
|
||||
from users.decorators import identity_required
|
||||
from users.shortcuts import by_handle_or_404
|
||||
|
@ -18,18 +21,38 @@ class Individual(TemplateView):
|
|||
|
||||
template_name = "activities/post.html"
|
||||
|
||||
def get_context_data(self, handle, post_id):
|
||||
identity = by_handle_or_404(self.request, handle, local=False)
|
||||
post = get_object_or_404(identity.posts, pk=post_id)
|
||||
def get(self, request, handle, post_id):
|
||||
self.identity = by_handle_or_404(self.request, handle, local=False)
|
||||
self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
|
||||
# If they're coming in looking for JSON, they want the actor
|
||||
accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
|
||||
if (
|
||||
"application/json" in accept
|
||||
or "application/ld" in accept
|
||||
or "application/activity" in accept
|
||||
):
|
||||
# Return post JSON
|
||||
return self.serve_object()
|
||||
else:
|
||||
# Show normal page
|
||||
return super().get(request)
|
||||
|
||||
def get_context_data(self):
|
||||
return {
|
||||
"identity": identity,
|
||||
"post": post,
|
||||
"identity": self.identity,
|
||||
"post": self.post_obj,
|
||||
"interactions": PostInteraction.get_post_interactions(
|
||||
[post],
|
||||
[self.post_obj],
|
||||
self.request.identity,
|
||||
),
|
||||
}
|
||||
|
||||
def serve_object(self):
|
||||
# If this not a local post, redirect to its canonical URI
|
||||
if not self.post_obj.local:
|
||||
return redirect(self.post_obj.object_uri)
|
||||
return JsonResponse(canonicalise(self.post_obj.to_ap(), include_security=True))
|
||||
|
||||
|
||||
@method_decorator(identity_required, name="dispatch")
|
||||
class Like(View):
|
||||
|
@ -111,6 +134,27 @@ class Boost(View):
|
|||
return redirect(post.urls.view)
|
||||
|
||||
|
||||
@method_decorator(identity_required, name="dispatch")
|
||||
class Delete(TemplateView):
|
||||
"""
|
||||
Deletes a post
|
||||
"""
|
||||
|
||||
template_name = "activities/post_delete.html"
|
||||
|
||||
def dispatch(self, request, handle, post_id):
|
||||
self.identity = by_handle_or_404(self.request, handle, local=False)
|
||||
self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
|
||||
return super().dispatch(request)
|
||||
|
||||
def get_context_data(self):
|
||||
return {"post": self.post_obj}
|
||||
|
||||
def post(self, request):
|
||||
self.post_obj.transition_perform(PostStates.deleted)
|
||||
return redirect("/")
|
||||
|
||||
|
||||
@method_decorator(identity_required, name="dispatch")
|
||||
class Compose(FormView):
|
||||
|
||||
|
|
|
@ -94,6 +94,7 @@ urlpatterns = [
|
|||
path("@<handle>/posts/<int:post_id>/unlike/", posts.Like.as_view(undo=True)),
|
||||
path("@<handle>/posts/<int:post_id>/boost/", posts.Boost.as_view()),
|
||||
path("@<handle>/posts/<int:post_id>/unboost/", posts.Boost.as_view(undo=True)),
|
||||
path("@<handle>/posts/<int:post_id>/delete/", posts.Delete.as_view()),
|
||||
# Authentication
|
||||
path("auth/login/", auth.Login.as_view(), name="login"),
|
||||
path("auth/logout/", auth.Logout.as_view(), name="logout"),
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<i class="fa-solid fa-caret-down"></i>
|
||||
</a>
|
||||
<menu>
|
||||
<a>
|
||||
<a href="{{ post.urls.action_delete }}">
|
||||
<i class="fa-solid fa-trash"></i> Delete
|
||||
</a>
|
||||
</menu>
|
||||
|
|
14
templates/activities/post_delete.html
Normal file
14
templates/activities/post_delete.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Delete Post{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Delete this post?</h1>
|
||||
<form action="." method="POST">
|
||||
{% csrf_token %}
|
||||
<a class="button" onclick="history.back()">Cancel</a>
|
||||
<button class="delete">Delete</button>
|
||||
</form>
|
||||
|
||||
{% include "activities/_post.html" %}
|
||||
{% endblock %}
|
Loading…
Reference in a new issue