import pytz

from django.utils import timezone
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _

class TimezoneMiddleware(object):
    def process_request(self, request):
        tzname = request.session.get('django_timezone')

        if tzname:
            timezone.activate(pytz.timezone(tzname))

        elif request.user.is_authenticated():
            try:
                tzname = request.user.timezone
                timezone.activate(pytz.timezone(tzname))
            except Exception as e:
                print('Failed to set timezone', e)
        else:
            timezone.deactivate()


class EnsureCompleteProfileMiddleware(object):
    def process_request(self, request):
        if request.user.is_authenticated():
            skip_urls = [str(reverse_lazy('profile_update', args=[request.user.username]))]
            skip_urls.append('/admin')
            skip_urls.append('/accounts/logout/')

            if not request.user.has_complete_profile() and request.path not in skip_urls:
                messages.info(request, _('Debes completar tu perfil para continuar'))
                return HttpResponseRedirect(skip_urls[0])



@@ -891,16 +891,33 @@
 urls = %5B
+%0A                
 str(reve
@@ -977,10 +977,14 @@
 e%5D))
-%5D%0A
+,%0A    
     
@@ -996,32 +996,91 @@
    s
-kip_urls.append
+tr(reverse_lazy('account_logout')),%0A                str(reverse_lazy
 ('
-/
 admin
-'
+:index')
 )%0A  
@@ -1093,44 +1093,92 @@
     
-skip_urls.append('/accounts/logout/'
+%5D%0A%0A            is_skip_url = any(%5Brequest.path.startswith(url) for url in skip_urls%5D
 )%0A%0A 
@@ -1239,36 +1239,23 @@
 and 
-request.path 
 not i
-n 
+s_
 skip_url
 s:%0A 
@@ -1250,17 +1250,16 @@
 skip_url
-s
 :%0A      

Fix EnsureCompleteProfileMiddleware