"InterfaceError at /add/" when using 'satchmo_cart_add_verify'

10 views
Skip to first unread message

Thomas

unread,
Apr 26, 2012, 3:52:57 AM4/26/12
to satchm...@googlegroups.com
I get this error when following the example at http://www.satchmoproject.com/docs/dev/signals.html
(I have attached the error log to this post.)
The wording of the error is: "Error binding parameter 1 - probably unsupported type."
What am I doing wrong? I'm pretty sure my code is the same as the example.

Here is my code:

from satchmo_store.shop.exceptions import CartAddProhibited
from django.utils.translation import gettext_lazy as _

class ContactCannotOrder(CartAddProhibited):
    def __init__(self, contact, product, msg):
        super(ContactCannotOrder, self).__init__(product, msg)
        self.contact = contact

def can_user_buy(product, contact=None):
    return False # If I make this 'True' then obviously it works fine.

def veto_if_already_purchased(sender, cartitem=None, added_quantity=0, **kwargs):
    customer = kwargs['cart'].customer
    if can_user_buy(cartitem.product, customer):
        return True
    else:
        msg = _("You have already purchased this.")
        raise ContactCannotOrder(customer, cartitem.product, msg)

In localsite/models.py, I have added the following line:

signals.satchmo_cart_add_verify.connect(veto_if_already_purchased, sender=None)

Many thanks,
Thomas
satchmo-error-log.txt

Thomas

unread,
Apr 26, 2012, 4:55:42 AM4/26/12
to satchm...@googlegroups.com
It seems the error is caused by this line:

  errors = [m for m in get_messages(request) if m.level == constants.ERROR]

That is from the 'get_product()' which I copied from
  src/satchmo/satchmo/apps/product/views/__init__.py

I am baffled. I don't have django's 'message levels' enabled. But why would the original version of get_product() work? where does the ".level" get set ?

Many thanks,
Thomas

hynekcer

unread,
Apr 26, 2012, 4:45:11 PM4/26/12
to Satchmo users
The second error can be probably *temporary* fixed by
getattr(m, 'level', None) instead of m.level in order that you can
continue.

Can you reproduceit in a new project with the only modification
copied from the link above?

--Hynek

(http://www.satchmoproject.com/docs/dev/signals.html)
On 26 dub, 10:55, Thomas <tea.andr...@gmail.com> wrote:
> It seems the error is caused by this line:
>
>   errors = [m for m in get_messages(request) if m.level == constants.ERROR]
>
> That is from the 'get_product()' which I copied from
>   src/satchmo/satchmo/apps/product/views/__init__.py
> .
Reply all
Reply to author
Forward
0 new messages