(template, user_ids, sender=None, extra_context={})
Create batch message from sender to a given recipient_list
Create batch message from sender to a given recipient_list
Create batch message from sender to a given recipient_list
def create_messages(template, user_ids, sender=None, extra_context={}):
    """
    Create batch message from sender to a given recipient_list
    """
    from biostar.accounts.models import User, Message, MessageBody

    rec_list = User.objects.filter(id__in=user_ids)
    # Get the sender
    name, email = settings.ADMINS[0]
    sender = sender or User.objects.filter(email=email).first() or User.objects.filter(is_superuser=True).first()
    # Load the template and context
    tmpl = loader.get_template(template_name=template)

    # Default context added to each template.
    context = dict(sender=sender, domain=settings.SITE_DOMAIN, protocol=settings.PROTOCOL)

    context.update(extra_context)
    body = tmpl.render(context)
    html = mistune.markdown(body, escape=False)
    body = MessageBody.objects.create(body=body, html=html)

    for rec in rec_list:
        Message.objects.create(sender=sender, recipient=rec, body=body)
def create_messages ( template , user_ids , sender = None , extra_context = { } ) : from biostar . accounts . models import User , Message , MessageBody rec_list = User . objects . filter ( id__in = user_ids ) # Get the sender name , email = settings . ADMINS [ 0 ] sender = sender or User . objects . filter ( email = email ) . first ( ) or User . objects . filter ( is_superuser = True ) . first ( ) # Load the template and context tmpl = loader . get_template ( template_name = template ) # Default context added to each template. context = dict ( sender = sender , domain = settings . SITE_DOMAIN , protocol = settings . PROTOCOL ) context . update ( extra_context ) body = tmpl . render ( context ) html = mistune . markdown ( body , escape = False ) body = MessageBody . objects . create ( body = body , html = html ) for rec in rec_list : Message . objects . create ( sender = sender , recipient = rec , body = body )