Travis Branham | 2 Jun 06:10 2008
Picon

Connecting to external JavaScript libs with Athena

Hi all,

So, I've been racking my brain for a couple of days on this, and I can't seem to get anywhere. My question is: Is it possible to connect to an external JavaScript library, and subsequently make calls to said library through an Athena LivePage element?

Just to let you know where this is going, I had planned on embedding a map in my web application, using the Google Maps API. The problem, as I'm sure you can guess, is that the JavaScript for GM is loaded directly from their servers through the Google AJAX API. Now, I know their Ajax API does create a unique namespace for the function calls (eg: google.maps.Map2, etc.), but, so far, I have been unable to get a method from a LivePage or LiveElement to be able to talk with the Google API. Just to be clear, I have no problem simply importing the GM API and displaying the map -- my problem is that I want to add markers to the map, based on some server-side events. Effectively, I will have little to no client -> server communication during a normal visit (except, of course, the user& #39;s interaction with the map, which happens on Google's end anyway).

When I tried to figure out how to do this in the first place, I tried modifying the "Athena LiveElement Tutorial" by embedding the JavaScript call (a simple "echo" function) directly into the HTML source (instead of using the jsClass attribute in LiveElement); from there, I tried a number of ways to get the LiveElement to "talk" to the embedded JS. No dice.

Perhaps I'm missing something, or perhaps what I'm trying to do is just not supported. I'd supply some code here, but I really don't know if that would be very useful; let me know, however, if you feel otherwise.

Anyway, any insight will be helpful.

Thanks a lot,
Travis

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
glyph | 2 Jun 08:09 2008

Re: Connecting to external JavaScript libs with Athena

On 04:10 am, tbranham <at> gmail.com wrote:
>So, I've been racking my brain for a couple of days on this, and I 
>can't
>seem to get anywhere. My question is: Is it possible to connect to an
>external JavaScript library, and subsequently make calls to said 
>library
>through an Athena LivePage element?

Sure, maybe.  It depends what you mean by all those words.  "connect" to 
an external javascript library?  Don't you mean "load" an external 
javascript library?  And how is making calls to a library different than 
making calls to any random function?

I don't know a lot about Google Maps, but I do know that Divmod's most 
recent product (Blendix) uses Google Maps to display locations.

You can see this in action on my blendix page:

    http://blendix.com/users/glyph/

or view the source code:

http://blendix.com/__jsmodule__/16f16613df2ba86d19271a41115d50bedf4b461d/Blendix.PersonDetail

Have a look at the 'initializeMap' method to see an example of 
integration between Athena and Google Maps.

Please note that this isn't open source; we haven't released the code 
anywhere yet (although this part is JavaScript, so you could of course 
have just done 'view source' and figured out that link for yourself).
Werner Thie | 2 Jun 11:34 2008
Picon

Re: Connecting to external JavaScript libs with Athena

Hi Travis

Say you want to use MochiKit functionality then just do a

	:
	:
class XYZPage(athena.LivePage):
   javaScript = ('/scripts/MochiKit.js')

