1 from django
import template
2 from django
.utils
.safestring
import mark_safe
3 from django
.utils
.translation
import ugettext
4 from django
.core
.urlresolvers
import reverse
8 from mygpo
.api
.models
import DEVICE_TYPES
9 from mygpo
.web
.views
.device
import show
11 register
= template
.Library()
13 # Create a dictionary of device_type -> caption mappings
14 DEVICE_TYPES_DICT
= dict(DEVICE_TYPES
)
16 # This dictionary maps device types to their icon files
18 'desktop': 'computer.png',
19 'laptop': 'stock_notebook.png',
20 'mobile': 'stock_cell-phone.png',
21 'server': 'server.png',
22 'other': 'audio-x-generic.png',
26 def device_type(device
):
27 return DEVICE_TYPES_DICT
.get(device
.type, _('Unknown'))
30 def device_icon(device
, size
=16):
31 icon
= DEVICE_TYPE_ICONS
.get(device
.type, None)
32 caption
= DEVICE_TYPES_DICT
.get(device
.type, None)
34 if icon
is not None and caption
is not None:
35 caption
= ugettext(caption
)
36 html
= ('<img src="/media/%(size)dx%(size)d/%(icon)s" '+
37 'alt="%(caption)s" class="device_icon"/>') % locals()
38 return mark_safe(html
)
43 def device_list(devices
):
44 return mark_safe('<br/>'.join([ '<a href="%s">%s %s</a>' % (reverse(show
, args
=[d
.id]), device_icon(d
), d
.name
.replace(' ', ' ')) for d
in devices
]))