RemotePerson.followers and RemotePerson.following both implemented in terms of the same helper function.

LocalPerson.followers moved to Person.followers, where it should always have been.
RemotePerson.followers overrides this, just as RemotePerson.following overrides Person.following.

Closes issue #64.
merge-requests/2/merge
Marnanel Thurman 2020-11-16 02:19:03 +00:00
rodzic 4f5325fb5c
commit 2e82f842e3
1 zmienionych plików z 22 dodań i 11 usunięć

Wyświetl plik

@ -111,6 +111,12 @@ class Person(PolymorphicModel):
rel_followers__follower = self,
)
@property
def followers(self):
return Person.objects.filter(
rel_following__following = self,
)
@property
def fields(self):
return [] # FIXME
@ -271,10 +277,21 @@ class RemotePerson(Person):
@property
def followers(self):
return self._get_remote_collection(
self.followers_url,
)
@property
def following(self):
return self._get_remote_collection(
self.following_url,
)
def _get_remote_collection(self, url):
from kepi.sombrero_sendpub.fetch import fetch
from kepi.sombrero_sendpub.collections import Collection
class RemotePersonFollowers(object):
class RemotePersonCollection(object):
def __init__(self, address):
logger.debug(
"%s RemotePerson: initialising",
@ -311,13 +328,13 @@ class RemotePerson(Person):
def __next__(self):
logger.debug("%s RemotePerson: finding next follower...",
logger.debug("%s RemotePerson: finding next...",
self.address,
)
url = self.collection.__next__()
logger.debug("%s RemotePerson: next follower is at %s",
logger.debug("%s RemotePerson: next is at %s",
self.address,
url,
)
@ -334,8 +351,8 @@ class RemotePerson(Person):
return person
result = RemotePersonFollowers(
self.followers_url,
result = RemotePersonCollection(
url,
)
return result
@ -607,12 +624,6 @@ class LocalPerson(Person):
return result
@property
def followers(self):
return Person.objects.filter(
rel_following__following = self,
)
def get_followers_collection(self):
return self.followers