diff options
author | Andrew Godwin | 2022-11-24 22:31:45 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-24 22:31:57 -0700 |
commit | 79002e1eaf96e9cfcd2993715b67cf3a61e02fb3 (patch) | |
tree | 10d3f3c7cd7709cdab5259c5e74066df6e175e74 /activities | |
parent | df5493dd2a9a884660ee2a491377237071493c76 (diff) | |
download | takahe-79002e1eaf96e9cfcd2993715b67cf3a61e02fb3.tar.gz takahe-79002e1eaf96e9cfcd2993715b67cf3a61e02fb3.tar.bz2 takahe-79002e1eaf96e9cfcd2993715b67cf3a61e02fb3.zip |
Add initial delete UI
Diffstat (limited to 'activities')
-rw-r--r-- | activities/models/post.py | 1 | ||||
-rw-r--r-- | activities/views/posts.py | 56 |
2 files changed, 51 insertions, 6 deletions
diff --git a/activities/models/post.py b/activities/models/post.py index c8165d6..642842c 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -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): diff --git a/activities/views/posts.py b/activities/views/posts.py index a53d401..268a3fe 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -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): @@ -112,6 +135,27 @@ class Boost(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): template_name = "activities/compose.html" |