示例#1
0
 def test_clean(self):
     image_plugin = FilerImage()
     with self.assertRaises(ValidationError):
         image_plugin.clean()
     filer_image = self.get_filer_object()
     image_plugin.image = filer_image
     image_plugin.image_url = 'https://github.com/divio/django-cms'
     with self.assertRaises(ValidationError):
         image_plugin.clean()
示例#2
0
def create_image_plugin(filename, image, parent_plugin, **kwargs):
    """
    Used for drag-n-drop image insertion with djangocms-text-ckeditor.
    Set TEXT_SAVE_IMAGE_FUNCTION='cmsplugin_filer_image.integrations.ckeditor.create_image_plugin' to enable.
    """
    from cmsplugin_filer_image.models import FilerImage
    from filer.models import Image
    image_plugin = FilerImage()
    image_plugin.placeholder = parent_plugin.placeholder
    image_plugin.parent = CMSPlugin.objects.get(pk=parent_plugin.id)
    image_plugin.position = CMSPlugin.objects.filter(parent=parent_plugin).count()
    image_plugin.language = parent_plugin.language
    image_plugin.plugin_type = 'FilerImagePlugin'
    image.seek(0)
    image_model = Image.objects.create(file=SimpleUploadedFile(name=filename, content=image.read()))
    image_plugin.image = image_model
    image_plugin.save()
    return image_plugin
def create_filer_plugin(filer_image, target_placeholder, language):
    image_plugin = FilerImage(image=filer_image)
    image_plugin.position = 0
    image_plugin.tree_id = 0
    image_plugin.lft = 0
    image_plugin.rght = 0
    image_plugin.level = 0
    image_plugin.plugin_type = 'FilerImagePlugin'
    image_plugin.language = language
    image_plugin.placeholder = target_placeholder
    image_plugin.save()

    return image_plugin