1

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.

user2673206
  • 215
  • 2
  • 12
  • 1
    does it have to be a swf? And do the images have to be embedded in the swf? There are lots of javascript based plugins that could do the same thing. Just pass them a list of images from django. – Henry Florence Nov 12 '13 at 17:01
  • have to be swf any idea? thanks. – user2673206 Nov 12 '13 at 17:03
  • 1
    Something like this: http://www.maani.us/xml_slideshow/ and generate the xml in django? – Henry Florence Nov 12 '13 at 17:07
  • thanks it seems direction to go it looks like 1. configure my django app to generate a xml with the static data 2. use xml_slideshow to generate the swf anyhow or document for me to learn more to program the swf file? i tried to google but i dont find something obvious. i would like to have more control on my slideshow. thanks. – user2673206 Nov 12 '13 at 17:28
  • Ah ok, the advantage of using a plugin is that you don't have to program swf. That bit is already done for you, just supply the xml – Henry Florence Nov 12 '13 at 17:31
  • Something like this is a javascript alternative: http://wowslider.com/rq/jquery-carousel/ – Henry Florence Nov 12 '13 at 17:41
  • thanks :) but i need swf any document to "program" swf? i am totally new on this. – user2673206 Nov 12 '13 at 17:47

1 Answers1

1

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?

Henry Florence
  • 2,848
  • 19
  • 16
  • thanks! exactly! i will check more and work on my stuff and let you know more later, may be weekend. thanks a lot for your help. – user2673206 Nov 12 '13 at 19:30