Ticket #7553: 7553-sites-decorators-ref.diff

File 7553-sites-decorators-ref.diff, 3.6 KB (added by Michael Newman, 16 years ago)

Another way to fix this problem using refactored code, without a try and except. Still not the cleanest.

  • django/views/decorators/cache.py

     
    4242    """
    4343    def _wrapped_view_func(request, *args, **kwargs):
    4444        response = view_func(request, *args, **kwargs)
    45         # Although rare, it is possible for a view to return None (e.g. the
    46         # django.contrib.admin.sites.AdminSite.login view in one corner-case)
    47         if response:
    48             add_never_cache_headers(response)
     45        add_never_cache_headers(response)
    4946        return response
    5047    return wraps(view_func)(_wrapped_view_func)
  • django/contrib/admin/sites.py

     
    7171            model_or_iterable = [model_or_iterable]
    7272        for model in model_or_iterable:
    7373            if model in self._registry:
    74                 raise AlreadyRegistered('The model %s is already registered' % model.__name__)
     74                raise AlreadyRegistered, _('The model %s is already registered') % model.__name__
    7575            self._registry[model] = admin_class(model, self)
    7676
    7777    def unregister(self, model_or_iterable):
     
    8484            model_or_iterable = [model_or_iterable]
    8585        for model in model_or_iterable:
    8686            if model not in self._registry:
    87                 raise NotRegistered('The model %s is not registered' % model.__name__)
     87                raise NotRegistered, _('The model %s is not registered') % model.__name__
    8888            del self._registry[model]
    8989
    9090    def has_permission(self, request):
     
    111111        # The 'logout' view doesn't require that the person is logged in.
    112112        if url == 'logout':
    113113            return self.logout(request)
    114 
     114       
     115        # Check for permission or show login form
    115116        if not self.has_permission(request):
    116             response = self.login(request)
    117             if response:
    118                 # make sure that there is a response before returning
    119                 # this addresses any post data that might persist from
    120                 # expired sessions and continue through (#5999)
    121                 return response
     117            return self.login(request)
    122118
    123119        if url == '':
    124120            return self.index(request)
     
    244240
    245241        # The user data is correct; log in the user in and continue.
    246242        else:
    247             if user.is_active and user.is_staff:
     243            if user.is_authenticated() and user.is_staff:
    248244                login(request, user)
    249245                # TODO: set last_login with an event.
    250246                user.last_login = datetime.datetime.now()
    251247                user.save()
    252248                if request.POST.has_key('post_data'):
     249                    request.session.delete_test_cookie()
    253250                    post_data = _decode_post_data(request.POST['post_data'])
    254251                    if post_data and not post_data.has_key(LOGIN_FORM_KEY):
    255252                        # overwrite request.POST with the saved post_data, and continue
    256253                        request.POST = post_data
    257254                        request.user = user
    258                         return None
     255                        return self.root(request, request.path.split(self.root_path)[-1])
    259256                    else:
    260                         request.session.delete_test_cookie()
    261257                        return http.HttpResponseRedirect(request.path)
    262258            else:
    263259                return self.display_login_form(request, ERROR_MESSAGE)
Back to Top