from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.contrib import messages


class ConfirmProfile(object):

    def process_response(self, request, response):

        my_profile = getattr(request, "my_profile", None)

        if my_profile == None:
            current_path = request.get_full_path()

            # TODO write this cleaner
            paths = ('profile_update', 'logout', )
            valid_path = False
            for path in paths:
                if current_path.startswith(reverse(path)):
                    valid_path = True
            if not valid_path:
                messages.add_message(request, messages.ERROR, "Please fill out your profile.")
                return HttpResponseRedirect(reverse('profile_update'))

        return response

@@ -263,16 +263,85 @@
  None)%0A%0A
+        if request.user.is_anonymous():%0A            return response%0A%0A
         

break the infinite loop in the profile middleware