mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-24 00:50:35 +00:00
Moves blocking to save function
I just like these better than signals??
This commit is contained in:
parent
930d9429ef
commit
65f81bd5f0
2 changed files with 12 additions and 18 deletions
|
@ -195,7 +195,7 @@ def handle_block(activity):
|
||||||
''' blocking a user '''
|
''' blocking a user '''
|
||||||
# create "block" databse entry
|
# create "block" databse entry
|
||||||
activitypub.Block(**activity).to_model(models.UserBlocks)
|
activitypub.Block(**activity).to_model(models.UserBlocks)
|
||||||
# the removing relationships is handled in post-save hook in model
|
# the removing relationships is handled in model save
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
''' defines relationships between users '''
|
''' defines relationships between users '''
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.dispatch import receiver
|
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
from .activitypub_mixin import ActivitypubMixin, ActivityMixin
|
from .activitypub_mixin import ActivitypubMixin, ActivityMixin
|
||||||
|
@ -126,20 +125,15 @@ class UserBlocks(ActivityMixin, UserRelationship):
|
||||||
status = 'blocks'
|
status = 'blocks'
|
||||||
activity_serializer = activitypub.Block
|
activity_serializer = activitypub.Block
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
@receiver(models.signals.post_save, sender=UserBlocks)
|
|
||||||
#pylint: disable=unused-argument
|
|
||||||
def execute_after_save(sender, instance, created, *args, **kwargs):
|
|
||||||
''' remove follow or follow request rels after a block is created '''
|
''' remove follow or follow request rels after a block is created '''
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
UserFollows.objects.filter(
|
UserFollows.objects.filter(
|
||||||
Q(user_subject=instance.user_subject,
|
Q(user_subject=self.user_subject, user_object=self.user_object) | \
|
||||||
user_object=instance.user_object) | \
|
Q(user_subject=self.user_object, user_object=self.user_subject)
|
||||||
Q(user_subject=instance.user_object,
|
|
||||||
user_object=instance.user_subject)
|
|
||||||
).delete()
|
).delete()
|
||||||
UserFollowRequest.objects.filter(
|
UserFollowRequest.objects.filter(
|
||||||
Q(user_subject=instance.user_subject,
|
Q(user_subject=self.user_subject, user_object=self.user_object) | \
|
||||||
user_object=instance.user_object) | \
|
Q(user_subject=self.user_object, user_object=self.user_subject)
|
||||||
Q(user_subject=instance.user_object,
|
|
||||||
user_object=instance.user_subject)
|
|
||||||
).delete()
|
).delete()
|
||||||
|
|
Loading…
Reference in a new issue