trilby's Status and Person classes now descend from a common ancestor,

AcObject. This allows bowler to return objects it finds without having
to require a particular type.
status-serialisers
Marnanel Thurman 2020-08-15 18:51:59 +01:00
rodzic 4bf78f6c37
commit e9d780d2a3
4 zmienionych plików z 56 dodań i 2 usunięć

Wyświetl plik

@ -0,0 +1,32 @@
# Generated by Django 3.0.9 on 2020-08-15 17:49
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('trilby_api', '0019_localperson_default_sensitive'),
]
operations = [
migrations.AlterModelOptions(
name='localperson',
options={},
),
migrations.AlterModelOptions(
name='person',
options={},
),
migrations.AlterModelOptions(
name='remoteperson',
options={},
),
migrations.AddField(
model_name='status',
name='polymorphic_ctype',
field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_trilby_api.status_set+', to='contenttypes.ContentType'),
),
]

Wyświetl plik

@ -0,0 +1,20 @@
# acobject.py
#
# Part of kepi.
# Copyright (c) 2018-2020 Marnanel Thurman.
# Licensed under the GNU Public License v2.
import logging
logger = logging.Logger("kepi")
from polymorphic.models import PolymorphicModel
class AcObject(PolymorphicModel):
"""
AcObjects are the ancestors of classes we can
receive over ActivityPub.
"""
class Meta:
abstract = True

Wyświetl plik

@ -19,8 +19,9 @@ import kepi.bowler_pub.utils as bowler_utils
from django.utils.timezone import now from django.utils.timezone import now
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from urllib.parse import urlparse from urllib.parse import urlparse
from .acobject import AcObject
class Person(PolymorphicModel): class Person(AcObject):
@property @property
def icon_or_default(self): def icon_or_default(self):

Wyświetl plik

@ -8,10 +8,11 @@ import kepi.trilby_api.utils as trilby_utils
from django.utils.timezone import now from django.utils.timezone import now
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
import logging import logging
from .acobject import AcObject
logger = logging.Logger('kepi') logger = logging.Logger('kepi')
class Status(models.Model): class Status(AcObject):
class Meta: class Meta:
verbose_name_plural = 'Statuses' verbose_name_plural = 'Statuses'