# Path: eulcommon/djangoextras/taskresult/models.py
# class TaskResult(models.Model):
#     label = models.CharField(max_length=100)
#     object_id = models.CharField(max_length=50)
#     url = models.URLField()
#     created = models.DateTimeField(auto_now_add=True)
#     task_id = models.CharField(max_length=100)
#     task_start = models.DateTimeField(blank=True, null=True)
#     task_end = models.DateTimeField(blank=True, null=True)
# 
#     @property
#     def task(self):
#         return AsyncResult(self.task_id)
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def duration(self):
#         if self.task_end and self.task_start:
#             return self.task_end - self.task_start
#         else:
#             return '-'
# 
#     @property
#     def status(self):
#         return self.task.status
# 
#     @property
#     def result(self):
#         return self.task.result or ''
# 
#     # use font-awesome icons for short-hand status display?
#     unknown_icon = 'glyphicon-question-sign'
#     status_icon_map = {
#         'pending': 'glyphicon-time',
#         'success': 'glyphicon-ok',
#         'failure': 'glyphicon-remove',
#         # 'failure': 'glyphicon-alert',  # doesn't display in keep; version?
#         '': unknown_icon
#     }
#     status_style = {
#         'pending': 'text-muted',
#         'success': 'text-success',
#         'failure': 'text-danger',
#         '': 'text-warning',
#     }
# 
#     def status_icon(self):
#         'glyphicon for task status; requires bootstrap'
#         icon = self.status_icon_map.get(self.status.lower(),
#                                         self.unknown_icon)
#         style = self.status_style.get(self.status.lower(), '')
#         return mark_safe(
#             '<span class="glyphicon %s %s" aria-hidden="true"></span>' %
#             (icon, style))
#     status_icon.short_description = 'Status'


from django.contrib import admin
from .models import TaskResult

class TaskResultAdmin(admin.ModelAdmin):
    list_display = ('object_id', 'status_icon', 'label', 'created',
                    'duration', 'result')
    search_fields = ('object_id', 'label', 'result')
    list_filter = ('created', )

    # disallow creating task results via admin site
    def has_add_permission(self, request):
        return False


# Path: eulcommon/djangoextras/taskresult/models.py
# class TaskResult(models.Model):
#     label = models.CharField(max_length=100)
#     object_id = models.CharField(max_length=50)
#     url = models.URLField()
#     created = models.DateTimeField(auto_now_add=True)
#     task_id = models.CharField(max_length=100)
#     task_start = models.DateTimeField(blank=True, null=True)
#     task_end = models.DateTimeField(blank=True, null=True)
# 
#     @property
#     def task(self):
#         return AsyncResult(self.task_id)
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def duration(self):
#         if self.task_end and self.task_start:
#             return self.task_end - self.task_start
#         else:
#             return '-'
# 
#     @property
#     def status(self):
#         return self.task.status
# 
#     @property
#     def result(self):
#         return self.task.result or ''
# 
#     # use font-awesome icons for short-hand status display?
#     unknown_icon = 'glyphicon-question-sign'
#     status_icon_map = {
#         'pending': 'glyphicon-time',
#         'success': 'glyphicon-ok',
#         'failure': 'glyphicon-remove',
#         # 'failure': 'glyphicon-alert',  # doesn't display in keep; version?
#         '': unknown_icon
#     }
#     status_style = {
#         'pending': 'text-muted',
#         'success': 'text-success',
#         'failure': 'text-danger',
#         '': 'text-warning',
#     }
# 
#     def status_icon(self):
#         'glyphicon for task status; requires bootstrap'
#         icon = self.status_icon_map.get(self.status.lower(),
#                                         self.unknown_icon)
#         style = self.status_style.get(self.status.lower(), '')
#         return mark_safe(
#             '<span class="glyphicon %s %s" aria-hidden="true"></span>' %
#             (icon, style))
#     status_icon.short_description = 'Status'


# Path: eulcommon/djangoextras/taskresult/admin.py
from django.contrib import admin
from .models import TaskResult


class TaskResultAdmin(admin.ModelAdmin):
    list_display = ('object_id', 'status_icon', 'label', 'created',
                    'duration', 'result')
    search_fields = ('object_id', 'label', 'result')
    list_filter = ('created', )

    # disallow creating task results via admin site
    def has_add_permission(self, request):
        return False


admin.site.register(TaskResult, TaskResultAdmin)