cleans up ordered collection mixin
This commit is contained in:
@ -36,7 +36,7 @@ class ActivitypubFieldMixin:
|
||||
def field_to_activity(self, value):
|
||||
''' formatter to convert a model value into activitypub '''
|
||||
if hasattr(self, 'activitypub_wrapper'):
|
||||
value = {self.activitypub_wrapper: value}
|
||||
return {self.activitypub_wrapper: value}
|
||||
return value
|
||||
|
||||
def from_activity(self, activity_data):
|
||||
@ -46,6 +46,14 @@ class ActivitypubFieldMixin:
|
||||
value = value.get(self.activitypub_wrapper)
|
||||
return value
|
||||
|
||||
def get_activitypub_field(self):
|
||||
''' model_field_name to activitypubFieldName '''
|
||||
if self.activitypub_field:
|
||||
return self.activitypub_field
|
||||
name = self.name.split('.')[-1]
|
||||
components = name.split('_')
|
||||
return components[0] + ''.join(x.title() for x in components[1:])
|
||||
|
||||
|
||||
class RemoteIdField(ActivitypubFieldMixin, models.CharField):
|
||||
''' a url that serves as a unique identifier '''
|
||||
@ -91,8 +99,6 @@ class ForeignKey(ActivitypubFieldMixin, models.ForeignKey):
|
||||
if not value:
|
||||
return None
|
||||
return value.remote_id
|
||||
def from_activity(self, activity_data):
|
||||
pass# TODO
|
||||
|
||||
|
||||
class OneToOneField(ActivitypubFieldMixin, models.OneToOneField):
|
||||
@ -102,9 +108,6 @@ class OneToOneField(ActivitypubFieldMixin, models.OneToOneField):
|
||||
return None
|
||||
return value.to_activity()
|
||||
|
||||
def from_activity(self, activity_data):
|
||||
pass# TODO
|
||||
|
||||
|
||||
class ManyToManyField(ActivitypubFieldMixin, models.ManyToManyField):
|
||||
''' activitypub-aware many to many field '''
|
||||
@ -123,6 +126,7 @@ class ManyToManyField(ActivitypubFieldMixin, models.ManyToManyField):
|
||||
values = super().from_activity(activity_data)
|
||||
return values# TODO
|
||||
|
||||
|
||||
class TagField(ManyToManyField):
|
||||
''' special case of many to many that uses Tags '''
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -145,7 +149,6 @@ class TagField(ManyToManyField):
|
||||
|
||||
def image_serializer(value):
|
||||
''' helper for serializing images '''
|
||||
print(value)
|
||||
if value and hasattr(value, 'url'):
|
||||
url = value.url
|
||||
else:
|
||||
|
Reference in New Issue
Block a user