from imagekit import ImageSpec, register
from imagekit.processors import ResizeToFit

from spectator.core import app_settings


class Thumbnail(ImageSpec):
    "Base class"
    format = "JPEG"
    options = {"quality": 60}


class ListThumbnail(Thumbnail):
    "For displaying in lists of Publications, Events, etc."
    processors = [ResizeToFit(*app_settings.LIST_THUMBNAIL_SIZE)]


register.generator("spectator:list_thumbnail", ListThumbnail)


class ListThumbnail2x(ListThumbnail):
    "Retina version of ListThumbnail"
    dimensions = [x * 2 for x in app_settings.LIST_THUMBNAIL_SIZE]
    processors = [ResizeToFit(*dimensions)]


register.generator("spectator:list_thumbnail2x", ListThumbnail2x)


class DetailThumbnail(Thumbnail):
    "For displaying on the detail pages of Publication, Event, etc"
    processors = [ResizeToFit(*app_settings.DETAIL_THUMBNAIL_SIZE)]


register.generator("spectator:detail_thumbnail", DetailThumbnail)


class DetailThumbnail2x(DetailThumbnail):
    "Retina version of DetailThumbnail"
    dimensions = [x * 2 for x in app_settings.DETAIL_THUMBNAIL_SIZE]
    processors = [ResizeToFit(*dimensions)]


register.generator("spectator:detail_thumbnail2x", DetailThumbnail2x)

@@ -382,72 +382,8 @@
 %5D%0A%0A%0A
-register.generator(%22spectator:list_thumbnail%22, ListThumbnail)%0A%0A%0A
 clas
@@ -412,32 +412,34 @@
 Thumbnail):%0A    
+%22%22
 %22Retina version 
@@ -446,33 +446,93 @@
 of ListThumbnail
-%22
+%0A    Generated twice the size of our set dimensions.%0A    %22%22%22%0A
 %0A    dimensions 
@@ -526,33 +526,33 @@
   dimensions = %5B
-x
+d
  * 2 for x in ap
@@ -536,33 +536,33 @@
 ns = %5Bd * 2 for 
-x
+d
  in app_settings
@@ -633,76 +633,8 @@
 %5D%0A%0A%0A
-register.generator(%22spectator:list_thumbnail2x%22, ListThumbnail2x)%0A%0A%0A
 clas
@@ -805,76 +805,8 @@
 %5D%0A%0A%0A
-register.generator(%22spectator:detail_thumbnail%22, DetailThumbnail)%0A%0A%0A
 clas
@@ -847,16 +847,18 @@
 l):%0A    
+%22%22
 %22Retina 
@@ -883,17 +883,77 @@
 humbnail
-%22
+%0A    Generated twice the size of our set dimensions.%0A    %22%22%22%0A
 %0A    dim
@@ -963,17 +963,17 @@
 ions = %5B
-x
+d
  * 2 for
@@ -973,17 +973,17 @@
 * 2 for 
-x
+d
  in app_
@@ -1060,16 +1060,210 @@
 ons)%5D%0A%0A%0A
+register.generator(%22spectator:list_thumbnail%22, ListThumbnail)%0Aregister.generator(%22spectator:list_thumbnail2x%22, ListThumbnail2x)%0Aregister.generator(%22spectator:detail_thumbnail%22, DetailThumbnail)%0A
 register

Tidy file