diff --git a/bookwyrm/migrations/0121_filelink_link.py b/bookwyrm/migrations/0126_filelink_link_linkdomain.py similarity index 58% rename from bookwyrm/migrations/0121_filelink_link.py rename to bookwyrm/migrations/0126_filelink_link_linkdomain.py index 716d56040..1235e81dc 100644 --- a/bookwyrm/migrations/0121_filelink_link.py +++ b/bookwyrm/migrations/0126_filelink_link_linkdomain.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.5 on 2021-12-16 00:20 +# Generated by Django 3.2.10 on 2022-01-09 21:16 import bookwyrm.models.activitypub_mixin import bookwyrm.models.fields @@ -9,7 +9,7 @@ import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - ("bookwyrm", "0120_list_embed_key"), + ("bookwyrm", "0125_alter_user_preferred_language"), ] operations = [ @@ -36,13 +36,53 @@ class Migration(migrations.Migration): ), ), ("url", bookwyrm.models.fields.URLField(max_length=255)), - ("name", bookwyrm.models.fields.CharField(max_length=255)), ], options={ "abstract": False, }, bases=(bookwyrm.models.activitypub_mixin.ActivitypubMixin, models.Model), ), + migrations.CreateModel( + name="LinkDomain", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("created_date", models.DateTimeField(auto_now_add=True)), + ("updated_date", models.DateTimeField(auto_now=True)), + ( + "remote_id", + bookwyrm.models.fields.RemoteIdField( + max_length=255, + null=True, + validators=[bookwyrm.models.fields.validate_remote_id], + ), + ), + ("domain", models.CharField(max_length=255)), + ( + "status", + models.CharField( + choices=[ + ("approved", "Approved"), + ("blocked", "Blocked"), + ("pending", "Pending"), + ], + default="pending", + max_length=50, + ), + ), + ("name", models.CharField(max_length=100)), + ], + options={ + "abstract": False, + }, + ), migrations.CreateModel( name="FileLink", fields=[ @@ -60,7 +100,7 @@ class Migration(migrations.Migration): ("filetype", bookwyrm.models.fields.CharField(max_length=5)), ( "book", - bookwyrm.models.fields.ForeignKey( + models.ForeignKey( null=True, on_delete=django.db.models.deletion.CASCADE, related_name="file_links", diff --git a/bookwyrm/models/link.py b/bookwyrm/models/link.py index bc8f5ce3c..12a5fae19 100644 --- a/bookwyrm/models/link.py +++ b/bookwyrm/models/link.py @@ -1,5 +1,6 @@ """ outlink data """ from django.db import models +from django.utils.translation import gettext_lazy as _ from bookwyrm import activitypub from .activitypub_mixin import ActivitypubMixin @@ -11,7 +12,6 @@ class Link(ActivitypubMixin, BookWyrmModel): """a link to a website""" url = fields.URLField(max_length=255, activitypub_field="href") - name = fields.CharField(max_length=255) activity_serializer = activitypub.Link reverse_unfurl = True @@ -31,3 +31,24 @@ class FileLink(Link): "Book", on_delete=models.CASCADE, related_name="file_links", null=True ) filetype = fields.CharField(max_length=5, activitypub_field="mediaType") + + +StatusChoices = [ + ("approved", _("Approved")), + ("blocked", _("Blocked")), + ("pending", _("Pending")), +] + + +class LinkDomain(BookWyrmModel): + """List of domains used in links""" + + domain = models.CharField(max_length=255) + status = models.CharField(max_length=50, choices=StatusChoices, default="pending") + name = models.CharField(max_length=100) + + def save(self, *args, **kwargs): + """set a default name""" + if not self.name: + self.name = self.domain + super().save(*args, **kwargs)