def beforeRender(self, ctx:
	:
	:

Simply use all MochiKit functionality as provided.

Best working environment for me is Firefox with Firebug installed, if 
you want to have a look at some experiments of mine in this area head to

http://jass.thie.ch

U:optobyte
P:optobyte

and poke around. Be warned though, those are early experiments of mine, 
dating back to 2006

HTH, Werner

Travis Branham wrote:
> Hi all,
> 
> So, I've been racking my brain for a couple of days on this, and I can't 
> seem to get anywhere. My question is: Is it possible to connect to an 
> external JavaScript library, and subsequently make calls to said library 
> through an Athena LivePage element?
> 
> Just to let you know where this is going, I had planned on embedding a 
> map in my web application, using the Google Maps API. The problem, as 
> I'm sure you can guess, is that the JavaScript for GM is loaded directly 
> from their servers through the Google AJAX API. Now, I know their Ajax 
> API does create a unique namespace for the function calls (eg: 
> google.maps.Map2, etc.), but, so far, I have been unable to get a method 
> from a LivePage or LiveElement to be able to talk with the Google API. 
> Just to be clear, I have no problem simply importing the GM API and 
> displaying the map -- my problem is that I want to add markers to the 
> map, based on some server-side events. Effectively, I will have little 
> to no client -> server communication during a normal visit (except, of 
> course, the user's interaction with the map, which happens on Google's 
> end anyway).
> 
> When I tried to figure out how to do this in the first place, I tried 
> modifying the "Athena LiveElement Tutorial" by embedding the JavaScript 
> call (a simple "echo" function) directly into the HTML source (instead 
> of using the jsClass attribute in LiveElement); from there, I tried a 
> number of ways to get the LiveElement to "talk" to the embedded JS. No dice.
> 
> Perhaps I'm missing something, or perhaps what I'm trying to do is just 
> not supported. I'd supply some code here, but I really don't know if 
> that would be very useful; let me know, however, if you feel otherwise.
> 
> Anyway, any insight will be helpful.
> 
> Thanks a lot,
> Travis
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Twisted-web mailing list
> Twisted-web <at> twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Travis Branham | 2 Jun 15:41 2008
Picon

Re: Connecting to external JavaScript libs with Athena

Thanks, Glyph.

Yes, by 'connect', I really meant 'load'. Your links were quite helpful; I believe that the following snippet was enough to keep me moving along:

function _makeGoogleMap(self, mapContainerNode) {
        return (new GMap2(mapContainerNode));
},

I'll have to double-check my trials, because I was trying something similar from the outset. Of course, "something similar" and "something wrong" are, in this case, one and the same ;)

Thanks for taking the time!

-Travis

On Mon, Jun 2, 2008 at 2:09 AM, <glyph <at> divmod.com> wrote:
On 04:10 am, tbranham <at> gmail.com wrote:
So, I've been racking my brain for a couple of days on this, and I can't
seem to get anywhere. My question is: Is it possible to connect to an
external JavaScript library, and subsequently make calls to said library
through an Athena LivePage element?

Sure, maybe.  It depends what you mean by all those words.  "connect" to an external javascript library?  Don't you mean "load" an external javascript library?  And how is making calls to a library different than making calls to any random function?

I don't know a lot about Google Maps, but I do know that Divmod's most recent product (Blendix) uses Google Maps to display locations.

You can see this in action on my blendix page:

  http://blendix.com/users/glyph/

or view the source code:

http://blendix.com/__jsmodule__/16f16613df2ba86d19271a41115d50bedf4b461d/Blendix.PersonDetail

Have a look at the 'initializeMap' method to see an example of integration between Athena and Google Maps.

Please note that this isn't open source; we haven't released the code anywhere yet (although this part is JavaScript, so you could of course have just done 'view source' and figured out that link for yourself).

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web



--
Travis Lee Branham

_______________________________________________
Twisted-web mailing list
Twisted-web <at> twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Phil Christensen | 5 Jun 20:58 2008

requestHeaders issues

Hi all,

I've run into a problem in Twisted.Web with a recent addition to SVN  
head. The problem occurs in my WSGI gateway module, which is derived  
from web2's version. When I'm creating the environment dictionary by  
iterating like this:

     # Propagate HTTP headers
     for title in request.received_headers:
         header = request.received_headers[title]
         ...
         ...

the iteration through received_headers causes the following exception:

     Traceback (most recent call last):
       File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in  
createCGIEnvironment
         for title in request.received_headers:
       File "/Users/phil/Workspace/Twisted/twisted/web/ 
http_headers.py", line 41, in __getitem__
         if self._headers.hasHeader(key):
       File "/Users/phil/Workspace/Twisted/twisted/web/ 
http_headers.py", line 247, in hasHeader
         return name.lower() in self._rawHeaders
     exceptions.AttributeError: 'int' object has no attribute 'lower'

After some searching, I found this patch:

     r23826 | exarkun | 2008-06-02 11:06:06 -0400 (Mon, 02 Jun 2008) |  
15 lines

     Merge web-headers-165-2

     Author: dreid, exarkun
     Reviewer: therve
     Fixes: #165

     Add two new attributes to twisted.web.http.Request,  
`requestHeaders` and
     `responseHeaders`, which parallel the previous attributes  
`received_headers`
     and `headers`.  The new attributes are preferred and provide a  
structured
     interface to accessing and manipulating header information,  
including
     multiples values per header which was unsupported by the previous  
API.
     `received_headers` and `headers` are not deprecated and coding  
using
     them will continue to work, but their use is discouraged and they  
will be
     deprecated at some future time.

If I make those changes and use `requestHeaders` instead, like this:

     # Propagate HTTP headers
     for title in request.received_headers:
         header = request.received_headers[title]
         ...
         ...

I instead get the following traceback:

     Traceback (most recent call last):
       File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in  
createCGIEnvironment
         for title in request.requestHeaders:
     exceptions.TypeError: 'Headers' object is not iterable

which seems strange to me, since from what I can tell,  
request.requestHeaders should be a http_headers._DictHeaders instance.  
Should I be calling request.requestHeaders.getAllRawHeaders() and  
iterate through that result instead?

Any guidance in this matter would be greatly appreciated.

Thanks again,

-phil
Jean-Paul Calderone | 5 Jun 22:01 2008

Re: requestHeaders issues

On Thu, 5 Jun 2008 14:58:21 -0400, Phil Christensen <phil <at> bubblehouse.org> wrote:
>Hi all,
>
>I've run into a problem in Twisted.Web with a recent addition to SVN  head. 
>The problem occurs in my WSGI gateway module, which is derived  from web2's 
>version. When I'm creating the environment dictionary by  iterating like 
>this:
>
>     # Propagate HTTP headers
>     for title in request.received_headers:
>         header = request.received_headers[title]
>         ...
>         ...

Hi Phil,

Thanks for reporting this and tracking down the cause.  I'll back out that
revision shortly until it can be fixed.

>
>If I make those changes and use `requestHeaders` instead, like this:
>
>     # Propagate HTTP headers
>     for title in request.received_headers:
>         header = request.received_headers[title]
>         ...
>         ...
>
>I instead get the following traceback:
>
>     Traceback (most recent call last):
>       File "/Users/phil/Workspace/modu/modu/web/wsgi.py", line 91, in 
>createCGIEnvironment
>         for title in request.requestHeaders:
>     exceptions.TypeError: 'Headers' object is not iterable
>
>which seems strange to me, since from what I can tell, 
>request.requestHeaders should be a http_headers._DictHeaders instance. 
>Should I be calling request.requestHeaders.getAllRawHeaders() and  iterate 
>through that result instead?
>
>Any guidance in this matter would be greatly appreciated.

In the future, using `requestHeaders.getAllRawHeaders´ will be the right
thing to do.  `request.requestHeaders´ isn't a `_DictHeaders´ though, it's
a `Headers´ - `request.received_headers´ is the `_DictHeaders´.  I suspect
that's what you meant, though.

Jean-Paul
Phil Christensen | 5 Jun 22:09 2008

Re: requestHeaders issues

On Jun 5, 2008, at 4:01 PM, Jean-Paul Calderone wrote:
> Thanks for reporting this and tracking down the cause.  I'll back  
> out that
> revision shortly until it can be fixed.

Thank you for the quick response!

-phil
Jean-Paul Calderone | 19 Jun 14:20 2008

Python 2.3 support in Nevow

Glyph and I had a discussion about Nevow on Python 2.3 yesterday.
We ended up wondering who is using Nevow with Python 2.3 and who
would notice or care if Python 2.4 became the minimum requirement.
So, if you're using Nevow, what version of Python are you using it
with?

Jean-Paul

Phil Mayers | 19 Jun 14:45 2008
Picon

Re: Python 2.3 support in Nevow

Jean-Paul Calderone wrote:
> Glyph and I had a discussion about Nevow on Python 2.3 yesterday.
> We ended up wondering who is using Nevow with Python 2.3 and who
> would notice or care if Python 2.4 became the minimum requirement.
> So, if you're using Nevow, what version of Python are you using it
> with?

2.5 because we want  <at> inlineCallbacks. The occasional 2.4 for a 
tiny/simple interface. No 2.3, and I can't see we'd ever want any - we 
roll RPMs for python25 on systems where the OS python is too low e.g. 
RHEL3/4

Drake Smith | 19 Jun 15:09 2008
Picon
Picon

Re: Python 2.3 support in Nevow

At 08:20 AM 6/19/2008, you wrote:
>Glyph and I had a discussion about Nevow on Python 2.3 yesterday.
>We ended up wondering who is using Nevow with Python 2.3 and who
>would notice or care if Python 2.4 became the minimum requirement.
>So, if you're using Nevow, what version of Python are you using it
>with?
>
>Jean-Paul

We use Nevow for several projects but only under Python 2.5.

Gmane