Notification emails #80
@ -7,22 +7,22 @@ from django.db.models.signals import m2m_changed, pre_save, post_save, post_dele
|
||||
from django.dispatch import receiver
|
||||
|
||||
from constants.activity import Flag
|
||||
from extensions.models import Extension, Preview, Version
|
||||
import extensions.models
|
||||
import files.models
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@receiver(post_delete, sender=Preview)
|
||||
def _delete_file(sender: object, instance: Preview, **kwargs: object) -> None:
|
||||
@receiver(post_delete, sender=extensions.models.Preview)
|
||||
def _delete_file(sender: object, instance: extensions.models.Preview, **kwargs: object) -> None:
|
||||
instance.file.delete()
|
||||
|
||||
|
||||
@receiver(pre_save, sender=Extension)
|
||||
@receiver(pre_save, sender=Version)
|
||||
@receiver(pre_save, sender=extensions.models.Extension)
|
||||
@receiver(pre_save, sender=extensions.models.Version)
|
||||
def _record_changes(
|
||||
sender: object,
|
||||
instance: Union[Extension, Version],
|
||||
instance: Union[extensions.models.Extension, extensions.models.Version],
|
||||
**kwargs: object,
|
||||
) -> None:
|
||||
was_changed, old_state = instance.pre_save_record()
|
||||
@ -35,7 +35,7 @@ def _record_changes(
|
||||
instance.record_status_change(was_changed, old_state, **kwargs)
|
||||
|
||||
|
||||
@receiver(post_save, sender=Extension)
|
||||
@receiver(post_save, sender=extensions.models.Extension)
|
||||
def _update_search_index(sender, instance, **kw):
|
||||
pass # TODO: update search index
|
||||
|
||||
@ -49,18 +49,18 @@ def extension_should_be_listed(extension):
|
||||
)
|
||||
|
||||
|
||||
@receiver(post_save, sender=Extension)
|
||||
@receiver(post_save, sender=Version)
|
||||
@receiver(post_save, sender=extensions.models.Extension)
|
||||
@receiver(post_save, sender=extensions.models.Version)
|
||||
@receiver(post_save, sender=files.models.File)
|
||||
def _set_is_listed(
|
||||
sender: object,
|
||||
instance: Union[Extension, Version, files.models.File],
|
||||
instance: Union[extensions.models.Extension, extensions.models.Version, files.models.File],
|
||||
*args: object,
|
||||
**kwargs: object,
|
||||
) -> None:
|
||||
if isinstance(instance, Extension):
|
||||
if isinstance(instance, extensions.models.Extension):
|
||||
extension = instance
|
||||
elif isinstance(instance, Version):
|
||||
elif isinstance(instance, extensions.models.Version):
|
||||
extension = instance.extension
|
||||
else:
|
||||
# Some file types (e.g., image or video) have no version associated to them.
|
||||
@ -76,17 +76,17 @@ def _set_is_listed(
|
||||
if old_is_listed == new_is_listed:
|
||||
return
|
||||
|
||||
if extension.status == Extension.STATUSES.APPROVED and not new_is_listed:
|
||||
extension.status = Extension.STATUSES.INCOMPLETE
|
||||
if extension.status == extensions.models.Extension.STATUSES.APPROVED and not new_is_listed:
|
||||
extension.status = extensions.models.Extension.STATUSES.INCOMPLETE
|
||||
|
||||
extension.is_listed = new_is_listed
|
||||
extension.save()
|
||||
|
||||
|
||||
@receiver(post_save, sender=Extension)
|
||||
@receiver(post_save, sender=extensions.models.Extension)
|
||||
def _setup_followers(
|
||||
sender: object,
|
||||
instance: Extension,
|
||||
instance: extensions.models.Extension,
|
||||
created: bool,
|
||||
**kwargs: object,
|
||||
) -> None:
|
||||
@ -99,20 +99,20 @@ def _setup_followers(
|
||||
follow(user, instance, send_action=False, flag=Flag.MODERATOR)
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=Extension.authors.through)
|
||||
@receiver(m2m_changed, sender=extensions.models.Extension.authors.through)
|
||||
def _update_authors_follow(instance, action, model, reverse, pk_set, **kwargs):
|
||||
if action not in ['post_add', 'post_remove']:
|
||||
return
|
||||
|
||||
if model == Extension and not reverse:
|
||||
if model == extensions.models.Extension and not reverse:
|
||||
targets = extensions.models.Extension.objects.filter(pk__in=pk_set)
|
||||
users = [instance]
|
||||
extensions = Extension.objects.filter(pk__in=pk_set)
|
||||
else:
|
||||
extensions = [instance]
|
||||
targets = [instance]
|
||||
users = User.objects.filter(pk__in=pk_set)
|
||||
|
||||
for user in users:
|
||||
for extension in extensions:
|
||||
for extension in targets:
|
||||
if action == 'post_remove':
|
||||
unfollow(user, extension, send_action=False, flag=Flag.AUTHOR)
|
||||
elif action == 'post_add':
|
||||
|
Loading…
Reference in New Issue
Block a user