List API now uses the thumbnail image

This commit is contained in:
Oliver Walters 2020-04-05 00:19:37 +11:00
parent afa31b3415
commit 0cfb293ca9
5 changed files with 30 additions and 8 deletions

View File

@ -139,7 +139,7 @@ function loadPartTable(table, url, options={}) {
name = '<i>' + name + '</i>'; name = '<i>' + name + '</i>';
} }
var display = imageHoverIcon(row.image) + renderLink(name, '/part/' + row.pk + '/'); var display = imageHoverIcon(row.thumbnail) + renderLink(name, '/part/' + row.pk + '/');
if (row.is_template) { if (row.is_template) {
display = display + "<span class='label label-info' style='float: right;'>TEMPLATE</span>"; display = display + "<span class='label label-info' style='float: right;'>TEMPLATE</span>";

View File

@ -70,7 +70,7 @@ function loadStockTable(table, options) {
name += row.part__name; name += row.part__name;
return imageHoverIcon(row.part__image) + name + ' <i>(' + data.length + ' items)</i>'; return imageHoverIcon(row.part__thumbnail) + name + ' <i>(' + data.length + ' items)</i>';
} }
else if (field == 'part__description') { else if (field == 'part__description') {
return row.part__description; return row.part__description;
@ -188,7 +188,7 @@ function loadStockTable(table, options) {
name += row.part__revision; name += row.part__revision;
} }
return imageHoverIcon(row.part__image) + renderLink(name, '/part/' + row.part + '/stock/'); return imageHoverIcon(row.part__thumbnail) + renderLink(name, '/part/' + row.part + '/stock/');
} }
}, },
{ {

View File

@ -221,7 +221,17 @@ class PartList(generics.ListCreateAPIView):
for item in data: for item in data:
if item['image']: if item['image']:
item['image'] = os.path.join(settings.MEDIA_URL, item['image']) img = item['image']
# Use the 'thumbnail' image here instead of the full-size image
# Note: The full-size image is used when requesting the /api/part/<x>/ endpoint
fn, ext = os.path.splitext(img)
thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext)
item['thumbnail'] = os.path.join(settings.MEDIA_URL, thumb)
del item['image']
cat_id = item['category'] cat_id = item['category']

View File

@ -47,7 +47,7 @@ class PartBriefSerializer(InvenTreeModelSerializer):
""" Serializer for Part (brief detail) """ """ Serializer for Part (brief detail) """
url = serializers.CharField(source='get_absolute_url', read_only=True) url = serializers.CharField(source='get_absolute_url', read_only=True)
image_url = serializers.CharField(source='get_image_url', read_only=True) image_url = serializers.CharField(source='get_thumbnail_url', read_only=True)
@staticmethod @staticmethod
def setup_eager_loading(queryset): def setup_eager_loading(queryset):
@ -79,7 +79,8 @@ class PartSerializer(InvenTreeModelSerializer):
""" """
url = serializers.CharField(source='get_absolute_url', read_only=True) url = serializers.CharField(source='get_absolute_url', read_only=True)
image_url = serializers.CharField(source='get_image_url', read_only=True) image = serializers.CharField(source='get_image_url', read_only=True)
thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True)
category_name = serializers.CharField(source='category_path', read_only=True) category_name = serializers.CharField(source='category_path', read_only=True)
allocated_stock = serializers.IntegerField(source='allocation_count', read_only=True) allocated_stock = serializers.IntegerField(source='allocation_count', read_only=True)
@ -100,7 +101,8 @@ class PartSerializer(InvenTreeModelSerializer):
'url', # Link to the part detail page 'url', # Link to the part detail page
'category', 'category',
'category_name', 'category_name',
'image_url', 'image',
'thumbnail',
'full_name', 'full_name',
'name', 'name',
'IPN', 'IPN',

View File

@ -337,7 +337,17 @@ class StockList(generics.ListCreateAPIView):
locations = {} locations = {}
for item in data: for item in data:
item['part__image'] = os.path.join(settings.MEDIA_URL, item['part__image'])
img = item['part__image']
# Use the thumbnail image instead
fn, ext = os.path.splitext(img)
thumb = "{fn}.thumbnail{ext}".format(fn=fn, ext=ext)
item['part__thumbnail'] = os.path.join(settings.MEDIA_URL, thumb)
del item['part__image']
loc_id = item['location'] loc_id = item['location']