Re: Sending a list of items by email

2009-03-03 Thread Eric Abrahamsen


On Mar 3, 2009, at 7:52 PM, Alfonso wrote:

>
> Thinking this should be easy but not sure of the correct path to
> success!
>
> Got a simple filter queryset that pulls order products from a db:
>
> order_list = CustomerBasket.objects.all()
> customer = UserProfile.objects.get(user=user).customer
> email = EmailMessage(
>'New Customer Order: %s ' % customer,
>'%s' % order_list, to = ['email']
> )
> email.send()
>
> So when running the  above I get this in the sent email:
>
> [, , ]
>
> At least it's sending the email :-)  My question is, what's a
> straightforward way to iterate through the items in 'order list' and
> print them nicely in the email body.

You'll probably want to make a plain text template for your email  
bodies, and then render it using render_to_string and putting that  
string into the EmailMessage(). It's going to look ugly otherwise, as  
it appears string formatting runs model instances through repr() when  
they're inside another data structure (your list, in this case). If  
you don't want to do that you can use '\n'.join([unicode(x) for x in  
order_list]) to produce slightly nicer-looking formatting.

Yours,
Eric


>
> Thanks
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sending a list of items by email

2009-03-03 Thread A Melé

Alfonso,

If you ar using text e-mail you can just use: ', '.join(order_list) or
'\n'.join(order_list)

Another way, is using a string (nice for sending HTML e-mails):

order_list = CustomerBasket.objects.all()
customer = UserProfile.objects.get(user=user).customer
body = ''

for item in order_list:
body += '%s: %s' % (item.attribute1,
item.attribute2)

email = EmailMessage(
'New Customer Order: %s ' % customer,
body, to = ['email']
)
email.send()

I hope that helps you.

A Melé
http://django.es


On 3 mar, 12:52, Alfonso  wrote:
> Thinking this should be easy but not sure of the correct path to
> success!
>
> Got a simple filter queryset that pulls order products from a db:
>
> order_list = CustomerBasket.objects.all()
> customer = UserProfile.objects.get(user=user).customer
> email = EmailMessage(
>         'New Customer Order: %s ' % customer,
>         '%s' % order_list, to = ['email']
> )
> email.send()
>
> So when running the  above I get this in the sent email:
>
> [, , ]
>
> At least it's sending the email :-)  My question is, what's a
> straightforward way to iterate through the items in 'order list' and
> print them nicely in the email body.
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Sending a list of items by email

2009-03-03 Thread Alfonso

Thinking this should be easy but not sure of the correct path to
success!

Got a simple filter queryset that pulls order products from a db:

order_list = CustomerBasket.objects.all()
customer = UserProfile.objects.get(user=user).customer
email = EmailMessage(
'New Customer Order: %s ' % customer,
'%s' % order_list, to = ['email']
)
email.send()

So when running the  above I get this in the sent email:

[, , ]

At least it's sending the email :-)  My question is, what's a
straightforward way to iterate through the items in 'order list' and
print them nicely in the email body.

Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---