Thanks Mladen for menioning the the import os, I wasn't aware of this. As for (2), I was using the original approach to try to be as unobtrusive as possible to JS from HTML (we're trying assign developers to cookie-cut each area: models for DBAs, controllers for Pythonists, and HTML/CSS for designers, but if the controllers should be manipulated then I guess there is no choice? I was trying NOT to manipulate the web2py_ajax.html directly, only having it including a JS file that will be included in it. I'm not sure what the security or load consequences there are which is why i'm asking for feedback.
Sorry I didn't included this snippet in the web2py_ajax.html to illustrate my point: >>> function web2py_ajax_init() { {{include '../static/jquery_dynamic.js'}} // import individual lines that manipulate IDs and CLASSES from Views files. }); <<<<< I don't directly write the web2py_ajax file but the include file. Is this possible? Thanks again. On Aug 30, 11:17 am, Mladen Milankovic <mml...@gmail.com> wrote: > Hi. > > 1. > If you want to open a file you have to give the file with path on the file > system > and not through url. > I do like this: > > import os > filename = os.path.join(request.folder, 'modules', 'appsettings.py') > > request.folder contains the path to the current application > > 2. > I think it's bad idea to rewrite web2py_ajax.html dynamically. It's not thread > safe. So if multiple people are trying to get the controller, you can't > predict what will happen. > I your case I would do like this: > > <div id="user1">user1<br><span id="hide_user1" > onclick="$("div#user1").hide()">hide</span></div> > > Also pay attention to the ids of the elements. Like in Highlander... there can > be only one, with one name. :) > You can replace the jQuery with $ sign, to be shorter. > > If you need some code to execute on document load, you can add a > document.ready jquery function code in your view. They are "added" together > before executing. So you can define as many as you need. > > regards > mmlado > > On Sunday 30 August 2009 10:37:59 tititi wrote: > > > > > I want to open and append a javascript file (placed in Static folder) > > from default.py file but not seem to get past the error: > > > filename = URL(r=request,c="static",f="jquery_dynamic.js") > > > try: > > logfile = open(filename , 'w') > > > for each in restaurantsFeatures: > > logfile.append('jQuery("span#thumbme%d"%each') > > logfile.close() > > msg = "The file exists" > > except IOError: > > msg = 'error > > > Why am I getting this error? Does this have anything to do with the > > chmod issues? > > > IOError: [Errno 2] No such file or directory: '/Que_Hay_de_Comer/ > > static/jquery_dynamic.js' > > > 2nd part of the question: I want to know if there is a better approach > > in dynamically writing jQuery lines in web2py_ajax.html. Let's say, > > I'm extracting a list of users wrapped in DIVs and with jQuery to > > enable the user to hide or show the DIV. For example: > > > index.html > > > <div id="user1">user1<br><span id="user1">hide</span></div> > > > Now inside the document.ready jQuery function I would put: > > > web2py_ajax.html > > > jQuery("span#user1").click(function() { > > jQuery("div#user1").hide() > > }); > > > So if I add more lines on list of index.html, I also to add lines for > > jQuery to manipulate these same lines. At this moment, I'm <<include>> > > a file to place these lines into the web2py_ajax.html. Is there a > > better way to do this? Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---