views:

41

answers:

1

I want to generate a choicelist for all specs that inherit from imagekit.specs.ImageSpec.

The idea is to allow users of the admin interface to select an ImageSpec to add to a picture.

i.e:

class Display(ImageSpec):
    pre_cache = True
    increment_count = True
    processors = [ResizeDisplay,]

class SingleDisplay(ImageSpec):
    pre_cache = True
    increment_count = True
    processors = [SingleDisplayResize]

class Reflection(ImageSpec):
    increment_count = True
    processors = [ResizeDisplay, ReflectionProcessor]

class SingleDisplayReflection(ImageSpec):
    increment_count = True
    processors = [SingleDisplayResize, ReflectionProcessor]

results in a drop-down list "Display, Singledisplay, Reflection, Singledisplayreflection"

+2  A: 

Well, something like the following will get you a list of all the ImageSpec subclasses defined in the file:

def subclassfilter(x, baseclass):
    return x is not baseclass and isinstance(x, type) and issubclass(x, baseclass)

subclasses = [c for c in locals().values() if subclassfilter(c, ImageSpec)]

You could then generate the choices list from the __name__ attribute of each class in the subclasses list.

Will McCutchen
and again I was thinking to complicated :D Thanks!
vikingosegundo