#8110: Admin interface: 'long' object has no attribute 'isdigit'
-------------------------------------------+--------------------------------
          Reporter:  anonymous             |         Owner:  nobody
            Status:  reopened              |     Milestone:  1.0   
         Component:  django.contrib.admin  |       Version:  1.0   
        Resolution:                        |      Keywords:        
             Stage:  Accepted              |     Has_patch:  1     
        Needs_docs:  0                     |   Needs_tests:  0     
Needs_better_patch:  0                     |  
-------------------------------------------+--------------------------------
Comment (by nekron):

 I did today evening some debugging and found a bugfix / workaround for
 this behaviour.

 Original file: django/contrib/admin/templatetags/log.py
 {{{
    def render(self, context):
         if self.user is None:
             context[self.varname] =
 LogEntry.objects.all().select_related()[:self.limit]
         else:
             if not self.user.isdigit():
                 self.user = context[self.user].id
             context[self.varname] =
 
LogEntry.objects.filter(user__id__exact=self.user).select_related()[:self.limit]
         return ''
 }}}

 Look at the line "if not self.user.isdigit()". We assume that self.user
 must be an unicode string containing a digit value. If this is not the
 case we get the current user id from the context dictionary and save it as
 self.user. And now here it happends that we get the id which is an integer
 value and no string. So we ovwerwrite the current string with an integer.
 The next time the render method is called we try to call isdigit() on an
 integer object which crashes the admin interface (error 500). What I did
 to fix this is that I put str(..) around the context[self.user].id. So I
 make sure that self.user is a string, however containing an integer values
 so isdigit() will become true.

 Fixed render method looks like:
 {{{
    def render(self, context):
         if self.user is None:
             context[self.varname] =
 LogEntry.objects.all().select_related()[:self.limit]
         else:
             if not self.user.isdigit():
                 self.user = str(context[self.user].id)
             context[self.varname] =
 
LogEntry.objects.filter(user__id__exact=self.user).select_related()[:self.limit]
         return ''
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8110#comment:21>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to