Пример #1
0
    def setUp(self):
        super(BaseTest, self).setUp()
        settings.THUMBNAIL_ALIASES = {
            '': {
                'large': {'size': (500, 500)},
                'medium': {'size': (300, 300)},
                'small': {'size': (100, 100)},
            },
            'some_app.Profile': {
                'large': {'size': (200, 200)},
                'banner': {'size': (600, 80), 'crop': True},
            },
            'some_app.Profile.avatar': {
                'avatar': {'size': (80, 80), 'crop': True},
                'small': {'size': (20, 20), 'crop': True},
            },
            'other_app': {
                'sidebar': {'size': (150, 250)},
            }
        }
        self.__aliases = aliases._aliases
        aliases._aliases = {}
        aliases.populate_from_settings()

        if self.create_file:
            self.storage = test.TemporaryStorage()
            # Save a test image.
            self.create_image(self.storage, 'avatars/test.jpg')
            # Set the test model to use the current temporary storage.
            Profile._meta.get_field('avatar').storage = self.storage
            Profile._meta.get_field('avatar').thumbnail_storage = self.storage
Пример #2
0
    def setUp(self):
        super().setUp()
        settings.THUMBNAIL_ALIASES = {
            '': {
                'large': {'size': (500, 500)},
                'medium': {'size': (300, 300)},
                'small': {'size': (100, 100)},
            },
            'easy_thumbnails_tests.Profile': {
                'large': {'size': (200, 200)},
                'banner': {'size': (600, 80), 'crop': True},
            },
            'easy_thumbnails_tests.Profile.avatar': {
                'avatar': {'size': (80, 80), 'crop': True},
                'small': {'size': (20, 20), 'crop': True},
            },
            'other_app': {
                'sidebar': {'size': (150, 250)},
            }
        }
        self.__aliases = aliases._aliases
        aliases._aliases = {}
        aliases.populate_from_settings()

        if self.create_file:
            self.storage = utils.TemporaryStorage()
            # Save a test image.
            self.create_image(self.storage, 'avatars/test.jpg')
            # Set the test model to use the current temporary storage.
            field = models.Profile._meta.get_field('avatar')
            field.storage = self.storage
            field.thumbnail_storage = self.storage
Пример #3
0
 def setUp(self):
     super(BaseTest, self).setUp()
     settings.THUMBNAIL_ALIASES = {
         '': {
             'large': {'size': (500, 500)},
             'medium': {'size': (300, 300)},
             'small': {'size': (100, 100)},
         },
         'some_app.Profile': {
             'large': {'size': (200, 200)},
             'banner': {'size': (600, 80), 'crop': True},
         },
         'some_app.Profile.avatar': {
             'avatar': {'size': (80, 80), 'crop': True},
             'small': {'size': (20, 20), 'crop': True},
         },
     }
     self.__aliases = aliases._aliases
     aliases._aliases = {}
     aliases.populate_from_settings()
Пример #4
0
    def setUp(self):
        super(BaseTest, self).setUp()
        settings.THUMBNAIL_ALIASES = {
            "": {"large": {"size": (500, 500)}, "medium": {"size": (300, 300)}, "small": {"size": (100, 100)}},
            "some_app.Profile": {"large": {"size": (200, 200)}, "banner": {"size": (600, 80), "crop": True}},
            "some_app.Profile.avatar": {
                "avatar": {"size": (80, 80), "crop": True},
                "small": {"size": (20, 20), "crop": True},
            },
            "other_app": {"sidebar": {"size": (150, 250)}},
        }
        self.__aliases = aliases._aliases
        aliases._aliases = {}
        aliases.populate_from_settings()

        if self.create_file:
            self.storage = test.TemporaryStorage()
            # Save a test image.
            self.create_image(self.storage, "avatars/test.jpg")
            # Set the test model to use the current temporary storage.
            Profile._meta.get_field("avatar").storage = self.storage
            Profile._meta.get_field("avatar").thumbnail_storage = self.storage
Пример #5
0
def content_post_save(sender, **kwargs):

    content_types = ['Page', 'Email', 'SMS']
    node_types = [t.lower() for t in content_types]

    if sender.__name__ in content_types:

        content = kwargs['instance']

        # Update title in all sessions
        for session in Session.objects.all():

            data = session.data
            nodes = data.get('nodes', [])
            for node in nodes:
                try:
                    if node['type'] in node_types and node[
                            'ref_id'] == content.id:
                        node['title'] = content.title

                        # ...gently
                        Session.objects.filter(id=session.id).update(data=data)
                except:
                    pass

        # Replace images with thumbnails
        data = content.data
        aliases.populate_from_settings()

        for pagelet in data:

            if pagelet.get('content_type') == 'image':

                url = pagelet['content']['url'].replace(settings.MEDIA_URL, '')

                if url:

                    try:
                        options = aliases.get('medium')
                        thumbnail = get_thumbnailer(url).get_thumbnail(
                            options).url
                    except:
                        thumbnail = None

                    if thumbnail:
                        pagelet['content']['thumbnail'] = thumbnail
                        Content.objects.filter(id=content.id).update(data=data)

            if pagelet.get('content_type') == 'toggle':
                if not 'img_content' in pagelet:
                    pagelet['img_content'] = {'url': ''}

                url = pagelet['img_content']['url'].replace(
                    settings.MEDIA_URL, '')

                if url:

                    try:
                        options = aliases.get('small')
                        thumbnail = get_thumbnailer(url).get_thumbnail(
                            options).url
                    except:
                        thumbnail = None

                    if thumbnail:
                        pagelet['img_content']['thumbnail'] = thumbnail
                        Content.objects.filter(id=content.id).update(data=data)