kopia lustrzana https://gitlab.com/marnanel/chapeau
Renamed methods to avoid confusion.
activity is now activity_form. find_activity is now activity_find. django_kepi.resolve is now django_kepi.find.thingy_objects
rodzic
434dc1fac1
commit
e6953e329d
|
@ -41,7 +41,7 @@ object_type_registry = {
|
|||
def register_type(f_type, handler):
|
||||
object_type_registry[f_type] = handler
|
||||
|
||||
def resolve(identifier, f_type=None):
|
||||
def find(identifier, f_type=None):
|
||||
|
||||
if f_type is None:
|
||||
f_type = object_type_registry.keys()
|
||||
|
@ -56,7 +56,7 @@ def resolve(identifier, f_type=None):
|
|||
cls = object_type_registry[t]
|
||||
|
||||
try:
|
||||
result = cls.find_activity(url=identifier)
|
||||
result = cls.activity_find(url=identifier)
|
||||
except cls.DoesNotExist:
|
||||
result = None
|
||||
|
||||
|
@ -77,7 +77,7 @@ def create(fields):
|
|||
|
||||
cls = object_type_registry[t]
|
||||
|
||||
result = cls.activitypub_create(fields)
|
||||
result = cls.activity_create(fields)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -86,10 +86,10 @@ class TombstoneException(Exception):
|
|||
def __init__(self, *args, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
self.activity = kwargs.copy()
|
||||
self.activity['type'] = 'Tombstone'
|
||||
self.activity_form = kwargs.copy()
|
||||
self.activity_form['type'] = 'Tombstone'
|
||||
|
||||
def __str__(self):
|
||||
return str(self.activity)
|
||||
return str(self.activity_form)
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.db import models
|
||||
from django_kepi import object_type_registry, resolve, register_type, logger
|
||||
from django_kepi import object_type_registry, find, register_type, logger
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.conf import settings
|
||||
|
@ -301,7 +301,7 @@ class Activity(models.Model):
|
|||
"""
|
||||
if self.f_type=='Accept':
|
||||
|
||||
referent = resolve(
|
||||
referent = find(
|
||||
identifier=self.f_object,
|
||||
f_type='Follow',
|
||||
)
|
||||
|
@ -312,7 +312,7 @@ class Activity(models.Model):
|
|||
|
||||
elif self.f_type=='Reject':
|
||||
|
||||
referent = resolve(
|
||||
referent = find(
|
||||
identifier=self.f_object,
|
||||
f_type='Follow',
|
||||
)
|
||||
|
@ -329,11 +329,11 @@ class Activity(models.Model):
|
|||
register_type(t, cls)
|
||||
|
||||
@classmethod
|
||||
def find_activity(cls, url):
|
||||
def activity_find(cls, url):
|
||||
return cls.objects.get(identifier=url)
|
||||
|
||||
@classmethod
|
||||
def activitypub_create(cls, fields):
|
||||
def activity_create(cls, fields):
|
||||
return cls.create(value, local=False)
|
||||
|
||||
@classmethod
|
||||
|
@ -410,7 +410,7 @@ class Activity(models.Model):
|
|||
|
||||
obj_id, obj_type = _object_to_id_and_type(value[fieldname])
|
||||
|
||||
referent = resolve(
|
||||
referent = find(
|
||||
identifier=obj_id,
|
||||
f_type=obj_type,
|
||||
)
|
||||
|
@ -418,7 +418,7 @@ class Activity(models.Model):
|
|||
if referent is None:
|
||||
|
||||
# oh, weird. Maybe they got the type wrong.
|
||||
referent = resolve(
|
||||
referent = find(
|
||||
identifier=obj_id,
|
||||
f_type=None,
|
||||
)
|
||||
|
|
|
@ -17,10 +17,10 @@ class ActivityObjectResponse(django.http.HttpResponse):
|
|||
|
||||
if item is not None:
|
||||
try:
|
||||
result = item.activity
|
||||
result = item.activity_form
|
||||
|
||||
except django_kepi.TombstoneException as tombstone:
|
||||
result = tombstone.activity
|
||||
result = tombstone.activity_form
|
||||
self.status_code = 410 # Gone
|
||||
|
||||
self._render(result)
|
||||
|
@ -93,10 +93,10 @@ class CollectionResponse(ActivityObjectResponse):
|
|||
try:
|
||||
return self._transform_object(obj)
|
||||
except django_kepi.TombstoneException as te:
|
||||
return te.activity
|
||||
return te.activity_form
|
||||
|
||||
def _transform_object(self, obj):
|
||||
return obj.activity
|
||||
return obj.activity_form
|
||||
|
||||
def _make_query_page(
|
||||
self,
|
||||
|
|
|
@ -24,9 +24,9 @@ copyright = '2018, Marnanel Thurman'
|
|||
author = 'Marnanel Thurman'
|
||||
|
||||
# The short X.Y version
|
||||
version = ''
|
||||
version = '0.0'
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '0.1'
|
||||
release = '0.0.18'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
@ -162,4 +162,4 @@ texinfo_documents = [
|
|||
# -- Options for todo extension ----------------------------------------------
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = True
|
||||
todo_include_todos = True
|
||||
|
|
|
@ -9,7 +9,8 @@ Welcome to django_kepi's documentation!
|
|||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
modules.rst
|
||||
django_kepi.rst
|
||||
|
||||
|
||||
Indices and tables
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.test import TestCase, Client
|
||||
from django_kepi.models import Activity, QuarantinedMessage, QuarantinedMessageNeeds
|
||||
from django_kepi import create, resolve, logger
|
||||
from django_kepi import create, logger
|
||||
from things_for_testing import KepiTestCase
|
||||
import logging
|
||||
import httpretty
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
from django.test import TestCase
|
||||
from django_kepi import resolve, register_type
|
||||
from django_kepi import find, register_type
|
||||
|
||||
class ResolveTests(TestCase):
|
||||
|
||||
def test_resolve(self):
|
||||
def test_find(self):
|
||||
|
||||
class Fruit(object):
|
||||
|
||||
@classmethod
|
||||
def find_activity(self, url):
|
||||
def activity_find(self, url):
|
||||
if url=='https://yellow.example.com':
|
||||
return {'name': 'Banana'}
|
||||
elif url=='https://orange.example.com':
|
||||
|
@ -19,7 +19,7 @@ class ResolveTests(TestCase):
|
|||
class Tellytubby(object):
|
||||
|
||||
@classmethod
|
||||
def find_activity(self, url):
|
||||
def activity_find(self, url):
|
||||
if url=='https://yellow.example.com':
|
||||
return {'name': 'Laa-Laa'}
|
||||
elif url=='https://purple.example.com':
|
||||
|
@ -29,42 +29,42 @@ class ResolveTests(TestCase):
|
|||
|
||||
register_type('Fruit', Fruit)
|
||||
|
||||
self.assertEqual(resolve('https://yellow.example.com'),
|
||||
self.assertEqual(find('https://yellow.example.com'),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'Fruit'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'Fruit'),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://purple.example.com', 'Fruit'),
|
||||
self.assertEqual(find('https://purple.example.com', 'Fruit'),
|
||||
None)
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'Tellytubby'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'Tellytubby'),
|
||||
None)
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'TubeLine'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'TubeLine'),
|
||||
None)
|
||||
|
||||
register_type('Tellytubby', Tellytubby)
|
||||
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'Fruit'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'Fruit'),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://purple.example.com', 'Fruit'),
|
||||
self.assertEqual(find('https://purple.example.com', 'Fruit'),
|
||||
None)
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'Tellytubby'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'Tellytubby'),
|
||||
{'name': 'Laa-Laa'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', 'TubeLine'),
|
||||
self.assertEqual(find('https://yellow.example.com', 'TubeLine'),
|
||||
None)
|
||||
self.assertEqual(resolve('https://yellow.example.com', ['Tellytubby']),
|
||||
self.assertEqual(find('https://yellow.example.com', ['Tellytubby']),
|
||||
{'name': 'Laa-Laa'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', ['Fruit']),
|
||||
self.assertEqual(find('https://yellow.example.com', ['Fruit']),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', ['Tellytubby', 'Fruit']),
|
||||
self.assertEqual(find('https://yellow.example.com', ['Tellytubby', 'Fruit']),
|
||||
{'name': 'Laa-Laa'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', ['Fruit', 'Tellytubby']),
|
||||
self.assertEqual(find('https://yellow.example.com', ['Fruit', 'Tellytubby']),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://yellow.example.com', ['Fruit', 'TubeLine', 'Tellytubby']),
|
||||
self.assertEqual(find('https://yellow.example.com', ['Fruit', 'TubeLine', 'Tellytubby']),
|
||||
{'name': 'Banana'})
|
||||
self.assertEqual(resolve('https://purple.example.com', ['Tellytubby', 'Fruit']),
|
||||
self.assertEqual(find('https://purple.example.com', ['Tellytubby', 'Fruit']),
|
||||
{'name': 'Tinky Winky'})
|
||||
self.assertEqual(resolve('https://purple.example.com', ['Fruit', 'Tellytubby']),
|
||||
self.assertEqual(find('https://purple.example.com', ['Fruit', 'Tellytubby']),
|
||||
{'name': 'Tinky Winky'})
|
||||
self.assertEqual(resolve('https://blue.example.com', ['Tellytubby', 'Fruit']),
|
||||
self.assertEqual(find('https://blue.example.com', ['Tellytubby', 'Fruit']),
|
||||
None)
|
||||
self.assertEqual(resolve('https://blue.example.com', ['Fruit', 'Tellytubby']),
|
||||
self.assertEqual(find('https://blue.example.com', ['Fruit', 'Tellytubby']),
|
||||
None)
|
||||
|
|
|
@ -30,7 +30,7 @@ class ResponseTests(TestCase):
|
|||
)
|
||||
|
||||
self.assertEqual(
|
||||
te.activity,
|
||||
te.activity_form,
|
||||
{
|
||||
'fred': 'jim',
|
||||
'sheila': 'hazel',
|
||||
|
@ -48,7 +48,7 @@ class ResponseTests(TestCase):
|
|||
|
||||
class RandomWeirdThing(object):
|
||||
@property
|
||||
def activity(self):
|
||||
def activity_form(self):
|
||||
return {
|
||||
'where': 'there',
|
||||
'what': 'that',
|
||||
|
@ -62,14 +62,14 @@ class ResponseTests(TestCase):
|
|||
content_value = json.loads(aor.content.decode(encoding='UTF-8'))
|
||||
|
||||
self.assertEqual(
|
||||
rwt.activity,
|
||||
rwt.activity_form,
|
||||
content_value)
|
||||
|
||||
def test_tombstone_object_response(self):
|
||||
|
||||
class RandomWeirdGoneAwayThing(object):
|
||||
@property
|
||||
def activity(self):
|
||||
def activity_form(self):
|
||||
raise TombstoneException(former_type='Article')
|
||||
|
||||
rwgat = RandomWeirdGoneAwayThing()
|
||||
|
@ -137,7 +137,7 @@ class ResponseTests(TestCase):
|
|||
self.assertEqual(content_value['partOf'], EXAMPLE_SERVER+PATH_INDEX)
|
||||
self.assertEqual(content_value['id'], EXAMPLE_SERVER+PATH_PAGE1)
|
||||
|
||||
expectedItems = [x.activity for x in queryset]
|
||||
expectedItems = [x.activity_form for x in queryset]
|
||||
self.assertEqual(content_value['orderedItems'], expectedItems)
|
||||
|
||||
def test_collection_response_spills(self):
|
||||
|
@ -173,7 +173,7 @@ class ResponseTests(TestCase):
|
|||
|
||||
def test_tombstone_collection_response(self):
|
||||
for name in ['King William', 'Queen Anne', 'Queen Elizabeth']:
|
||||
# "Queen Anne" is a magic name which causes ThingUser.activity
|
||||
# "Queen Anne" is a magic name which causes ThingUser.activity_form
|
||||
# to throw TombstoneException
|
||||
# XXX this is not elegant
|
||||
someone = ThingUser(name=name)
|
||||
|
|
|
@ -20,7 +20,7 @@ class ThingUser(models.Model):
|
|||
return '[ThingUser {}]'.format(self.name)
|
||||
|
||||
@property
|
||||
def activity(self):
|
||||
def activity_form(self):
|
||||
|
||||
if self.name=='Queen Anne':
|
||||
raise TombstoneException(original_type=self.activity_type)
|
||||
|
@ -46,7 +46,7 @@ class ThingUser(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def find_activity(cls, url):
|
||||
def activity_find(cls, url):
|
||||
PREFIX = "https://example.com/user/"
|
||||
|
||||
if url.startswith(PREFIX):
|
||||
|
@ -57,7 +57,7 @@ class ThingUser(models.Model):
|
|||
return cls.objects.get(name=name)
|
||||
|
||||
@classmethod
|
||||
def activitypub_create(cls, fields):
|
||||
def activity_create(cls, fields):
|
||||
result = cls(
|
||||
name=fields['id'],
|
||||
remote=True,
|
||||
|
@ -75,7 +75,8 @@ class ThingArticle(models.Model):
|
|||
remote_url = models.URLField(max_length=256,
|
||||
null=True, default=None)
|
||||
|
||||
def serialize(self):
|
||||
@property
|
||||
def activity_form(self):
|
||||
return {
|
||||
'id': self.activity_id,
|
||||
'type': 'Article',
|
||||
|
@ -89,23 +90,7 @@ class ThingArticle(models.Model):
|
|||
)
|
||||
|
||||
@classmethod
|
||||
def activity_create(cls, type_name, actor, fields):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def activity_update(cls, type_name, actor, fields, partial):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def activity_delete(cls, type_name, actor):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def activity_like(cls, type_name, actor, fobject):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def find_activity(cls, url):
|
||||
def activity_find(cls, url):
|
||||
PREFIX = "https://articles.example.com/"
|
||||
if url.startswith(PREFIX):
|
||||
title = url[len(PREFIX):]
|
||||
|
@ -114,7 +99,7 @@ class ThingArticle(models.Model):
|
|||
return cls.objects.get(remote_url=url)
|
||||
|
||||
@classmethod
|
||||
def activitypub_create(cls, fields):
|
||||
def activity_create(cls, fields):
|
||||
result = cls(
|
||||
remote_url=fields['id'],
|
||||
title=fields['title'],
|
||||
|
|
|
@ -8,7 +8,7 @@ class ThingUserCollection(CollectionView):
|
|||
return ThingUser.objects.all()
|
||||
|
||||
def _stringify_object(self, obj):
|
||||
return obj.activity
|
||||
return obj.activity_form
|
||||
|
||||
class ThingUserFollowingView(CollectionView):
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue