put all of the otherwise duplicative code into its own function within
another module. then import that function into your views.py, i.e:

at the top of views.py:
from formprocessing.py import formprocessor

then within formproccessor.py

def processemail(email, reference_name):
           subject = 'Your suggestion has been received.'
           message = "Thank you for suggesting %s to us. We'll review
your suggestion and get back to you as quickly as possible." %
(reference_name)

           send_mail(subject, message, email,
'[EMAIL PROTECTED]')

and of course in the view:
       if form.is_valid():
           first_name = form.cleaned_data['first_name']
           last_name = form.cleaned_data['last_name']
           email = form.cleaned_data['email']
           reference_name = form.cleaned_data['reference_name']
           url = form.cleaned_data['url']

           processemail(email, reference_name):

           request.session['first_name'] = first_name
           return HttpResponseRedirect('/articles-and-books/thanks/')


you could have it do all of the form processing if you need it too, just
depends on what you need.
-richard


On 6/20/08, Brandon Taylor <[EMAIL PROTECTED]> wrote:
>
>
> Hi everyone,
>
> I have a feedback form which needs to be functional across 3 different
> actions within the same view...
>
> My actions are:
>    references_list
>    reference_detail
>    thanks
>
> Here's my current form processing code:
>
> if request.method == 'POST':
>        form = SuggestionForm(request.POST)
>
>        if form.is_valid():
>            first_name = form.cleaned_data['first_name']
>            last_name = form.cleaned_data['last_name']
>            email = form.cleaned_data['email']
>            reference_name = form.cleaned_data['reference_name']
>            url = form.cleaned_data['url']
>
>            subject = 'Your suggestion has been received.'
>            message = "Thank you for suggesting %s to us. We'll review
> your suggestion and get back to you as quickly as possible." %
> (reference_name)
>
>            send_mail(subject, message, email,
> '[EMAIL PROTECTED]')
>            request.session['first_name'] = first_name
>            return HttpResponseRedirect('/articles-and-books/thanks/')
>    else:
>        form = SuggestionForm()
>
>
> How can I structure this such that I don't have to repeat myself in
> each action of the view?
>
> TIA,
> Brandon
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to