Add thumbnail images to Appliances grid
guess we'll see how folks like this
This commit is contained in:
parent
4aa8f43a7e
commit
78941ec8d9
30
tailbone/templates/tempmon/appliances/index.mako
Normal file
30
tailbone/templates/tempmon/appliances/index.mako
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
## -*- coding: utf-8; -*-
|
||||||
|
<%inherit file="/master/index.mako" />
|
||||||
|
|
||||||
|
<%def name="extra_styles()">
|
||||||
|
${parent.extra_styles()}
|
||||||
|
<style type="text/css">
|
||||||
|
|
||||||
|
.grid .image-frame {
|
||||||
|
height: 150px;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid .image-helper {
|
||||||
|
display: inline-block;
|
||||||
|
height: 100%;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid img {
|
||||||
|
vertical-align: middle;
|
||||||
|
max-height: 150px;
|
||||||
|
max-width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
${parent.body()}
|
|
@ -106,6 +106,7 @@ class MasterView(View):
|
||||||
executing = False
|
executing = False
|
||||||
has_pk_fields = False
|
has_pk_fields = False
|
||||||
has_image = False
|
has_image = False
|
||||||
|
has_thumbnail = False
|
||||||
|
|
||||||
row_attrs = {}
|
row_attrs = {}
|
||||||
cell_attrs = {}
|
cell_attrs = {}
|
||||||
|
@ -871,6 +872,22 @@ class MasterView(View):
|
||||||
def get_image_bytes(self, obj):
|
def get_image_bytes(self, obj):
|
||||||
raise NotImplementedError
|
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):
|
def clone(self):
|
||||||
"""
|
"""
|
||||||
View for cloning an object's data into a new object.
|
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),
|
config.add_view(cls, attr='image', route_name='{}.image'.format(route_prefix),
|
||||||
permission='{}.view'.format(permission_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
|
# clone
|
||||||
if cls.cloneable:
|
if cls.cloneable:
|
||||||
config.add_tailbone_permission(permission_prefix, '{}.clone'.format(permission_prefix),
|
config.add_tailbone_permission(permission_prefix, '{}.clone'.format(permission_prefix),
|
||||||
|
|
|
@ -49,10 +49,12 @@ class TempmonApplianceView(MasterView):
|
||||||
route_prefix = 'tempmon.appliances'
|
route_prefix = 'tempmon.appliances'
|
||||||
url_prefix = '/tempmon/appliances'
|
url_prefix = '/tempmon/appliances'
|
||||||
has_image = True
|
has_image = True
|
||||||
|
has_thumbnail = True
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'name',
|
'name',
|
||||||
'location',
|
'location',
|
||||||
|
'image',
|
||||||
]
|
]
|
||||||
|
|
||||||
form_fields = [
|
form_fields = [
|
||||||
|
@ -69,6 +71,15 @@ class TempmonApplianceView(MasterView):
|
||||||
g.set_link('name')
|
g.set_link('name')
|
||||||
g.set_link('location')
|
g.set_link('location')
|
||||||
|
|
||||||
|
g.set_renderer('image', self.render_grid_thumbnail)
|
||||||
|
|
||||||
|
def render_grid_thumbnail(self, appliance, field):
|
||||||
|
route_prefix = self.get_route_prefix()
|
||||||
|
url = self.request.route_url('{}.thumbnail'.format(route_prefix), uuid=appliance.uuid)
|
||||||
|
image = tags.image(url, "")
|
||||||
|
helper = HTML.tag('span', class_='image-helper')
|
||||||
|
return HTML.tag('div', class_='image-frame', c=[helper, image])
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(TempmonApplianceView, self).configure_form(f)
|
super(TempmonApplianceView, self).configure_form(f)
|
||||||
|
|
||||||
|
@ -106,6 +117,9 @@ class TempmonApplianceView(MasterView):
|
||||||
def get_image_bytes(self, appliance):
|
def get_image_bytes(self, appliance):
|
||||||
return appliance.image_normal or appliance.image_raw
|
return appliance.image_normal or appliance.image_raw
|
||||||
|
|
||||||
|
def get_thumbnail_bytes(self, appliance):
|
||||||
|
return appliance.image_thumbnail
|
||||||
|
|
||||||
def render_image(self, appliance, field):
|
def render_image(self, appliance, field):
|
||||||
route_prefix = self.get_route_prefix()
|
route_prefix = self.get_route_prefix()
|
||||||
url = self.request.route_url('{}.image'.format(route_prefix), uuid=appliance.uuid)
|
url = self.request.route_url('{}.image'.format(route_prefix), uuid=appliance.uuid)
|
||||||
|
|
Loading…
Reference in a new issue