Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace status fields with icons #9

Open
mridang opened this issue Oct 19, 2012 · 0 comments
Open

Replace status fields with icons #9

mridang opened this issue Oct 19, 2012 · 0 comments

Comments

@mridang
Copy link

mridang commented Oct 19, 2012

I've currently monkey-patches all the admin classes for Overseer but it would be nice to see icons for the — "No Problems", "Some Issues" and "Unavailable" statuses. Django already includes these icons. Here's my code of how I accomplished this:

from overseer.models import *
from overseer.admin import *

admin.site.unregister(Service)

class ModdedServiceAdmin(ServiceAdmin):
    """
    Modified service administration with icon support
    """
    list_display = ('name', 'state', 'order', 'date_updated')

    def state(self, obj):
        """
        Returns an icon depending upon the status
        """
        if obj.status == 0:
            return '<img alt="Working" style="height: 11.5px;" src="/media/img/admin/icon_success.gif">'
        if obj.status == 1:
            return '<img alt="Errors" style="height: 11.5px;" src="/media/img/admin/icon_alert.gif">'
        if obj.status == 2:
            return '<img alt="Unavailable" style="height: 11.5px;"  src="/media/img/admin/icon_error.gif">'
    state.allow_tags=True

admin.site.register(Service, ModdedServiceAdmin)

admin.site.unregister(Event)

class ModdedEventAdmin(EventAdmin):
    """
    Modified event administration with icon support
    """
    list_display = ('date_created', 'description', 'state', 'date_updated')

    def state(self, obj):
        """
        Returns an icon depending upon the status
        """
        if obj.status == 0:
            return '<img alt="Working" style="height: 11.5px;" src="/media/img/admin/icon_success.gif">'
        if obj.status == 1:
            return '<img alt="Errors" style="height: 11.5px;" src="/media/img/admin/icon_alert.gif">'
        if obj.status == 2:
            return '<img alt="Unavailable" style="height: 11.5px;"  src="/media/img/admin/icon_error.gif">'
    state.allow_tags=True

admin.site.register(Event, ModdedEventAdmin)

admin.site.unregister(EventUpdate)

class ModdedEventUpdateAdmin(EventUpdateAdmin):
    """
    Modified event-update administration with icon support
    """
    list_display = ('date_created', 'message', 'state', 'event')

    def state(self, obj):
        """
        Returns an icon depending upon the status
        """
        if obj.status == 0:
            return '<img alt="Working" style="height: 11.5px;" src="/media/img/admin/icon_success.gif">'
        if obj.status == 1:
            return '<img alt="Errors" style="height: 11.5px;" src="/media/img/admin/icon_alert.gif">'
        if obj.status == 2:
            return '<img alt="Unavailable" style="height: 11.5px;"  src="/media/img/admin/icon_error.gif">'
    state.allow_tags=True

admin.site.register(EventUpdate, ModdedEventUpdateAdmin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant