2018-08-12 13:06:26 +00:00
|
|
|
from django.db import models
|
|
|
|
from django_kepi import register_type
|
|
|
|
|
|
|
|
class ThingUser(models.Model):
|
|
|
|
|
|
|
|
name = models.CharField(max_length=256)
|
2018-08-18 19:21:39 +00:00
|
|
|
#activity_object = models.OneToOneField(
|
|
|
|
# ActivityObject,
|
|
|
|
# on_delete=models.CASCADE,
|
|
|
|
# )
|
2018-08-12 13:06:26 +00:00
|
|
|
|
2018-08-24 17:13:57 +00:00
|
|
|
ftype = 'Person'
|
|
|
|
|
2018-08-27 17:53:52 +00:00
|
|
|
def as_activity(self):
|
2018-08-12 13:06:26 +00:00
|
|
|
return {
|
2018-08-19 20:47:54 +00:00
|
|
|
'id': self.url_identifier(),
|
|
|
|
'type': 'Person',
|
2018-08-12 13:06:26 +00:00
|
|
|
'name': self.name,
|
|
|
|
}
|
|
|
|
|
2018-08-19 16:47:46 +00:00
|
|
|
def url_identifier(self):
|
|
|
|
return 'https://example.com/user/{}'.format(
|
|
|
|
self.name,
|
|
|
|
)
|
2018-08-19 20:47:54 +00:00
|
|
|
|
2018-08-24 17:13:57 +00:00
|
|
|
register_type('Person', ThingUser)
|
|
|
|
|
2018-08-19 20:47:54 +00:00
|
|
|
class ThingArticle(models.Model):
|
|
|
|
|
|
|
|
title = models.CharField(max_length=256)
|
2018-08-24 17:13:57 +00:00
|
|
|
ftype = 'Article'
|
2018-08-19 20:47:54 +00:00
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return {
|
|
|
|
'id': self.url_identifier(),
|
|
|
|
'type': 'Article',
|
|
|
|
'title': self.title,
|
|
|
|
}
|
|
|
|
|
|
|
|
def url_identifier(self):
|
|
|
|
return 'https://articles.example.com/{}'.format(
|
|
|
|
self.title,
|
|
|
|
)
|
|
|
|
|
2018-08-24 17:13:57 +00:00
|
|
|
@classmethod
|
|
|
|
def activity_create(cls, type_name, actor, fields):
|
2018-08-27 18:13:30 +00:00
|
|
|
pass
|
2018-08-24 17:13:57 +00:00
|
|
|
|
2018-08-27 18:13:30 +00:00
|
|
|
@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
|
2018-08-19 20:47:54 +00:00
|
|
|
|
2018-08-24 17:13:57 +00:00
|
|
|
register_type('Article', ThingArticle)
|
2018-08-27 17:53:52 +00:00
|
|
|
|