chrisspen/django-chroniker

Error when calling change_form to add a job

Closed this issue · 1 comments

I use the custom admin skin django-suit.
There the view button is not hidden when adding a job. So this method is called anyway:

admin.py: lines 225-230:

def view_logs_button(self, obj):
    q = obj.logs.all()
    url = get_admin_changelist_url(Log)
    return ('<a href="%s?job=%d" target="_blank">'
        '<input type="button" value="View %i" /></a>') % \
        (url, obj.id, q.count())

That causes the error

%d format: a number is required, not NoneType

because obj.id is not set yet.
Is it possible to change it to

def view_logs_button(self, obj):
    if obj.id:
        q = obj.logs.all()
        url = get_admin_changelist_url(Log)
        return ('<a href="%s?job=%d" target="_blank">'
            '<input type="button" value="View %i" /></a>') % \
            (url, obj.id, q.count())
    else:
            return ''

?

I'd argue this is a failing of django-suit, as internal errors should be hidden from the user, especially on production. That said, I have no problem adding a simple check for this specific case. I've committed the change.