kopia lustrzana https://gitlab.com/marnanel/chapeau
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.thingy_objects
rodzic
0812080730
commit
cb5f115e45
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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()
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue