<s> from django . contrib . auth . decorators import permission_required <EOL> from django . conf import settings <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . sites . models import Site <EOL> from django . core . mail import EmailMultiAlternatives <EOL> from django . shortcuts import render_to_response <EOL> from django . template . loader import render_to_string <EOL> from django . template import RequestContext <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> import lfs . core . utils <EOL> import lfs . marketing . utils <EOL> from lfs . catalog . models import Product <EOL> from lfs . marketing . models import OrderRatingMail <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def manage_rating_mails ( request , orders_sent = [ ] , template_name = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> return render_to_response ( template_name , RequestContext ( request , { } ) ) <EOL> @ permission_required ( "<STR_LIT>" ) <EOL> def send_rating_mails ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . method == "<STR_LIT:POST>" : <EOL> ctype = ContentType . objects . get_for_model ( Product ) <EOL> site = "<STR_LIT>" % Site . objects . get ( id = settings . SITE_ID ) <EOL> shop = lfs . core . utils . get_default_shop ( ) <EOL> subject = _ ( u"<STR_LIT>" ) <EOL> subject += shop . name <EOL> from_email = shop . from_email <EOL> orders_sent = [ ] <EOL> for order in lfs . marketing . utils . get_orders ( ) : <EOL> try : <EOL> OrderRatingMail . objects . get ( order = order ) <EOL> except OrderRatingMail . DoesNotExist : <EOL> pass <EOL> else : <EOL> continue <EOL> orders_sent . append ( order ) <EOL> if request . POST . get ( "<STR_LIT:test>" ) : <EOL> to = shop . get_notification_emails ( ) <EOL> bcc = [ ] <EOL> else : <EOL> to = [ order . customer_email ] <EOL> if request . POST . get ( "<STR_LIT>" ) : <EOL> bcc = shop . get_notification_emails ( ) <EOL> else : <EOL> bcc = [ ] <EOL> OrderRatingMail . objects . create ( order = order ) <EOL> text = render_to_string ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : order , <EOL> "<STR_LIT>" : ctype . id , <EOL> "<STR_LIT>" : site , <EOL> } ) <EOL> mail = EmailMultiAlternatives ( <EOL> subject = subject , body = text , from_email = from_email , to = to , bcc = bcc ) <EOL> order_items = [ ] <EOL> for order_item in order . items . all ( ) : <EOL> product = order_item . product <EOL> if product . is_variant ( ) : <EOL> product = product . parent <EOL> order_items . append ( { <EOL> "<STR_LIT>" : product . id , <EOL> "<STR_LIT>" : product . name , <EOL> } ) <EOL> html = render_to_string ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : order , <EOL> "<STR_LIT>" : order_items , <EOL> "<STR_LIT>" : ctype . id , <EOL> "<STR_LIT>" : site , <EOL> } ) <EOL> mail . attach_alternative ( html , "<STR_LIT>" ) <EOL> mail . send ( ) <EOL> return render_to_response ( "<STR_LIT>" , RequestContext ( request , { <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : orders_sent <EOL> } ) ) </s>
