On Wed, 2008-01-02 at 22:44 -0800, Tiger Uppercut wrote: > Hi, > > I'm looking for the most pythonic [or djangonautic] way to render a > FusionChart [http://www.fusioncharts.com/gadgets/docs/] in Django. I > searched through the forums and didn't see this addressed directly -- > my apologies if this is very basic and obvious! > > 1. I have a django template, container.html: > > {% block head %} > <script language="JavaScript" > src="/site_media/swf/Charts/FusionCharts.js"></script> > {% endblock head %} > > {% block main_content %} > <div id="chartdiv" align="center"> > The chart will appear within this DIV. This text will > be replaced by the chart. > </div> > <script type="text/javascript"> > > var myChart = new > FusionCharts("/site_media/swf/Charts/HLinearGauge.swf", > "myChartId", "400", "200", "0", "0"); > > myChart.setDataXML("your_data.xml"); > > myChart.render("chartdiv"); > > </script> > {% endblock main_content %} > > 2. your_data.xml is also a django template, stored in > myapp/templates/you/your_data.xml, and the TEMPLATE_DIRS setting > includes myapp/template > > <chart lowerLimit='0' upperLimit='100' lowerLimitDisplay='Bad' > upperLimitDisplay='Good' palette='1' numberSuffix='%' > chartRightMargin='20'> > <colorRange> > <color minValue='0' maxValue='75' code='FF654F' > label='Bad'/> > <color minValue='75' maxValue='90' code='F6BD0F' > label='Moderate'/> > <color minValue='90' maxValue='100' code='8BBA00' > label='Good'/> > </colorRange> > <pointers> > <pointer value='{{ your.value }}' /> > </pointers> > </chart> > > 3. I have a view --- def your_data(request). I want this view to > > > a) populate the your.value object in the xml template -- your_data.xml > b) render the containing template, container.html. > > > Any suggestions on the best approach for this ... ?
I think you've got the horse and cart is slightly the wrong order here. Rendering the first template should be easy, since it's just a normal render_to_response() call. It looks like this is designed to be part of some larger template that wraps things in html elements, etc. So maybe there's a {% extends "foo.html" %} missing at the top. Now imagine that you've served that data to the user's browser and it is executing away. It gets to the point where it needs the file your_data.xml and so will, at that point only, call back to the webserver to retrieve the file. So you now need a view that responds to the request for your_data.xml and serves up the template you've constructed. If you know what should be in the context variable "your" at that point, you've got no problems. The view for your_data.xml just returns the rendered template. If you don't know "your", but you did know it when you served the original template, you have to get a bit tricky. You could change the name of the XML template from your_data.xml to your_data_<id>.xml (where <id> is some identifier). Then your URL pattern knows how to serve things that look like ^your-data-(?P<ident>\d+).xml$ and your view function will take an "ident" parameter that tells you how to look up the "your" object for populating the data. You could also shove this information into the user's session or use a query parameter, but munging the name makes things nice and clear and RESTful, so it would be my natural reaction. In short, this isn't a single view, since it's multiple HTTP requests from the browser (this is what I meant by getting things in the right order: one view is one request, so work out the requests to determine the views you need). You need two views and (maybe) some way of passing information from the first response to the second. Regards, Malcolm > -- A conclusion is the place where you got tired of thinking. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---