Пример #1
0
def resize_profile_image(sender, instance, *args, **kwargs):
    try:
        obj = Profile.objects.get(pk=instance.pk)
        """
        Rahul: image_path(i think you might need this "profile_image:)
        not exists please correct this.
        Till then i have commented this code
        """
        if obj.profile_image.name:
            width, height = image_dimensions(settings.BASE_DIR + str(obj.profile_image.url))
            if width > MAX_WIDTH:
                img_resized = resize_image(settings.BASE_DIR + str(obj.profile_image.url), MAX_WIDTH)
                obj.image_path = img_resized
                try:
                    obj.save()
                except Exception as e:
                    log.critical("Unhandled exception in {}, {}".format(__name__, e))
                    # TODO, notify Sentry
    except ObjectDoesNotExist as e:
        log.error("Exception getting profile object: {}".format(e))
Пример #2
0
 def test_profile_img_resize(self):
     path = settings.BASE_DIR + str(self.profile.profile_image.url)
     new_path = resize_image(path, 50, append_str="thumb")
     self.assertRegexpMatches(new_path, re.compile(r'.*thumb\.png'))