<s> from django . conf import settings <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . sites . models import Site <EOL> from django . utils . translation import ugettext as _ <EOL> import bleach <EOL> from celery import task <EOL> from kitsune . announcements . models import Announcement <EOL> from kitsune . sumo . decorators import timeit <EOL> from kitsune . sumo . email_utils import make_mail , safe_translation , send_messages <EOL> @ task ( ) <EOL> @ timeit <EOL> def send_group_email ( announcement_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> announcement = Announcement . objects . get ( pk = announcement_id ) <EOL> except Announcement . DoesNotExist : <EOL> return <EOL> group = announcement . group <EOL> users = User . objects . filter ( groups__in = [ group ] ) <EOL> plain_content = bleach . clean ( announcement . content_parsed , <EOL> tags = [ ] , strip = True ) . strip ( ) <EOL> email_kwargs = { '<STR_LIT:content>' : plain_content , <EOL> '<STR_LIT>' : announcement . content_parsed , <EOL> '<STR_LIT>' : Site . objects . get_current ( ) . domain } <EOL> text_template = '<STR_LIT>' <EOL> html_template = '<STR_LIT>' <EOL> @ safe_translation <EOL> def _make_mail ( locale , user ) : <EOL> subject = _ ( '<STR_LIT>' ) . format ( <EOL> group = group . name ) <EOL> mail = make_mail ( subject = subject , <EOL> text_template = text_template , <EOL> html_template = html_template , <EOL> context_vars = email_kwargs , <EOL> from_email = settings . TIDINGS_FROM_ADDRESS , <EOL> to_email = user . email ) <EOL> return mail <EOL> messages = [ ] <EOL> for u in users : <EOL> locale = u . profile . locale or settings . LANGUAGE_CODE <EOL> messages . append ( _make_mail ( locale , u ) ) <EOL> send_messages ( messages ) </s>
