I have a function which takes values from two classes and maps it into an array. The array then gets pushed into a send email function.
var p1 = document.getElementsByClassName('emailtest'),
email = [].map.call(p1, function(email) {
return email.value;
}).join(',');
var p2 = document.getElementsByClassName('reciptest'),
rname = [].map.call(p2, function(rname) {
return rname.value;
}).join(',');
var to = [];
var p3 = email.split(',');
var p4 = rname.split(',');
p3.forEach(function(em, i) {
var recipient = {
email: em,
name: null,
type: 'to'
};
if (p4.length > i)
recipient = p4[i];
to.push(recipient);
});
How would I implement this in python and more specifically django ? I have a rough idea on splitting the strings but am not sure how to convert the last section p3.forEach(function(em, i) and to.push(recipient)
asked Jul 10, 2015 at 2:29
vvdect
1851 gold badge2 silver badges14 bronze badges
1 Answer 1
Try this out:
to = []
p3 = email.split(',')
p4 = rname.split(',')
for i,em in enumerate(p3):
recipient = {'email': em, 'name': None, 'type': to}
if len(p4) > i:
recipient = p4[i]
to.append(recipient)
answered Jul 10, 2015 at 2:35
Brent Washburne
13.2k4 gold badges65 silver badges86 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
vvdect
Hey thanks. In regards to the string split. Would it be best to use request.POST.getlist ?
Brent Washburne
Only if the POST data has already been split for you. If it comes in as a single comma-delimited string, then no, you have to split it yourself.
rassa45
GET is probably the easiest
vvdect
Ok . This is actually a part of a broader issue that Im trying to solve. stackoverflow.com/questions/31329834/… Would really appreciate some advice on this
default