Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_thumbnail doesn't work on ImageSubset #43

Open
picakoch opened this issue Jul 21, 2017 · 1 comment
Open

find_thumbnail doesn't work on ImageSubset #43

picakoch opened this issue Jul 21, 2017 · 1 comment

Comments

@picakoch
Copy link

I might not use the library as expected, but I could not find a way to use the find_thumbnail method on a ImageSubset object (returned by get_image_set). I get the following error :
AttributeError: 'ImageSubset' object has no attribute 'filter_by'

Looking in the code, it doesn't seem surprising since ImageSubset is not a descendant of BaseImageQuery, and the method filter_by is called on the self variable.

Could you please let me know how this should be done ?
Here is a snippet of my code (Python 3, imageattach version 1.0.0):

class EventPicture(db.Model, Image):
    __tablename__ = 'event_picture'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), primary_key=True)
    event = db.relationship("Event")
    order_index = db.Column(db.Integer, primary_key=True)  

    @property
    def object_id(self):
        key = '{0},{1}'.format(self.event_id, self.order_index).encode('ascii')
        return int(sha1(key).hexdigest(), 16)

class Event(db.Model):
    __tablename__ = 'event'
    pictures = image_attachment('EventPicture', uselist=True)

    def get_photo(self, i, width=None, height=None):
    """ get the photo with index i and given width/height """
        with store_context(store):
            image_set = self.pictures.get_image_set(order_index=i)
            image_set.find_thumbnail(width=width,height=height) # This is where the exception occurs
           # find_thumbnail tries to execute filter_by on self, but ImageSubset is not a query, it's query is in it's query attribute.

If I reproduce the code of find_thumbnail but replacing the q variable with image_set.query, then it works smoothly.

Thanks a lot,
Best regards,
Antoine

@rogeriobastos
Copy link

I have the same problem then @picakoch and solution proposed works like a charm.

@picakoch is the method generate_thumbnail() working for you when using Multiple Image Sets ?
Here it only generate the first thumbnail, others ImageSets is getting the thumbnail of the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants