On Tue, Jul 7, 2009 at 5:45 AM, Newt <[email protected]> wrote:

>
> Hello,
>
> I'm kinda newbie, is there any way how to add optional organization
> form to the checkout form?
> I can't find way way to do this, but to hardcode it into corresponding
> view, is there any simpler way?
>
> I'm using satchmo 0.81
>
> Thnaks, Ales


If you were using the trunk version, you could do this by connecting to
three listeners.

Something like this (rough, untested, but 90% there):

from payment.signals import payment_form_init
from payment.forms import PaymentContactInfoForm
from satchmo_store.contact.signals import form_save
from satchmo_utils.signals import form_initialdata

def org_initialdata_listener(sender, init_data={}, contact=None, **kwargs):
    """Populate the initial data for the form."""
    if contact and contact.organization:
        org = contact.organization.name
    else:
        org = ""
    init_data['organization'] = org

def org_view_listener(sender, form=None, **kwargs):
    """Adds an org textfield to the form"""

    form.fields['organization'] = forms.TextField(
        label=_('Your Organization'),
        required=False)

def org_save_listener(sender, object=None, formdata=None, form=None,
**kwargs):
    """Add org to contact on form save"""
    orgname = formdata['organization']

    org = None
    if object and object.organization:
        org = object.organization
        if org.name != orgname:
            org = None

    if not org:
        org = Organization.objects.create(name=orgname)
        contact.org = org
        contact.save()

def start_listening():
    form_initialdata.connect(org_initialdata_listener,
sender=PaymentContactInfoForm)
    payment_form_init.connect(org_view_listener,
sender=PaymentContactInfoForm)
    form_save.connect(org_save_listener, sender=PaymentContactInfoForm)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Satchmo 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/satchmo-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to