diff options
Diffstat (limited to 'middleware')
-rw-r--r-- | middleware/__init__.py | 0 | ||||
-rw-r--r-- | middleware/anon_user.py | 34 | ||||
-rw-r--r-- | middleware/cancel.py | 15 | ||||
-rw-r--r-- | middleware/pagesize.py | 33 |
4 files changed, 0 insertions, 82 deletions
diff --git a/middleware/__init__.py b/middleware/__init__.py deleted file mode 100644 index e69de29b..00000000 --- a/middleware/__init__.py +++ /dev/null diff --git a/middleware/anon_user.py b/middleware/anon_user.py deleted file mode 100644 index fa2686f0..00000000 --- a/middleware/anon_user.py +++ /dev/null @@ -1,34 +0,0 @@ -from django.http import HttpResponseRedirect -from utils.forms import get_next_url -from django.utils.translation import ugettext as _ -from user_messages import create_message, get_and_delete_messages -from django.conf import settings -import logging - -class AnonymousMessageManager(object): - def __init__(self,request): - self.request = request - def create(self,message=''): - create_message(self.request,message) - def get_and_delete(self): - messages = get_and_delete_messages(self.request) - return messages - -def dummy_deepcopy(*arg): - """this is necessary to prevent deepcopy() on anonymous user object - that now contains reference to request, which cannot be deepcopied - """ - return None - -class ConnectToSessionMessagesMiddleware(object): - def process_request(self, request): - if not request.user.is_authenticated(): - request.user.__deepcopy__ = dummy_deepcopy #plug on deepcopy which may be called by django db "driver" - request.user.message_set = AnonymousMessageManager(request) #here request is linked to anon user - request.user.get_and_delete_messages = request.user.message_set.get_and_delete - - #also set the first greeting one time per session only - if 'greeting_set' not in request.session: - request.session['greeting_set'] = True - msg = _('first time greeting with %(url)s') % {'url':settings.GREETING_URL} - request.user.message_set.create(message=msg) diff --git a/middleware/cancel.py b/middleware/cancel.py deleted file mode 100644 index 51e1b253..00000000 --- a/middleware/cancel.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.http import HttpResponseRedirect -from utils.forms 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 diff --git a/middleware/pagesize.py b/middleware/pagesize.py deleted file mode 100644 index f6e6fcfd..00000000 --- a/middleware/pagesize.py +++ /dev/null @@ -1,33 +0,0 @@ -# used in questions -QUESTIONS_PAGE_SIZE = 10 -class QuestionsPageSizeMiddleware(object): - def process_request(self, request): - # Set flag to False by default. If it is equal to True, then need to be saved. - pagesize_changed = False - # get pagesize from session, if failed then get default value - user_page_size = request.session.get("pagesize", QUESTIONS_PAGE_SIZE) - # set pagesize equal to logon user specified value in database - if request.user.is_authenticated() and request.user.questions_per_page > 0: - user_page_size = request.user.questions_per_page - - try: - # get new pagesize from UI selection - pagesize = int(request.GET.get('pagesize', user_page_size)) - if pagesize <> user_page_size: - pagesize_changed = True - - except ValueError: - pagesize = user_page_size - - # save this pagesize to user database - if pagesize_changed: - if request.user.is_authenticated(): - user = request.user - user.questions_per_page = pagesize - user.save() - # put pagesize into session - request.session["pagesize"] = pagesize - - def process_exception(self,request,exception): - import logging - logging.debug('have exception %s' % str(exception)) |