Commit b61b9efe authored by Michal Čihař's avatar Michal Čihař

Automatically add subscriptions when adding owners

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 647272ab
...@@ -21,9 +21,10 @@ ...@@ -21,9 +21,10 @@
import os import os
import shutil import shutil
from django.db.models.signals import post_delete, post_save from django.db.models.signals import post_delete, post_save, m2m_changed
from django.dispatch import receiver from django.dispatch import receiver
from weblate.accounts.models import Profile
from weblate.trans.models.project import Project from weblate.trans.models.project import Project
from weblate.trans.models.subproject import SubProject from weblate.trans.models.subproject import SubProject
from weblate.trans.models.translation import Translation from weblate.trans.models.translation import Translation
...@@ -262,3 +263,16 @@ def user_commit_pending(sender, instance, **kwargs): ...@@ -262,3 +263,16 @@ def user_commit_pending(sender, instance, **kwargs):
last_author = translation.change_set.content()[0].author last_author = translation.change_set.content()[0].author
if last_author == instance: if last_author == instance:
translation.commit_pending(None) translation.commit_pending(None)
@receiver(m2m_changed, sender=Profile.subscriptions.through)
def add_user_subscription(sender, instance, action, reverse, model, pk_set, **kwargs):
if action != 'post_add':
return
targets = model.objects.filter(pk__in=pk_set)
if reverse:
for target in targets:
instance.add_subscription(target.user)
else:
for target in targets:
target.add_subscription(instance.user)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment