Display supplier logo in part suppliers list

- Also add a background colour for popup image in case of transparent image file
This commit is contained in:
Oliver Walters 2019-05-08 20:23:54 +10:00
parent 0754afd5f5
commit 58e5b10d26
4 changed files with 14 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import os
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.conf import settings
def rename_company_image(instance, filename): def rename_company_image(instance, filename):
@ -78,6 +79,14 @@ class Company(models.Model):
""" Get the web URL for the detail view for this Company """ """ Get the web URL for the detail view for this Company """
return reverse('company-detail', kwargs={'pk': self.id}) return reverse('company-detail', kwargs={'pk': self.id})
def get_image_url(self):
""" Return the URL of the image for this company """
if self.image:
return os.path.join(settings.MEDIA_URL, str(self.image.url))
else:
return ''
@property @property
def part_count(self): def part_count(self):
""" The number of parts supplied by this company """ """ The number of parts supplied by this company """

View File

@ -128,6 +128,7 @@ class SupplierPartSerializer(serializers.ModelSerializer):
part_detail = PartBriefSerializer(source='part', many=False, read_only=True) part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
supplier_name = serializers.CharField(source='supplier.name', read_only=True) supplier_name = serializers.CharField(source='supplier.name', read_only=True)
supplier_logo = serializers.CharField(source='supplier.get_image_url', read_only=True)
class Meta: class Meta:
model = SupplierPart model = SupplierPart
@ -138,6 +139,7 @@ class SupplierPartSerializer(serializers.ModelSerializer):
'part_detail', 'part_detail',
'supplier', 'supplier',
'supplier_name', 'supplier_name',
'supplier_logo',
'SKU', 'SKU',
'manufacturer', 'manufacturer',
'MPN', 'MPN',

View File

@ -63,7 +63,7 @@
field: 'supplier_name', field: 'supplier_name',
title: 'Supplier', title: 'Supplier',
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
return renderLink(value, '/company/' + row.supplier + '/'); return imageHoverIcon(row.supplier_logo) + renderLink(value, '/company/' + row.supplier + '/');
} }
}, },
{ {

View File

@ -13,12 +13,14 @@
/* Part image icons with full-display on mouse hover */ /* Part image icons with full-display on mouse hover */
.hover-img-thumb { .hover-img-thumb {
background: #eee;
width: 28px; width: 28px;
height: 28px; height: 28px;
border: 1px solid #cce; border: 1px solid #cce;
} }
.hover-img-large { .hover-img-large {
background: #eee;
display: none; display: none;
position: absolute; position: absolute;
z-index: 999; z-index: 999;