def test_path(self): """Tag should accept a path as its argument.""" storage_path = self.create_image('100x100.png') helper = AdjustmentHelper(storage_path, width=50, height=50, adjustment='fit') t = Template("{% load daguerre %}{% adjust image width=50 height=50 adjustment='fit' %}") c = Context({'image': storage_path}) self.assertEqual(t.render(c), helper.info_dict()['url'])
def test_file(self): """Tag should accept an :class:`ImageFieldFile` as its argument.""" storage_path = self.create_image('100x100.png') adjusted = AdjustedImage() adjusted.adjusted = storage_path helper = AdjustmentHelper(storage_path, width=50, height=50, adjustment='fit') t = Template("{% load daguerre %}{% adjust image width=50 height=50 adjustment='fit' %}") c = Context({'image': adjusted.adjusted}) self.assertEqual(t.render(c), helper.info_dict()['url'])
def render(self, context): # storage_path might be an ImageFile. storage_path = self.storage_path.resolve(context) kwargs = dict((k, v.resolve(context)) for k, v in self.kwargs.iteritems()) helper = AdjustmentHelper(storage_path, **kwargs) info_dict = helper.info_dict() if self.asvar is not None: context[self.asvar] = info_dict return '' return info_dict