2021-10-04 20:14:32 +00:00
|
|
|
""" outlink data """
|
2021-12-16 00:23:21 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
from bookwyrm import activitypub
|
2021-12-15 20:40:31 +00:00
|
|
|
from .activitypub_mixin import ActivitypubMixin
|
2021-10-04 20:14:32 +00:00
|
|
|
from .base_model import BookWyrmModel
|
|
|
|
from . import fields
|
|
|
|
|
2021-10-07 23:53:39 +00:00
|
|
|
|
2021-12-15 20:40:31 +00:00
|
|
|
class Link(ActivitypubMixin, BookWyrmModel):
|
2021-10-04 20:14:32 +00:00
|
|
|
"""a link to a website"""
|
|
|
|
|
2021-12-16 00:23:21 +00:00
|
|
|
url = fields.URLField(max_length=255, activitypub_field="href")
|
2021-10-04 20:14:32 +00:00
|
|
|
name = fields.CharField(max_length=255)
|
|
|
|
|
2021-12-16 00:23:21 +00:00
|
|
|
activity_serializer = activitypub.Link
|
|
|
|
reverse_unfurl = True
|
|
|
|
|
2021-12-15 20:40:31 +00:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
"""create a link"""
|
|
|
|
# this is never broadcast, the owning model broadcasts an update
|
|
|
|
if "broadcast" in kwargs:
|
|
|
|
del kwargs["broadcast"]
|
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
2021-10-04 20:14:32 +00:00
|
|
|
|
|
|
|
class FileLink(Link):
|
|
|
|
"""a link to a file"""
|
|
|
|
|
2021-12-16 01:10:59 +00:00
|
|
|
book = models.ForeignKey(
|
2021-12-16 00:23:21 +00:00
|
|
|
"Book", on_delete=models.CASCADE, related_name="file_links", null=True
|
|
|
|
)
|
|
|
|
filetype = fields.CharField(max_length=5, activitypub_field="mediaType")
|