1 from django
import template
2 from django
.utils
.safestring
import mark_safe
3 from django
.utils
.translation
import ugettext
7 from mygpo
.api
.models
import DEVICE_TYPES
9 register
= template
.Library()
11 # Create a dictionary of device_type -> caption mappings
12 DEVICE_TYPES_DICT
= dict(DEVICE_TYPES
)
14 # This dictionary maps device types to their icon files
16 'desktop': 'computer.png',
17 'laptop': 'stock_notebook.png',
18 'mobile': 'stock_cell-phone.png',
19 'server': 'server.png',
20 'other': 'audio-x-generic.png',
24 def device_type(device
):
25 return DEVICE_TYPES_DICT
.get(device
.type, _('Unknown'))
28 def device_icon(device
, size
=16):
29 icon
= DEVICE_TYPE_ICONS
.get(device
.type, None)
30 caption
= DEVICE_TYPES_DICT
.get(device
.type, None)
32 if icon
is not None and caption
is not None:
33 caption
= ugettext(caption
)
34 html
= ('<img src="/media/%(size)dx%(size)d/%(icon)s" '+
35 'alt="%(caption)s" class="device_icon"/>') % locals()
36 return mark_safe(html
)
41 def device_list(devices
):
42 return mark_safe('<br/>'.join([ '<a href="/device/%s">%s %s</a>' % (d
.id, device_icon(d
), d
.name
.replace(' ', ' ')) for d
in devices
]))