pythondjangopyamfming

how to generate a slideshow in swf format from python?


how to generate a sildeshow in swf format from python/django?

basically i have a list of images and text and I would like to use python to generate a swf file.

I checked seems using MING or PyAMF is the direction to go but I dont quite understand how it should work.

thanks.


Solution

  • Ok, so to create an swf slideshow you need to use Adobe Flash, a suitable tutorial: http://www.republicofcode.com/tutorials/flash/slideshow/.

    To output the xml file from django, use a view that outputs xml:

    views.py

    from django.template.loader import render_to_string
    from django.http import HttpResponse
    
    def slideshow_xml(request, pk):
        slideshow = Slideshow.objects.get(pk=pk)
        xml = render_to_string('xml_template.xml', {'slideshow': slideshow})
    
        return HttpResponse(xml, mimetype="application/xml")
    

    This would respond to a url like /slideshow/10/ and retrieves the SlideShow object with id 10, this is then passed to an xml template to be rendered:

    Template xml_template.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <slideshow width="{{ slideshow.width }}" height="{{ slideshow.height }}" speed="{{ slideshow.speed }}">
         {% for image in slideshow.slideshowimage_set.all %}
          <image url="{{ image.image.url }}" title="{{ image.title }}" />
         {% endfor %}
    </slideshow>
    

    This will output the xml format as required for the tutorial above. It extracts the data stored in the objects to create the xml file.

    models.py:

    from django.db import models
    
    class SlideShow(Models.model):
        height = models.IntegerField()
        width = models.IntegerField()
        speed = models.IntegerField()
    
    class SlideShowImage(Models.model):
        slideshow = models.ForeignKey(SlideShow)
        title = models.CharField(max_length=100)
        image = models.ImageField(upload_to='slideshow_images/')
    

    These models can be created in the admin interface of django and allow the parameters of the slideshow to be specified. An arbitrary number of SlideShowImage objects can be created and connected to a single SlideShow object.

    If you haven't used django before the django tutorial will get you far enough to understand the above.

    Is this something like what you want?