summaryrefslogtreecommitdiffstats
path: root/middleware/cancel.py
blob: f03ff35ef2d1ceca45891f905e97a430a306c6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from django.http import HttpResponseRedirect
from django_authopenid.util import get_next_url
import logging
class CancelActionMiddleware(object):
    def process_view(self, request, view_func, view_args, view_kwargs):
        if 'cancel' in request.REQUEST:
            #todo use session messages for the anonymous users
            try:
                msg = getattr(view_func,'CANCEL_MESSAGE')
            except AttributeError:
                msg = 'action canceled'
            request.user.message_set.create(message=msg)
            return HttpResponseRedirect(get_next_url(request))
        else:
            return None