a very basic sketch

thingy_objects
Marnanel Thurman 2018-08-11 17:01:27 +01:00
rodzic 6c3f76fb8f
commit 830d2d30e1
7 zmienionych plików z 116 dodań i 28 usunięć

Wyświetl plik

@ -5,3 +5,28 @@ __author__ = 'Marnanel Thurman'
__license__ = 'GPL-2'
__copyright__ = 'Copyright (c) 2018 Marnanel Thurman'
# XXX this is mastodon-specific; it will be generalised later
ATSIGN_CONTEXT = [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1",
{
"schema": "http://schema.org#",
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
"movedTo": "as:movedTo",
"conversation": "ostatus:conversation",
"ostatus": "http://ostatus.org#",
"atomUri": "ostatus:atomUri",
"featured": "toot:featured",
"value": "schema:value",
"PropertyValue": "schema:PropertyValue",
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"Hashtag": "as:Hashtag",
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
"focalPoint": {
"@id": "toot:focalPoint",
"@container": "@list"
},
"Emoji": "toot:Emoji"
}
]

Wyświetl plik

@ -1,3 +1,54 @@
from django.db import models
# Create your models here.
object_type_registry = {
'Object': None,
}
def register_type(type_name, type_class):
object_type_registry[type_name] = type_class
class ActivityObject(models.Model):
type_ = models.CharField(max_length=255,
default='Object')
verified = models.BooleanField(default=False)
def save(self, *args, **kwargs):
if self.type_ not in object_type_registry:
raise ValueError("Can't save object with unknown type {}".format(
self.type_,
))
super().save(*args, **kwargs)
def activity_fields(self):
result = {}
try:
type_class = object_type_registry[self.type_]
except KeyError:
raise ValueError("ActivityObject {} has unknown type {}".format(
self.pk,
self.type_,
))
if type_class is not None:
instance = type_class.objects.find(activity_object__pk=self.pk)
if instance is None:
raise ValueError("ActivityObject {} has no corresponding instance in type {}".format(
self.pk,
self.type_,
))
result.update(
instance.activity_fields(),
)
result.update({
'id': self.pk,
'type': self.type_,
})
return result

Wyświetl plik

@ -1,6 +1,4 @@
from un_chapeau.config import config
from un_chapeau.constants import ATSIGN_CONTEXT
import trilby_api.models as trilby_models
from . import ATSIGN_CONTEXT
from rest_framework_constant.fields import ConstantField
from rest_framework import serializers, mixins, pagination
from rest_framework.response import Response

Wyświetl plik

@ -1,16 +1,11 @@
# XXX several of these are probably superfluous
from django.shortcuts import render, get_object_or_404
from django.views import View
from django.http import HttpResponse, JsonResponse
from oauth2_provider.models import Application
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.datastructures import MultiValueDictKeyError
from django.core.exceptions import SuspiciousOperation
from un_chapeau.config import config
import trilby_api.models as trilby
import kepi_activity.serializers as serializers
import django_kepi.serializers as serializers
from rest_framework import generics, response
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

Wyświetl plik

@ -1,20 +1,39 @@
import os
from setuptools import setup
import re
from io import open
from setuptools import find_packages, setup
# much of this was cribbed from django_rest_framework
here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README.md')).read()
README = open('README.md', 'r', encoding='utf-8').read()
def get_version(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
init_py = open(os.path.join(package, '__init__.py')).read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
version = get_version('django_kepi')
setup(
name='django-kepi',
version='0.1.0',
packages=['django-kepi'],
description='ActivityPub for Django',
long_description=README,
author='Marnanel Thurman',
author_email='marnanel@thurman.org.uk',
url='https://gitlab.com/marnanel/django-kepi',
license='GPL 2.0',
install_requires=[
'Django>=2.0',
]
)
name='django_kepi',
version=version,
url='https://gitlab.com/marnanel/django-kepi/',
license='GPL-2',
description='ActivityPub for Django',
long_description=README,
long_description_content_type='text/markdown',
author='Marnanel Thurman',
author_email='marnanel@thurman.org.uk',
packages=['django_kepi'],
include_package_data=True,
install_requires=[],
python_requires=">=3.0",
#zip_safe=False,
classifiers=[
# XXX fixme
]
)

Wyświetl plik

@ -1,11 +1,11 @@
from django.test import TestCase, Client
from .views import User
from django_kepi.views import User
class UserTests(TestCase):
def test_user_activity(self):
def test_collections(self):
c = Client()
activity = c.get('/users/alice/activity').json()
activity = c.get('/collections/0').json()
raise ValueError(str(activity))