I bugged Massimo with this but thought I should post here too.  It's
just a suggestion for a menu of quick links back to the models,views
and controllers of the current application when editing a file.  I
flip back and forth between the views and controllers a lot so I also
included a link to edit the corresponding controller when the file you
are currently editing is a view.  Here's what I came up with:

In admin/controllers/default.py I changed the edit function:
----------------------------------------------------------------------------------
def edit():
    """ admin controller function """
    filename='/'.join(request.args)
    if filename[-3:]=='.py': filetype='python'
    elif filename[-5:]=='.html': filetype='html'
    elif filename[-4:]=='.css': filetype='css'
    elif filename[-3:]=='.js': filetype='js'
    else: filetype='text'
    ### check if file is not there
    data=open(apath(filename),'r').read()
    try:
        data=request.vars.data.replace('\r\n','\n').strip()
        open(apath(filename),'w').write(data)
        response.flash=T("file saved on %
(time)s",dict(time=time.ctime()))
    except Exception: pass
    ctrlr=None
    if filetype=='html' and request.args[2].lower().endswith('.html')
== False:
        try:
 
ctrlr=URL(r=request,f='edit',args=[request.args[0],'controllers',request.args[2]+'.py'])
        except:
            pass
    return
dict(app=request.args[0],filename=filename,filetype=filetype,data=data,ctrlr=ctrlr)

In admin/views/default/edit.html I added the menu:
-----------------------------------------------------------------------
{{extend 'layout.html'}}
<script language="Javascript" type="text/javascript" src="/
{{=request.application}}/static/edit_area/edit_area_full.js"></
script><script language="Javascript" type="text/javascript">
editAreaLoader.init({id: "body",start_highlight: true,allow_resize:
"both",allow_toggle: true,language: "en",syntax:
"{{=filetype}}",replace_tab_by_spaces: 4});
</script>

<h1>Editing file "{{=filename}}"</h1>
[ {{=A("models",_href=URL(r=request,f='design',args=[app
+'#models']))}}
| {{=A("views",_href=URL(r=request,f='design',args=[app+'#views']))}}
| {{=A("controllers",_href=URL(r=request,f='design',args=[app
+'#controllers']))}}
{{if ctrlr:}}
| <a href="{{=ctrlr}}">edit this controller</a>
{{pass}}]<hr/>
<form action="/{{=request.application}}/default/edit/{{=filename}}"
method="post">
<input type="submit" value="save"/><br/>
<textarea cols="80" rows="25" id="body" style="width: 100%;"
name="data">{{=data}}</textarea>
</form>

--------------------------------
Nothing ground-breaking but it helps me a bit. web2py rocks!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to