Tom - many thanks again.

This is good stuff.

W

On 3 November 2010 11:36, Tom Evans <tevans...@googlemail.com> wrote:
> On Wed, Nov 3, 2010 at 10:16 AM, wawa wawawa <wazawaz...@gmail.com> wrote:
>> You Sir, are awesome.
>>
>> I think this seems to be exactly what I was looking for...
>>
>> Can I ask for JS code that does the periodic polling from the client
>> please and possibly the appropriate bits of the template?
>>
>> Many thanks!
>>
>> W
>>
>
> Sure. In the main page view, I check to see whether I have transcoded
> or started transcoding the episode, and set context variables as
> appropriate:
>
>  if episode.ipad_media:
>    if hasattr(episode.ipad_media, 'task_id'):
>      from transcoding.utils import get_task_progress
>      data['ipad_media_class'] = 'transcoding'
>      data['ipad_media_progress'] = (episode.ipad_media.task_id,
> get_task_progress(episode.ipad_media.task_id))
>    else:
>      data['ipad_media_class'] = 'good'
>  else:
>    data['ipad_media_class'] = 'bad'
>
> This is rendered into a widget on the page:
>
>  {% if episode.media %}
>  <div class='pushbutton'>
>    <div class='button play'>Play episode</div>
>    <div class='button ipad_{{ ipad_media_class }} {{ ipad_media_class }}'>
>      {% if ipad_media_progress %}
>      Transcoding to ipad
>      <div class='pct' id='{{ ipad_media_progress.0 }}'>{{
> ipad_media_progress.1 }} %</div>
>      {% else %}
>      Transcode to ipad
>      {% endif %}
>    </div>
>  </div>
>  {% endif %}
>
>
> Then, during page load, I configure an observer to update each
> progress widget (I use the prototype JS framework):
>
>  $$('div.pct').each(function(ctl) {
>      new Ajax.PeriodicalUpdater(ctl, '{% url transcode_task_status_ajax %}', {
>        method: 'get',
>        asynchronous: true,
>        frequency: 3,
>        decay: 2,
>        parameters: { task_id: ctl.id }
>        });
>      });
>
> That view is trivial, since it just updates the appropriate div with
> the current percentage:
>
> def transcode_task_status_ajax(request):
>  from transcoding.utils import get_task_progress
>  task_id = request.GET.get('task_id')
>  return HttpResponse(u'%s %%' % get_task_progress(task_id))
>
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to