From cb5f115e4592e12e37992008b0b0730cb3ff935d Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Tue, 18 Sep 2018 23:09:18 +0100 Subject: [PATCH] Add "accepted" flag to Activity, which is a special case for Follows. Seems a bit hacky, though. f_type becomes a CharField, because it was a URLField, which is blatantly wrong. Activity now has the relevant properties to make it able to consider itself as an object type. --- .../migrations/0003_auto_20180918_1708.py | 23 ++++++++++++++ django_kepi/models.py | 31 ++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 django_kepi/migrations/0003_auto_20180918_1708.py diff --git a/django_kepi/migrations/0003_auto_20180918_1708.py b/django_kepi/migrations/0003_auto_20180918_1708.py new file mode 100644 index 0000000..0dfd564 --- /dev/null +++ b/django_kepi/migrations/0003_auto_20180918_1708.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1 on 2018-09-18 17:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('django_kepi', '0002_auto_20180916_1457'), + ] + + operations = [ + migrations.AddField( + model_name='activity', + name='accepted', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='activity', + name='f_type', + field=models.CharField(choices=[('C', 'Create'), ('U', 'Update'), ('D', 'Delete'), ('F', 'Follow'), ('+', 'Add'), ('-', 'Remove'), ('L', 'Like'), ('U', 'Undo'), ('A', 'Accept'), ('R', 'Reject')], max_length=1), + ), + ] diff --git a/django_kepi/models.py b/django_kepi/models.py index 35213ec..8e7f649 100644 --- a/django_kepi/models.py +++ b/django_kepi/models.py @@ -1,5 +1,5 @@ from django.db import models -from django_kepi import object_type_registry, resolve, NeedToFetchException +from django_kepi import object_type_registry, resolve, NeedToFetchException, register_type from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.conf import settings @@ -112,7 +112,7 @@ class Activity(models.Model): (REJECT, 'Reject'), ) - f_type = models.URLField( + f_type = models.CharField( max_length=1, choices=ACTIVITY_TYPE_CHOICES, ) @@ -147,6 +147,10 @@ class Activity(models.Model): default=True, ) + accepted = models.BooleanField( + default=False, + ) + # XXX Updates from clients are partial, # but updates from remote sites are total. # We don't currently let clients create Activities, @@ -166,6 +170,14 @@ class Activity(models.Model): ) return result + @property + def activity_id(self): + return self.identifier + + @property + def activity_type(self): + return self.f_type + @property def activity(self): result = { @@ -197,10 +209,19 @@ class Activity(models.Model): 'Remove': (True, False, True), 'Like': (True, True, False), 'Undo': (False, True, False), - 'Accept': (False, True, False), - 'Reject': (False, True, False), + 'Accept': (True, True, False), + 'Reject': (True, True, False), } + @classmethod + def register_all_activity_types(cls): + for t in cls.TYPES.keys(): + register_type(t, cls) + + @classmethod + def find_activity(cls, url): + return cls.objects.get(identifier=url) + @classmethod def create(cls, value, local=False): @@ -300,3 +321,5 @@ class Activity(models.Model): # TODO: there should be a clean() method with the same # checks as create(). +Activity.register_all_activity_types() +