Let me give more details..

I am trying to write a web-based multi-protocol client. There is an
opensource messenger Pidgin. Pidgin also comes with a dbus interface
with which, you can talk to pidgin, and do all the stuff provided by
pidin through scripts. Pidgin has signal handling system.  For certain
events, corresponding signals will be raised. Through dbus, I am
registering a python function (message_received) as a callback
function which listens to "message received" signal. This function
will be called when ever a new message is received on Pidgin. Now I
have to do **something** inside the message_received function which
will render the the received message on my Template.

Is there an automatic way of updating my template from this view?

Right now, the way I am doing is, I am using Ajax.PeriodicalUpdater,
and polling every second for new messages. This is very inefficient
and I think this is not a scalable solution. With out continuous
updating, if I can update the template from message_received callback
function, only when message is received, that will be great.

Could someone throw some light in this? Even some hints will be
great.



-------------------- Signal Handling inside a Django View ------------

def message_received(account, sender, message, conversation, flags):
    # here I should do something to make this message popup in my
    # template. I think I cannot use the render_to_response directly
here
    # this function is not called by a Httprequest


class SignalListner(threading.Thread):
        run(self):
                import dbus, gobject
                from dbus.mainloop.glib import DBusGMainLoop
                dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
                bus = dbus.SessionBus()

                bus.add_signal_receiver(my_func,

dbus_interface="im.pidgin.purple.PurpleInterface",
                        signal_name="ReceivedImMsg")

                loop = gobject.MainLoop()
                loop.run()

SignalListner().run()

----------------- end of view -------------------


Thanks  a lot

-Priyank


On Jun 20, 7:55 am, "Norman Harman" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi,
>
> > I am writing a web based chat client in Django framework. When ever I
> > receive a message, I get that in a python function which is in the
> > same file as my views. Can I directly pass this data to the template
> > (by using response_to_render ) toupdatethe template? Could someone
> > suggest a way to automaticallyupdatemessages in the site from python
> > code.
>
> are you talking about 
> this?http://www.djangoproject.com/documentation/authentication/#messages
>
> or something else?
>
> If the function takes no parameters and returns a string, you can pass
> it in the context and call it like a variable.
>
> {{ myfunction }}
>
> I believe this will call the function each time it is used.  I'd
> probably do something like this instead.
>
> def my_view(request):
>    extra = dict()
>    extra["message"] = myfunction(args, and, stuff)
>    return render_to_response("mytemplate", extra)
>
> seehttp://www.djangoproject.com/documentation/shortcuts/#render-to-response
>
> --
> Norman J. Harman Jr.
> Senior Web Specialist, Austin American-Statesman
> ___________________________________________________________________________
> You've got fun!  Check out Austin360.com for all the entertainment
> info you need to live it up in the big city!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to