def render(self, name, value, attrs=None, choices=()): dev = None if value: try: dev = Device.objects.get(sn=(value or '').lower()) except Device.DoesNotExist: pass if dev is None: output = [ '<input type="hidden" name="%s" value="">' % (escape(name),), '<div class="input uneditable-input">', '<i class="fugue-icon %s"></i> %s</a>' % ( presentation.get_device_icon(None), 'None'), '</div>', ] else: output = [ '<input type="hidden" name="%s" value="%s">' % (escape(name), escape(value)), '<div class="input uneditable-input">', '<a href="/ui/racks/%s/info/">' '<i class="fugue-icon %s"></i> %s</a>' % (slugify(dev.sn), presentation.get_device_icon(dev), escape(dev.name)), '</div>', ] return mark_safe('\n'.join(output))
def render(self, name, value, attrs=None, choices=()): dev = None if value: try: dev = Device.objects.get(id=value) except Device.DoesNotExist: pass if dev is None: output = [ '<input type="hidden" name="%s" value="">' % (escape(name), ), '<div class="input uneditable-input">', '<i class="fugue-icon %s"></i> %s</a>' % (presentation.get_device_icon(None), 'None'), '</div>', ] else: output = [ '<input type="hidden" name="%s" value="%s">' % (escape(name), escape(value)), '<div class="input uneditable-input">', '<a href="%s">' '<i class="fugue-icon %s"></i> %s</a>' % (dev.id, presentation.get_device_icon(dev), escape(dev.name)), '</div>', ] return mark_safe('\n'.join(output))
def render(self, name, value, attrs=None, choices=()): dev = None if value: try: dev = Device.objects.get(id=value) except Device.DoesNotExist: pass if dev is None: output = [ '<input type="hidden" name="%s" value="">' % (name,), '<div class="input uneditable-input">', '<i class="fugue-icon %s"></i> %s</a>' % ( presentation.get_device_icon(None), 'None'), '</div>', ] else: output = [ '<input type="hidden" name="%s" value="%s">' % (name, value), '<div class="input uneditable-input">', '<a href="%s">' '<i class="fugue-icon %s"></i> %s</a>' % (dev.id, presentation.get_device_icon(dev), dev.name), '</div>', ] return mark_safe('\n'.join(output))
def get_icon_for(ci): if not ci or not ci.content_object: return if ci.content_type.name == 'venture': return get_venture_icon(ci.content_object) elif ci.content_type.name == 'device': return get_device_icon(ci.content_object) elif ci.content_type.name == 'network': return get_network_icon(ci.content_object)
def get_icon_for(ci): if not ci or not ci.content_object: return if ci.content_type.name == "venture": return get_venture_icon(ci.content_object) elif ci.content_type.name == "device": return get_device_icon(ci.content_object) elif ci.content_type.name == "network": return get_network_icon(ci.content_object)
def _prices_per_venture_device_details(device, exclude=[]): components, stock = [], [] total = 0 for detail in _get_details( device, ignore_deprecation=True, exclude=exclude, ): model = detail.get('model') price = detail.get('price') or 0 if not model: components.append({ 'model': 'n/a', 'icon': 'n/a', 'count': 'n/a', 'price': 'n/a', 'serial': 'n/a', }) if model not in stock: components.append({ 'model': model.name if hasattr(model, 'name') else model, 'icon': detail.get('icon'), 'count': 1, 'price': price, 'serial': detail.get('serial'), }) else: for component in components: if component['model'] == model: component['count'] = component['count'] + 1 total += price stock.append(model) venture = 'N/a' if device.venture and device.venture.symbol: venture = device.venture.symbol return { 'device': { 'id': device.id, 'name': device.name, 'sn': device.sn, 'barcode': device.barcode, 'deprecation_date': device.deprecation_date, 'cached_price': device.cached_price, 'icon': get_device_icon(device), 'venture': venture, 'role': device.role or 'N/a', }, 'components': components, 'total': total, 'deprecated': device.is_deprecated(), }
def format_item_display(self, obj): return '<i class="fugue-icon %s"></i> %s <div><small>%s</small></div>' % ( presentation.get_device_icon(obj), escape(obj.name), escape(obj.venture) + '/' + escape(obj.venture_role), )
def device_icon(device): return icon_filter(presentation.get_device_icon(device))