kopia lustrzana https://github.com/dukethis/activitypub-example
Remove trailing whitespaces
rodzic
5717e8a98d
commit
b7c706ffb0
|
@ -15,11 +15,11 @@ class Object(object):
|
|||
for key in self.attributes:
|
||||
if key == "type":
|
||||
continue
|
||||
|
||||
|
||||
value = kwargs.get(key)
|
||||
if value is None:
|
||||
continue
|
||||
|
||||
|
||||
if isinstance(value, dict) and value.get("type"):
|
||||
value = as_activitystream(value)
|
||||
self.__setattr__(key, value)
|
||||
|
@ -167,14 +167,13 @@ def as_activitystream(obj):
|
|||
if not type:
|
||||
msg = "Invalid ActivityStream object, the type is missing"
|
||||
raise errors.ASDecodeError(msg)
|
||||
|
||||
|
||||
if type in ALLOWED_TYPES:
|
||||
return ALLOWED_TYPES[type](**obj)
|
||||
|
||||
|
||||
raise errors.ASDecodeError("Invalid Type {0}".format(type))
|
||||
|
||||
def encode_activitystream(obj):
|
||||
if isinstance(obj, Object):
|
||||
return obj.to_json()
|
||||
raise errors.ASTypeError("Unknown ActivityStream Type")
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class Activity(Object):
|
|||
value = getattr(self, attr, None)
|
||||
if not value:
|
||||
continue
|
||||
|
||||
|
||||
if isinstance(value, str):
|
||||
value = [value]
|
||||
audience += value
|
||||
|
|
|
@ -20,7 +20,7 @@ class URIs(object):
|
|||
class Person(Model):
|
||||
ap_id = TextField(null=True)
|
||||
remote = BooleanField(default=False)
|
||||
|
||||
|
||||
username = CharField(max_length=100)
|
||||
name = CharField(max_length=100)
|
||||
following = ManyToManyField('self', symmetrical=False, related_name='followers')
|
||||
|
@ -29,7 +29,7 @@ class Person(Model):
|
|||
def uris(self):
|
||||
if self.remote:
|
||||
return URIs(id=self.ap_id)
|
||||
|
||||
|
||||
return URIs(
|
||||
id=uri("person", self.username),
|
||||
following=uri("following", self.username),
|
||||
|
@ -61,7 +61,7 @@ class Note(Model):
|
|||
person = ForeignKey(Person, related_name='notes')
|
||||
content = CharField(max_length=500)
|
||||
likes = ManyToManyField(Person, related_name='liked')
|
||||
|
||||
|
||||
@property
|
||||
def uris(self):
|
||||
if self.remote:
|
||||
|
@ -69,7 +69,7 @@ class Note(Model):
|
|||
else:
|
||||
ap_id = uri("note", self.person.username, self.id)
|
||||
return URIs(id=ap_id)
|
||||
|
||||
|
||||
def to_activitystream(self):
|
||||
return {
|
||||
"id": self.uris.id,
|
||||
|
@ -83,4 +83,3 @@ def save_ap_id(sender, instance, created, **kwargs):
|
|||
if created and not instance.remote:
|
||||
instance.ap_id = instance.uris.id
|
||||
instance.save()
|
||||
|
||||
|
|
|
@ -35,9 +35,9 @@ def outbox(request, username):
|
|||
actor=person.uris.id,
|
||||
object=obj
|
||||
)
|
||||
|
||||
|
||||
activity.validate()
|
||||
|
||||
|
||||
if activity.type == "Create":
|
||||
if activity.object.type != "Note":
|
||||
raise Exception("Sorry, you can only create Notes objects")
|
||||
|
@ -156,4 +156,3 @@ def followers(request, username):
|
|||
actor = activities.Person(id="http://bob.local/@bob",name="Bob")
|
||||
followers.items.append(actor)
|
||||
return JsonResponse(followers.to_json(context=True))
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue