(sub_ids, author_id, uid, extra_context={})
Generate notification to users subscribed to a post, excluding author, a message/email.
Generate notification to users subscribed to a post, excluding author, a message/email.
Generate notification to users subscribed to a post excluding author a message / email .
def notify_followers(sub_ids, author_id, uid, extra_context={}):
    """
    Generate notification to users subscribed to a post, excluding author, a message/email.
    """
    from biostar.forum.models import Subscription
    from biostar.accounts.models import Profile, User
    from biostar.forum.models import Post
    from django.conf import settings

    # Template used to send local messages
    local_template = "messages/subscription_message.md"

    # Template used to send emails with
    email_template = "messages/subscription_email.html"

    # Does not have subscriptions.
    if not sub_ids:
        return

    post = Post.objects.filter(uid=uid).first()
    author = User.objects.filter(id=author_id).first()
    subs = Subscription.objects.filter(id__in=sub_ids)

    users = [sub.user for sub in subs]
    user_ids = [u.pk for u in users]

    # Update template context with post
    extra_context.update(dict(post=post))

    # Every subscribed user gets local messages with any subscription type.
    create_messages(template=local_template,
                    extra_context=extra_context,
                    user_ids=user_ids,
                    sender=author)

    # Select users with email subscriptions.
    email_subs = subs.filter(type=Subscription.EMAIL_MESSAGE)
    # Exclude mailing list users to avoid duplicate emails.
    email_subs = email_subs.exclude(user__profile__digest_prefs=Profile.ALL_MESSAGES)
    # No email subscriptions
    if not email_subs:
        return

    recipient_list = [sub.user.email for sub in email_subs]
    from_email = settings.DEFAULT_NOREPLY_EMAIL

    send_email(template_name=email_template,
               extra_context=extra_context,
               name=author.profile.name,
               from_email=from_email,
               recipient_list=recipient_list,
               mass=True)
def notify_followers ( sub_ids , author_id , uid , extra_context = { } ) : from biostar . forum . models import Subscription from biostar . accounts . models import Profile , User from biostar . forum . models import Post from django . conf import settings # Template used to send local messages local_template = "messages/subscription_message.md" # Template used to send emails with email_template = "messages/subscription_email.html" # Does not have subscriptions. if not sub_ids : return post = Post . objects . filter ( uid = uid ) . first ( ) author = User . objects . filter ( id = author_id ) . first ( ) subs = Subscription . objects . filter ( id__in = sub_ids ) users = [ sub . user for sub in subs ] user_ids = [ u . pk for u in users ] # Update template context with post extra_context . update ( dict ( post = post ) ) # Every subscribed user gets local messages with any subscription type. create_messages ( template = local_template , extra_context = extra_context , user_ids = user_ids , sender = author ) # Select users with email subscriptions. email_subs = subs . filter ( type = Subscription . EMAIL_MESSAGE ) # Exclude mailing list users to avoid duplicate emails. email_subs = email_subs . exclude ( user__profile__digest_prefs = Profile . ALL_MESSAGES ) # No email subscriptions if not email_subs : return recipient_list = [ sub . user . email for sub in email_subs ] from_email = settings . DEFAULT_NOREPLY_EMAIL send_email ( template_name = email_template , extra_context = extra_context , name = author . profile . name , from_email = from_email , recipient_list = recipient_list , mass = True )