Okay, the NamedObject table was a mistake. Let's use the existing registration system.

thingy_objects
Marnanel Thurman 2018-09-06 23:01:18 +01:00
rodzic 928934eab2
commit 553c3d8d3d
5 zmienionych plików z 53 dodań i 49 usunięć

Wyświetl plik

@ -1,3 +1,5 @@
from collections import Iterable
__title__ = 'django_kepi'
__version__ = '0.0.16'
VERSION = __version__
@ -31,13 +33,30 @@ ATSIGN_CONTEXT = [
}
]
object_type_registry = {
'Object': None,
}
def register_type(a_typename, a_typeclass):
object_type_registry[a_typename] = a_typeclass
def register_type(atype, handler):
object_type_registry[atype] = handler
def resolve(identifier, atype=None):
if atype is None:
atype = object_type_registry.keys()
elif not isinstance(atype, Iterable):
atype = [atype]
for t in atype:
if t not in object_type_registry:
continue
result = object_type_registry[t].find_activity(url=identifier)
if result is not None:
return result
return None
class TombstoneException(Exception):

Wyświetl plik

@ -0,0 +1,20 @@
# Generated by Django 2.1 on 2018-09-06 16:57
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('django_kepi', '0009_namedobject'),
]
operations = [
migrations.RemoveField(
model_name='namedobject',
name='content_type',
),
migrations.DeleteModel(
name='NamedObject',
),
]

Wyświetl plik

@ -373,48 +373,4 @@ class RequestingAccess(UserRelationship):
self.following.name,
)
class UnexpiredNamedObjectsManager(models.Manager):
def get_queryset(self):
return super().get_queryset().exclude(
#expiry==datetime.datetime.now(),
)
class NamedObject(models.Model):
"""
This table maps URL identifiers to Django objects, using the
contenttypes mechanism. It also keeps track of the object's
ActivityObject type.
Any object we know about on a remote server must be listed
here. Objects on this server *may* be listed here; if they're not,
django_kepi.resolve() can also find them
through following the URL path.
"""
url = models.URLField(
max_length=255,
primary_key=True,
)
activity_type = models.CharField(
max_length=255,
)
expiry = models.DateTimeField(default=None)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
objects = UnexpiredNamedObjectsManager()
all_objects = models.Manager()
def resolve(identifier):
try:
result = NamedObject.objects.get(url=identifier)
return result
except NamedObject.DoesNotExist:
pass
return None

Wyświetl plik

@ -1,5 +1,5 @@
from django.test import TestCase
from django_kepi.models import resolve
from django_kepi import resolve
class ResolveTests(TestCase):

Wyświetl plik

@ -51,6 +51,10 @@ class ThingUser(models.Model):
self.name,
)
@classmethod
def find_activity(self, url):
return None # XXX stub
register_type('Person', ThingUser)
class ThingArticle(models.Model):
@ -86,5 +90,10 @@ class ThingArticle(models.Model):
def activity_like(cls, type_name, actor, fobject):
pass
@classmethod
def find_activity(self, url):
return None # XXX stub
register_type('Article', ThingArticle)