I have a form that is working well. However I want to allow them to
reuse the form multiple times. Each time they submit the form, I will
send up to 6 emails. Then, if an email is sent successfully, I want
to remove that email address from the form that I present to them. If
the email isn't successfully sent, I want to move that field up the
list.
The problem comes when I get to
self.data[friend] = ''
inside clearsent
When I work thru this in the shell, it works as expected, but when
runserver is going, it generates the error: This QueryDict instance is
immutable
I don't want to clear all the fields, I want to leave the email
subject and body alone and clear the 'To' fields and present the form
for another round of emails to be sent. How do you do this?
class AnnounceForm(forms.Form):
friend1 = forms.EmailField(label='1st Friend', required=True,
help_text='Enter the first friend you want to tell about this')
friend2 = forms.EmailField(label='2nd Friend', required=False)
friend3 = forms.EmailField(label='3rd Friend', required=False)
friend4 = forms.EmailField(label='4th Friend', required=False)
friend5 = forms.EmailField(label='5th Friend', required=False)
friend6 = forms.EmailField(label='6th Friend', required=False)
cc_myself = forms.BooleanField(label='cc myself', required=False)
emailsubject = forms.CharField(label='Email Subject')
emailbody = forms.CharField(widget=forms.Textarea, label='The
email will say:')
friends =
('friend1','friend2','friend3','friend4','friend5','friend6')
def recipients(self):
data = super(AnnounceQuizForm, self).clean()
recipients = []
for friend in self.friends:
if data[friend]:
recipients.append(data[friend])
return recipients
def clearsent(self, sentto):
"""
Clear the form of all the emails that are contained in sentto
and repopulate the fields from the top down with the ones that did not
send successfully
"""
again = []
for friend in self.friends:
if self.cleaned_data[friend] not in sentto:
again.append(self.cleaned_data[friend])
<b>self.data[friend] = ''</b>
if len(again):
fields = list(self.friends)
fields.reverse()
for email in again:
self.data[fields.pop()] = email
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---