Merge branch 'main' into inventaire

This commit is contained in:
Mouse Reeve
2021-04-26 14:22:05 -07:00
280 changed files with 20693 additions and 9991 deletions

View File

@ -6,7 +6,7 @@ from bookwyrm import models
def update_related(canonical, obj):
""" update all the models with fk to the object being removed """
"""update all the models with fk to the object being removed"""
# move related models to canonical
related_models = [
(r.remote_field.name, r.related_model) for r in canonical._meta.related_objects
@ -24,7 +24,7 @@ def update_related(canonical, obj):
def copy_data(canonical, obj):
""" try to get the most data possible """
"""try to get the most data possible"""
for data_field in obj._meta.get_fields():
if not hasattr(data_field, "activitypub_field"):
continue
@ -38,7 +38,7 @@ def copy_data(canonical, obj):
def dedupe_model(model):
""" combine duplicate editions and update related models """
"""combine duplicate editions and update related models"""
fields = model._meta.get_fields()
dedupe_fields = [
f for f in fields if hasattr(f, "deduplication_field") and f.deduplication_field
@ -68,12 +68,12 @@ def dedupe_model(model):
class Command(BaseCommand):
""" dedplucate allllll the book data models """
"""dedplucate allllll the book data models"""
help = "merges duplicate book data"
# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
""" run deudplications """
"""run deudplications"""
dedupe_model(models.Edition)
dedupe_model(models.Work)
dedupe_model(models.Author)

View File

@ -10,15 +10,15 @@ r = redis.Redis(
def erase_streams():
""" throw the whole redis away """
"""throw the whole redis away"""
r.flushall()
class Command(BaseCommand):
""" delete activity streams for all users """
"""delete activity streams for all users"""
help = "Delete all the user streams"
# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
""" flush all, baby """
"""flush all, baby"""
erase_streams()

View File

@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from bookwyrm.models import Connector, SiteSettings, User
from bookwyrm.models import Connector, FederatedServer, SiteSettings, User
from bookwyrm.settings import DOMAIN
@ -119,6 +119,16 @@ def init_connectors():
)
def init_federated_servers():
"""big no to nazis"""
built_in_blocks = ["gab.ai", "gab.com"]
for server in built_in_blocks:
FederatedServer.objects.create(
server_name=server,
status="blocked",
)
def init_settings():
SiteSettings.objects.create()
@ -130,4 +140,5 @@ class Command(BaseCommand):
init_groups()
init_permissions()
init_connectors()
init_federated_servers()
init_settings()

View File

@ -10,21 +10,21 @@ r = redis.Redis(
def populate_streams():
""" build all the streams for all the users """
"""build all the streams for all the users"""
users = models.User.objects.filter(
local=True,
is_active=True,
)
for user in users:
for stream in activitystreams.streams.values():
stream.populate_stream(user)
stream.populate_streams(user)
class Command(BaseCommand):
""" start all over with user streams """
"""start all over with user streams"""
help = "Populate streams for all users"
# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
""" run feed builder """
"""run feed builder"""
populate_streams()

View File

@ -5,7 +5,7 @@ from bookwyrm import models
def remove_editions():
""" combine duplicate editions and update related models """
"""combine duplicate editions and update related models"""
# not in use
filters = {
"%s__isnull" % r.name: True for r in models.Edition._meta.related_objects
@ -33,10 +33,10 @@ def remove_editions():
class Command(BaseCommand):
""" dedplucate allllll the book data models """
"""dedplucate allllll the book data models"""
help = "merges duplicate book data"
# pylint: disable=no-self-use,unused-argument
def handle(self, *args, **options):
""" run deudplications """
"""run deudplications"""
remove_editions()