Ejemplo n.º 1
0
def save_image(folder, dir, filename, user):
    base, _ =  os.path.splitext(filename)
    filepath = os.path.join(dir, filename)
    file = DjangoFile(open(filepath, 'rb'), name=filename)
    image = Image(owner=user, folder=folder, name=base, original_filename=filename, file=file, is_public=True)
    image.save()
    return image
Ejemplo n.º 2
0
 def setUp(self):
     # create & save plugin
     self.plugin = ImageSetPlugin()
     self.plugin.save()
     # create & save images
     self.image1 = Image(_width=100, _height=100)
     self.image1.save()
    def setUp(self):
        self.inactive_category = self.create_categorization('category', 'Inactive', active=False)

        # Modifiers
        self.phones_discount = self.create_modifier('Phones Discount 10%', percent=-10)
        self.mobile_discount = self.create_modifier('Mobile Discount 5%', percent=-5)

        # Flags
        self.f1 = self.create_flag('F1')
        self.f2 = self.create_flag('F2')

        # Tax
        self.tax = self.create_tax('PDV', percent=25)

        # Categories
        self.dummy_image = Image(original_filename='dummy.jpg')
        self.phones = self.create_categorization('category', 'Phones', tax=self.tax)
        self.phones.featured_image = self.dummy_image
        self.phones.modifiers.add(self.phones_discount)
        self.phones.flags.add(self.f1)
        self.phones_mobile = self.create_categorization('category', 'Mobile', parent=self.phones)
        self.phones_mobile.modifiers.add(self.mobile_discount)
        self.phones_mobile.flags.add(self.f2)

        self.apple = self.create_categorization('brand', 'Apple')
        self.china = self.create_categorization('manufacturer', 'Made in China')

        # Products
        self.p1 = self.create_product('P1', category=self.phones)
        self.p2 = self.create_product('P2', category=self.phones_mobile)
Ejemplo n.º 4
0
 def setUp(self):
     # create & save plugin
     self.plugin = ImageSetPlugin()
     self.plugin.save()
     # create & save images
     self.image1 = Image(_width=100, _height=100)
     self.image2 = Image(_width=200, _height=100)
     self.image3 = Image(_width=300, _height=100)
     self.image1.save()
     self.image2.save()
     self.image3.save()
     # create & save plugin items
     self.item1 = ImageSetItem(plugin=self.plugin, image=self.image1)
     self.item2 = ImageSetItem(plugin=self.plugin, image=self.image2)
     self.item3 = ImageSetItem(plugin=self.plugin, image=self.image3)
     self.item1.save()
     self.item2.save()
     self.item3.save()
Ejemplo n.º 5
0
    def test_carousel_plugin(self):
        """
        test the output of the link set plugin
        """
        img = Image(_width=100, _height=100)
        img.save()

        placeholder = Placeholder(slot=u"some_slot")
        placeholder.save() # a good idea, if not strictly necessary

        # add the plugin
        plugin = add_plugin(
            placeholder,
            u"CarouselPluginPublisher",
            u"en",
            width = 1000.0
        )
        plugin.save()

        # get the corresponding plugin instance
        instance = plugin.get_plugin_instance()[1]
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add an item to the plugin
        item1 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            active=False,
            image_id=img.id,
            )
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # now the item is active
        item1.active=True
        item1.save()
        self.assertEquals(instance.render({}, plugin, placeholder), {})

        # add a second image to the plugin
        item2 = CarouselPluginItem(
            plugin=plugin,
            destination_content_type = ContentType.objects.get_for_model(self.school),
            destination_object_id = self.school.id,
            link_title=u"item1 link title",
            image_id=img.id,
            )
        item2.save()
        self.assertListEqual(
            instance.render({}, plugin, placeholder)["segments"],
            [item1, item2]
        )

        # now the ordering should be reversed
        item1.inline_item_ordering=1
        item1.save()
        rendered_plugin = instance.render({}, plugin, placeholder)
        self.assertListEqual(
            rendered_plugin["segments"],
            [item2, item1]
        )

        # check size calculations
        self.assertEqual(
            rendered_plugin["size"],
            (98,65)
        )
        # if we delete the image the items should be deleted too
        img.delete()
        self.assertEquals(instance.render({}, plugin, placeholder), {})