Hi, I tried to write my first middleware today and seem to have failed horribly.
Basically I have made a view decorator almost identical to the csrf ones, that sets a flag on the view function. My middleware then checks this flag and if missing it runs another function (which deletes some session variables) My middleware looks like: from MySite.cart.checkout.views import _checkout_cleanup class ReleaseOrderMiddleware(object): def process_view(self, request, view_func, view_args, view_kwargs): if getattr(view_func, 'preserve_order_details', False): _checkout_cleanup(request, True) return None If I turn this on I get errors like: ImproperlyConfigured: Error importing middleware MySite.cart.checkout.middleware: "cannot import name exclusive_boolean_fields" Well, exclusive_boolean_fields is a function, basically a decorator I apply to my models. The weird thing is it's not imported directly anywhere in the middleware or _checkout_cleanup function. _checkout_cleanup does do this though: def _checkout_cleanup(request, abort_order): if CHECKOUT_KEY_ORDER in request.session: if abort_order: order = request.session[CHECKOUT_KEY_ORDER] order.restore_stock() order.delivery = Decimal('0.00') order.delivery_label = '' order.status = cart_models.ORDER_STATUS_ABORTED order.fulfillment_status = cart_models.FULFILLMENT_STATUS_ABORTED order.save() del request.session[CHECKOUT_KEY_ORDER] ...so we're working with a model object there. I realise this code doesn't make an easy test case for others, but I'm hoping I have made a basic 'aha!' type of blunder. eg, is it possible to work with model objects at all in the middleware layer? Why would I get that import error? (The _checkout_cleanup method works fine from within a view.) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.