Skip to content

Commit

Permalink
follow with through model.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasofthings committed Aug 10, 2024
1 parent 707e59b commit d741347
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 49 deletions.
12 changes: 11 additions & 1 deletion webapp/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from django.db import models


class ActorField(models.URLField):
class FedIDField(models.URLField):
"""
A Field that represents a FedID.
.. seealso::
Activity Pub <Object Identifiers https://www.w3.org/TR/activitypub/#obj-id>_`
**id**:
The object's unique global identifier (unless the object is transient, in which case the id MAY be omitted).
"""
def __init__(self, *args, **kwargs):
super(ActorField, self).__init__(*args, **kwargs)
20 changes: 20 additions & 0 deletions webapp/migrations/0042_actor_flw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0.7 on 2024-08-09 08:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("webapp", "0041_alter_actor_id"),
]

operations = [
migrations.AddField(
model_name="actor",
name="flw",
field=models.ManyToManyField(
blank=True, related_name="flwng", to="webapp.actor"
),
),
]
13 changes: 4 additions & 9 deletions webapp/models/activitypub/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,7 @@ class Actor(models.Model):
)

flw = models.ManyToManyField( # this is to prep/test migration of the above.
"self",
related_name="flwng",
symmetrical=False,
blank=True, # , through="Follow"
"self", related_name="flwng", symmetrical=False, blank=True, through="Follow"
)

class Meta:
Expand Down Expand Up @@ -290,7 +287,7 @@ def liked(self):
"""
return reverse(
"actor-likes",
"actor-liked",
args=[self.profile.slug],
)

Expand All @@ -304,13 +301,11 @@ class Follow(models.Model):
"""


"""
class Fllwng(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

validators=[validate_iri],
actor = models.ForeignKey(Actor, on_delete=models.CASCADE)
object = models.ForeignKey(Actor, on_delete=models.CASCADE)
id = models.CharField(max_length=255, primary_key=True, unique=True, blank=False, validators=[validate_iri])
accepted = models.URLField(blank=True, null=True, validators=[validate_iri])
"""


29 changes: 6 additions & 23 deletions webapp/urls/activitypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
OutboxView,
FollowersView,
FollowingView,
LikedView
)

from webapp.views.activitypub.activity import (
NoteView,
ActionView,
SignatureView,
)

from webapp.views import (
LikeCreateView,
LikeDetailView,
LikeDeleteView,
LikeListView,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,26 +67,12 @@
),
path(
r"accounts/<slug:slug>/liked",
LikeListView.as_view(),
name="actor-likes",
LikedView.as_view(),
name="actor-liked",
),
]

urlpatterns += [
path(r"like/", LikeCreateView.as_view(), name="like-create"),
path(r"like/list", LikeCreateView.as_view(), name="like-list"),
path(r"like/<uuid:pk>", LikeDetailView.as_view(), name="like-detail"),
path(
r"like/<uuid:pk>/delete", LikeDeleteView.as_view(), name="like-delete"
), # noqa: E501
]

urlpatterns += [
path(r"note/<uuid:pk>", NoteView.as_view(), name="note-detail"),
path(r"action/<uuid:pk>", ActionView.as_view(), name="action_detail"),
]

urlpatterns += [
# Debug view to show the signature of a given object
path(r"signature", SignatureView.as_view(), name="signature"),
]
20 changes: 18 additions & 2 deletions webapp/urls/web.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
from django.urls import path
from webapp.views.web import FollowingListView
from webapp.views.web import (
LikeListView,
LikeCreateView,
LikeDetailView,
LikeDeleteView,
)
from webapp.views.signature import SignatureView

urlpatterns = [
path(r'', FollowingListView.as_view(), name='following_list'),
path(r"like/", LikeCreateView.as_view(), name="like-create"),
path(r"like/list", LikeListView.as_view(), name="like-list"),
path(r"like/<uuid:pk>", LikeDetailView.as_view(), name="like-detail"),
path(
r"like/<uuid:pk>/delete", LikeDeleteView.as_view(), name="like-delete"
), # noqa: E501
]

urlpatterns += [
# Debug view to show the signature of a given object
path(r"signature", SignatureView.as_view(), name="signature"),
]
8 changes: 1 addition & 7 deletions webapp/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__name__ = "webapp.views"
__author__ = "Andreas Neumeier"

from .web import (
from .profile import (
HomeView,
StatusView,
AccountView,
Expand All @@ -21,12 +21,6 @@
from .activitypub.followers import FollowersView
from .activitypub.following import FollowingView

from webapp.views.likes import (
LikeCreateView,
LikeDeleteView,
LikeListView,
LikeDetailView,
)

from .activitypub import (
NodeInfoView,
Expand Down
19 changes: 18 additions & 1 deletion webapp/views/activitypub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
from .nodeinfo import NodeInfoView, VersionView
from .webfinger import WebFingerView
from .actor import ActorView
from .inbox import InboxView
from .outbox import OutboxView
from .followers import FollowersView
from .following import FollowingView
from .liked import LikedView

__all__ = ["NodeInfoView", "VersionView"]
__all__ = [
"NodeInfoView",
"VersionView",
"WebFingerView",
"ActorView",
"InboxView",
"OutboxView",
"FollowersView",
"FollowingView",
"LikedView"
]
32 changes: 32 additions & 0 deletions webapp/views/activitypub/liked.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.views.generic.detail import DetailView
from django.http import JsonResponse
from webapp.models import Profile


class LikedView(DetailView):
"""
View for handling the liked a
```
GET /liked/
```
Every actor MAY have a liked collection. This is a list of every object from all of the actor's Like activities, added as a side effect. The liked collection MUST be either an OrderedCollection or a Collection and MAY be filtered on privileges of an authenticated user or as appropriate when no authentication is given.
.. seealso::
`ActivityPub Liked <https://www.w3.org/TR/activitypub/#liked>`_
.. seealso:: :class:`django.views.generic.View`
.. seealso::
:class:`django.http.HttpResponse`
"""

models = Profile

def liked(self):
return self.get_object().actor.liked.all()

def get(self, request, *args, **kwargs):
result = {"type": "Collection", "totalItems": 0, "items": []}
return JsonResponse(result, contenttype="application/activity+json")
File renamed without changes.
12 changes: 6 additions & 6 deletions webapp/views/web/following.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
from django import forms
from django.views.generic import DetailView, ListView
from django.views.generic.edit import CreateView, DeleteView
from webapp.models import Profile as Fllwng
# from webapp.models import Profile as Fllwng
from webapp.models import Actor

class FollowForm(forms.ModelForm):
class Meta:
model = Actor
fields = ["self", "following"]
fields = "__all__"
widgets = {
"object": forms.URLInput(attrs={"class": "form-control"}),
}

class FollowingCreateView(CreateView):
model = Fllwng
model = Actor
form_class = FollowForm

class FollowingDetailView(DetailView):
model = Fllwng
model = Actor

class FollowingListView(ListView):
model = Fllwng
model = Actor

class FollowingDeleteView(DeleteView):
model = Fllwng
model = Actor
success_url = "/following/"

0 comments on commit d741347

Please sign in to comment.