Hi there,

As I'm fairly new to the python web development, sometimes I found it's hard to get an idea of how to use features in the repoze.bfg. For example, for the xhr view predicate, the document says "this is useful for detecting AJAX requests issued from jQuery, Prototype and other Javascript libraries.".

Well yes, I understand it, but I still don't know what can I do with it. Although a first look at the question I would say it's not appropriate to ask it here, as I can understand this is a feature exists in such a framework like BFG, which declares itself as /Minimalism/, and it's totally up to each individual developer to deal with, but for a newbie like me just can't imagine how to start with it. Thankfully I can study and learn many other features by looking at the source code such as BFG site, but still there are points here and there which I can't find a example. So a sample code snippet would be will very helpful.

Enough talk and let's go back to the business, I'm currently trying to use TinyMCE to provide a rich editor of my text field, one of its functionality is to supply a list of jpg files on the server to the user, which is an option named "external_image_list_url" in TinyMce. My task is to return a java script like "var = array of files" to the main TinyMCE script in a template, I first defined a view in zcml:


in the template, I have TinyMCE java script initialized as this,

 external_image_list_url: "imgList"

in the js.py I have a function to return a javascript document,

def imgList(context, request):
    response = Response(content_type='application/x-javascript')
    here = os.path.dirname(__file__)
    basedir = os.path.join(here,"templates","static","images","site")
    baseurl = "/static/images/site/"

    files = glob.glob(basedir+"/*")
array = [(os.path.basename(file),baseurl+os.path.basename(file)) for file in files]

response.body = "var %s = %s" % ('tinyMCEImageList', simplejson.dumps(array))
    return response

in the above function I use json to return the array of image files to the template,

It runs without problem, my question is, is it a best way to do it? As I read through the document, I saw "xhr" view predicate, and json renderer, is there a way to utilize them to simplify my code? And I'm very interested to see a sample piece of code to use json+xhr+jquery.


Repoze-dev mailing list

Reply via email to