Add thumbnail images to Appliances grid

guess we'll see how folks like this
This commit is contained in:
Lance Edgar 2018-10-19 19:47:00 -05:00
parent 4aa8f43a7e
commit 78941ec8d9
3 changed files with 67 additions and 0 deletions

View file

@ -106,6 +106,7 @@ class MasterView(View):
executing = False
has_pk_fields = False
has_image = False
has_thumbnail = False
row_attrs = {}
cell_attrs = {}
@ -871,6 +872,22 @@ class MasterView(View):
def get_image_bytes(self, obj):
raise NotImplementedError
def thumbnail(self):
"""
View which renders the object's thumbnail image as a response.
"""
obj = self.get_instance()
image_bytes = self.get_thumbnail_bytes(obj)
if not image_bytes:
raise self.notfound()
# TODO: how to properly detect image type?
self.request.response.content_type = str('image/jpeg')
self.request.response.body = image_bytes
return self.request.response
def get_thumbnail_bytes(self, obj):
raise NotImplementedError
def clone(self):
"""
View for cloning an object's data into a new object.
@ -3002,6 +3019,12 @@ class MasterView(View):
config.add_view(cls, attr='image', route_name='{}.image'.format(route_prefix),
permission='{}.view'.format(permission_prefix))
# thumbnail
if cls.has_thumbnail:
config.add_route('{}.thumbnail'.format(route_prefix), '{}/{{{}}}/thumbnail'.format(url_prefix, model_key))
config.add_view(cls, attr='thumbnail', route_name='{}.thumbnail'.format(route_prefix),
permission='{}.view'.format(permission_prefix))
# clone
if cls.cloneable:
config.add_tailbone_permission(permission_prefix, '{}.clone'.format(permission_prefix),