Skip to content

snoop.data.serializers #

Django Rest Framwork serializer for the Tags API.

Classes#

DocumentUserTagSerializer #

Serializer for the Tags API.

Combines fields from the table with other fields from the URL path. Since this URL path is private between the backend services, we use it to store pertinent information too (e.g. user interacting with tags).

All fields are read-only except "public" and "tag". The UI doesn't edit "tag", so we may remove editing it in the future.

Classes#
Meta #

Configure the serializer model, fields and read only fields.

Classes#
model #

Table used to store tags made by users.

Both private and public tags are stored here.

Private tags are stored on separate Elasticsearch fields, one field per user. Tags are referenced both by usernames and user UUIDs, since we can't use usernames as parts of the elasticsearch field name (since they can contain characters like dot '.' that cannot be part of a field name).

Attributes#
blob property readonly #

Returns the Blob containing the document for this tag.

date_indexed #

Moment when document containing this tag was re-indexed.

digest #

Document being tagged.

field property readonly #

Returns the elasticsearch field name for this tag.

public #

Boolean that decides type of tag

tag #

String with the actual tag.

user #

Username, as string (to send back in the API).

uuid #

Unique identifier for user, used in elasticsearch field name.

Methods#
delete(self, *args, **kwargs) #

Override for re-indexing document targeted by this tag.

Source code in snoop/data/serializers.py
def delete(self, *args, **kwargs):
    """Override for re-indexing document targeted by this tag.
    """

    super().delete(*args, **kwargs)

    from . import digests
    digests.retry_index(self.blob)
save(self, *args, **kwargs) #

Override for re-indexing document targeted by this tag.

Source code in snoop/data/serializers.py
def save(self, *args, **kwargs):
    """Override for re-indexing document targeted by this tag.
    """

    self.check_tag_name()

    self.date_indexed = None
    super().save(*args, **kwargs)

    from . import digests
    digests.retry_index(self.blob)
Methods#
create(self, validated_data) #

Get additional fields from context when creating object.

See snoop.data.views.TagViewSet.get_serializer.

Source code in snoop/data/serializers.py
def create(self, validated_data):
    """Get additional fields from context when creating object.

    See [snoop.data.views.TagViewSet.get_serializer][].
    """

    data = dict(validated_data)
    data['user'] = self.context['user']
    data['uuid'] = self.context['uuid']
    data['digest_id'] = self.context['digest_id']
    return super().create(data)
update(self, instance, validated_data) #

Get additional fields from context when updating object.

See snoop.data.views.TagViewSet.get_serializer.

Source code in snoop/data/serializers.py
def update(self, instance, validated_data):
    """Get additional fields from context when updating object.

    See [snoop.data.views.TagViewSet.get_serializer][].
    """

    data = dict(validated_data)
    data['user'] = self.context['user']
    data['uuid'] = self.context['uuid']
    data['digest_id'] = self.context['digest_id']
    return super().update(instance, data)

EntitySerializer #

Classes#
Meta #
Classes#
model #

Database model for Entities. Entities have a textfield for their string and a type. Additionally, they may have a parent (if merged), or can be blacklisted (so not shown as entities).

Methods#
__repr__(self) special #

Return str(self).

Source code in snoop/data/serializers.py
def __str__(self):
    return f'entity.{self.type.type}: {self.entity}'