Closed joesingo closed 5 years ago
First stab. These are changes to tom_base
.
diff --git a/tom_dataproducts/models.py b/tom_dataproducts/models.py
index 66da10d..b8fb096 100644
--- a/tom_dataproducts/models.py
+++ b/tom_dataproducts/models.py
@@ -114,7 +114,7 @@ class DataProduct(models.Model):
def get_preview(self, size=settings.THUMBNAIL_DEFAULT_SIZE, redraw=False):
if self.thumbnail:
- im = Image.open(self.thumbnail)
+ im = Image.open(self.thumbnail.path)
if im.size != settings.THUMBNAIL_DEFAULT_SIZE:
redraw = True
@@ -128,17 +128,25 @@ class DataProduct(models.Model):
self.thumbnail.save(filename, File(f), save=True)
self.save()
tmpfile.close()
- return self.thumbnail.url
+ if self.thumbnail:
+ return self.thumbnail.url
+ return None
def create_thumbnail(self, width=None, height=None):
- if is_fits_image_file(self.data.file.name):
- tmpfile = tempfile.NamedTemporaryFile()
+ tmpfile = tempfile.NamedTemporaryFile()
+
+ if self.tag == IMAGE_FILE[0]:
+ im = Image.open(self.data.path)
+ fmt = os.path.splitext(self.data.path)[-1][1:]
+ im.resize((width, height)).save(tmpfile, format=fmt)
+ elif is_fits_image_file(self.data.file.name):
if not width or not height:
width, height = find_img_size(self.data.file.name)
resp = fits_to_jpg(self.data.file.name, tmpfile.name, width=width, height=height)
- if resp:
- return tmpfile
- return
+ # TODO: what happens in this case?
+ # if resp:
+ # return tmpfile
+ return tmpfile
class ReducedDatum(models.Model):
diff --git a/tom_dataproducts/templates/tom_dataproducts/dataproduct_list.html b/tom_dataproducts/templates/tom_dataproducts/dataproduct_list.html
index b367dbe..c4c3816 100644
--- a/tom_dataproducts/templates/tom_dataproducts/dataproduct_list.html
+++ b/tom_dataproducts/templates/tom_dataproducts/dataproduct_list.html
@@ -44,7 +44,7 @@
{{ product.get_tag_display }}
{% endif %}
</a></td>
- {% if product.get_file_extension == '.fz' or product.get_file_extension == '.fits' %}
+ {% if product.get_file_extension == '.fz' or product.get_file_extension == '.fits' or product.tag == 'image_file' %}
<td>
{% cache None thumbnail product.id %}
<img src="{{ product.get_preview }}" class="thumbnail"><br/>
diff --git a/tom_targets/models.py b/tom_targets/models.py
index f623bba..6b5d9c8 100644
--- a/tom_targets/models.py
+++ b/tom_targets/models.py
@@ -156,7 +156,8 @@ class Target(models.Model):
return reverse('targets:detail', kwargs={'pk': self.id})
def featured_image(self):
- return self.dataproduct_set.filter(tag='fits_file', featured=True).first()
+ image_types = ('fits_file', 'image_file')
+ return self.dataproduct_set.filter(tag__in=image_types, featured=True).first()
def light_curve(self):
return self.dataproduct_set.reduceddatum_set.filter(data_type='photometry').all()
diff --git a/tom_targets/templates/tom_targets/partials/target_feature.html b/tom_targets/templates/tom_targets/partials/target_feature.html
index 3153940..d849f88 100644
--- a/tom_targets/templates/tom_targets/partials/target_feature.html
+++ b/tom_targets/templates/tom_targets/partials/target_feature.html
@@ -1,6 +1,6 @@
{% load cache %}
<h3>{{ target.identifier }}</h3>
-{% if target.featured_image %}
+{% if target.featured_image and target.featured_image.get_preview %}
{% cache None featured_image target.id %}
<img src="{{ target.featured_image.get_preview }}" id="featured-image" onerror="this.style.display='none'">
{% endcache %}
Above patch is in this branch: https://github.com/joesingo/tom_base/tree/featured-timelapses
Problems:
/dataproducts/data/
page with MP4Closing: tom_base
needs too many changes
Need to allow timelapses to be 'featured', and show them in the featured image section on the target detail page.