Made some changes intended to speed up page loading slightly.
* Blank iframe contents now come from static HTML rather than dynamic CherryPy. * Reindented @strongly_expire decorator. * Removed one stage of Editor's multi-stage construction.
This commit is contained in:
parent
0b920ca8a5
commit
658e42aeba
|
@ -2,14 +2,14 @@ import cherrypy
|
||||||
|
|
||||||
|
|
||||||
def strongly_expire( function ):
|
def strongly_expire( function ):
|
||||||
"""
|
"""
|
||||||
Decorator that sends headers that instruct browsers and proxies not to cache.
|
Decorator that sends headers that instruct browsers and proxies not to cache.
|
||||||
"""
|
"""
|
||||||
def expire( *args, **kwargs ):
|
def expire( *args, **kwargs ):
|
||||||
cherrypy.response.headers[ "Expires" ] = "Sun, 19 Nov 1978 05:00:00 GMT"
|
cherrypy.response.headers[ "Expires" ] = "Sun, 19 Nov 1978 05:00:00 GMT"
|
||||||
cherrypy.response.headers[ "Cache-Control" ] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
|
cherrypy.response.headers[ "Cache-Control" ] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
|
||||||
cherrypy.response.headers[ "Pragma" ] = "no-cache"
|
cherrypy.response.headers[ "Pragma" ] = "no-cache"
|
||||||
|
|
||||||
return function( *args, **kwargs )
|
return function( *args, **kwargs )
|
||||||
|
|
||||||
return expire
|
return expire
|
||||||
|
|
|
@ -12,7 +12,6 @@ from model.Notebook import Notebook
|
||||||
from model.Note import Note
|
from model.Note import Note
|
||||||
from view.Main_page import Main_page
|
from view.Main_page import Main_page
|
||||||
from view.Json import Json
|
from view.Json import Json
|
||||||
from view.Note_page import Note_page
|
|
||||||
from view.Html_file import Html_file
|
from view.Html_file import Html_file
|
||||||
|
|
||||||
|
|
||||||
|
@ -617,19 +616,6 @@ class Notebooks( object ):
|
||||||
self.__database.save( notebook )
|
self.__database.save( notebook )
|
||||||
|
|
||||||
yield dict()
|
yield dict()
|
||||||
@expose( view = Note_page )
|
|
||||||
@validate( id = Valid_string( min = 1, max = 100 ) )
|
|
||||||
def blank_note( self, id ):
|
|
||||||
"""
|
|
||||||
Provide the information necessary to display a blank note frame to be filled in by the client.
|
|
||||||
|
|
||||||
@param id: unicode
|
|
||||||
@type id: id of the note
|
|
||||||
@rtype: unicode
|
|
||||||
@return: rendered HTML page
|
|
||||||
@raise Validation_error: the argument is invalid
|
|
||||||
"""
|
|
||||||
return dict( id = id )
|
|
||||||
|
|
||||||
@expose( view = Json )
|
@expose( view = Json )
|
||||||
@strongly_expire
|
@strongly_expire
|
||||||
|
|
|
@ -1244,10 +1244,6 @@ class Test_notebooks( Test_controller ):
|
||||||
note2 = result.get( "note" )
|
note2 = result.get( "note" )
|
||||||
assert note2.object_id == self.note2.object_id
|
assert note2.object_id == self.note2.object_id
|
||||||
|
|
||||||
def test_blank_note( self ):
|
|
||||||
result = self.http_get( "/notebooks/blank_note/5" )
|
|
||||||
assert result[ u"id" ] == u"5"
|
|
||||||
|
|
||||||
def test_search_titles_without_titles_only( self ):
|
def test_search_titles_without_titles_only( self ):
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="/static/css/note.css" type="text/css" rel="stylesheet"></link>
|
||||||
|
<script src="/static/js/MochiKit.js" type="text/javascript"></script>
|
||||||
|
<script src="/static/js/Invoker.js" type="text/javascript"></script>
|
||||||
|
<meta content="text/html; charset=UTF-8" http-equiv="content-type"></meta>
|
||||||
|
</head>
|
||||||
|
<body></body>
|
||||||
|
</html>
|
|
@ -13,7 +13,7 @@ function Editor( id, notebook_id, note_text, deleted_from, revisions_list, inser
|
||||||
var self = this;
|
var self = this;
|
||||||
this.document = null;
|
this.document = null;
|
||||||
this.iframe = createDOM( "iframe", {
|
this.iframe = createDOM( "iframe", {
|
||||||
"src": "/notebooks/blank_note/" + id,
|
"src": "/static/html/blank_note.html",
|
||||||
"frameBorder": "0",
|
"frameBorder": "0",
|
||||||
"scrolling": "no",
|
"scrolling": "no",
|
||||||
"id": iframe_id,
|
"id": iframe_id,
|
||||||
|
@ -95,25 +95,20 @@ function Editor( id, notebook_id, note_text, deleted_from, revisions_list, inser
|
||||||
appendChildNodes( "notes", this.note_controls );
|
appendChildNodes( "notes", this.note_controls );
|
||||||
appendChildNodes( "notes", this.iframe );
|
appendChildNodes( "notes", this.iframe );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect( this.iframe, "onload", function ( event ) { self.init_document(); } );
|
||||||
}
|
}
|
||||||
|
|
||||||
// second stage of construction, invoked by the iframe's body onload handler. do not call directly.
|
// second stage of construction, invoked by editor_loaded(). do not call directly
|
||||||
// four-stage construction is only necessary because IE is such a piece of shit
|
|
||||||
function editor_loaded( id ) {
|
|
||||||
var iframe = getElement( "note_" + id );
|
|
||||||
setTimeout( function () { iframe.editor.init_document(); }, 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// third stage of construction, invoked by the editor_loaded() function. do not call directly
|
|
||||||
Editor.prototype.init_document = function () {
|
Editor.prototype.init_document = function () {
|
||||||
var self = this; // necessary so that the member functions of this editor object are used
|
var self = this; // necessary so that the member functions of this editor object are used
|
||||||
|
|
||||||
if ( this.iframe.contentDocument ) { // browsers such as Firefox
|
if ( this.iframe.contentDocument ) { // browsers such as Firefox
|
||||||
this.document = this.iframe.contentDocument;
|
this.document = this.iframe.contentDocument;
|
||||||
|
|
||||||
if ( this.read_write ) {
|
if ( this.read_write )
|
||||||
this.document.designMode = "On";
|
this.document.designMode = "On";
|
||||||
}
|
|
||||||
setTimeout( function () { self.finish_init(); }, 1 );
|
setTimeout( function () { self.finish_init(); }, 1 );
|
||||||
} else { // browsers such as IE
|
} else { // browsers such as IE
|
||||||
this.document = this.iframe.contentWindow.document;
|
this.document = this.iframe.contentWindow.document;
|
||||||
|
@ -127,7 +122,7 @@ Editor.prototype.init_document = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fourth and final stage of construction, invoked by init_document(). do not call directly
|
// third and final stage of construction, invoked by init_document(). do not call directly
|
||||||
Editor.prototype.finish_init = function () {
|
Editor.prototype.finish_init = function () {
|
||||||
if ( !this.initial_text )
|
if ( !this.initial_text )
|
||||||
this.initial_text = "<h3>";
|
this.initial_text = "<h3>";
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
from Tags import Html, Head, Link, Script, Meta, Body
|
|
||||||
|
|
||||||
|
|
||||||
class Note_page( Html ):
|
|
||||||
def __init__( self, id ):
|
|
||||||
Html.__init__(
|
|
||||||
self,
|
|
||||||
Head(
|
|
||||||
Link( rel = u"stylesheet", type = u"text/css", href = u"/static/css/note.css" ),
|
|
||||||
Script( type = u"text/javascript", src = u"/static/js/MochiKit.js" ),
|
|
||||||
Script( type = u"text/javascript", src = u"/static/js/Invoker.js" ),
|
|
||||||
Meta( content = u"text/html; charset=UTF-8", http_equiv = u"content-type" ),
|
|
||||||
),
|
|
||||||
Body(
|
|
||||||
onload = u"parent.editor_loaded( '%s' );" % id,
|
|
||||||
),
|
|
||||||
)
|
|
Reference in New Issue