2007-09-26 23:49:27 +00:00
|
|
|
from cgi import escape
|
2007-07-16 20:22:38 +00:00
|
|
|
from Page import Page
|
2007-11-28 23:17:58 +00:00
|
|
|
from Tags import Input, Div, Span, H2, H4, A, Br, Strong, Script, Img
|
2007-07-16 20:22:38 +00:00
|
|
|
from Search_form import Search_form
|
2007-10-16 21:37:12 +00:00
|
|
|
from User_area import User_area
|
2007-07-16 20:22:38 +00:00
|
|
|
from Link_area import Link_area
|
|
|
|
from Toolbar import Toolbar
|
2007-10-16 21:37:12 +00:00
|
|
|
from Json import Json
|
2007-10-31 07:46:02 +00:00
|
|
|
from Rounded_div import Rounded_div
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Main_page( Page ):
|
2007-10-16 21:37:12 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
user,
|
|
|
|
rate_plan,
|
|
|
|
notebooks,
|
|
|
|
notebook,
|
|
|
|
parent_id = None,
|
|
|
|
login_url = None,
|
|
|
|
logout_url = None,
|
|
|
|
startup_notes = None,
|
2007-10-19 20:24:16 +00:00
|
|
|
total_notes_count = None,
|
2007-10-30 23:05:46 +00:00
|
|
|
notes = None,
|
2007-10-16 21:37:12 +00:00
|
|
|
note_read_write = True,
|
2007-11-10 01:46:56 +00:00
|
|
|
start = None,
|
|
|
|
count = None,
|
2007-11-10 03:57:27 +00:00
|
|
|
http_url = None,
|
2007-11-12 10:51:31 +00:00
|
|
|
conversion = None,
|
2007-11-15 23:46:30 +00:00
|
|
|
rename = False,
|
2007-11-17 04:21:48 +00:00
|
|
|
deleted_id = None,
|
2007-12-12 00:52:34 +00:00
|
|
|
invites = None,
|
2007-12-27 22:16:47 +00:00
|
|
|
invite_id = None,
|
2008-01-10 08:33:19 +00:00
|
|
|
after_login = None,
|
2007-10-16 21:37:12 +00:00
|
|
|
):
|
|
|
|
startup_note_ids = [ startup_note.object_id for startup_note in startup_notes ]
|
|
|
|
|
|
|
|
static_notes = Div(
|
2007-10-30 23:05:46 +00:00
|
|
|
notes and [ Div(
|
2007-10-16 21:37:12 +00:00
|
|
|
note.contents,
|
|
|
|
id = "static_note_%s" % note.object_id,
|
2007-10-30 23:05:46 +00:00
|
|
|
) for note in notes ] or
|
2007-10-16 21:37:12 +00:00
|
|
|
[ Div(
|
|
|
|
startup_note.contents,
|
|
|
|
id = "static_note_%s" % startup_note.object_id
|
|
|
|
) for startup_note in startup_notes ],
|
|
|
|
id = "static_notes",
|
|
|
|
)
|
|
|
|
|
|
|
|
# Since the contents of these notes are included in the static_notes section below, don't
|
|
|
|
# include them again in the hidden fields here. Accomplish this by making custom dicts for
|
|
|
|
# sending to the client.
|
|
|
|
startup_note_dicts = [ {
|
|
|
|
u"object_id" : startup_note.object_id,
|
|
|
|
u"revision" : startup_note.revision,
|
|
|
|
u"deleted_from_id" : startup_note.deleted_from_id,
|
|
|
|
} for startup_note in startup_notes ]
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-10-30 23:05:46 +00:00
|
|
|
note_dicts = [ {
|
|
|
|
u"object_id" : note.object_id,
|
|
|
|
u"revision" : note.revision,
|
|
|
|
u"deleted_from_id" : note.deleted_from_id,
|
|
|
|
u"creation" : note.creation,
|
|
|
|
} for note in notes ]
|
2007-10-16 21:37:12 +00:00
|
|
|
|
|
|
|
def json( string ):
|
|
|
|
return escape( unicode( Json( string ) ), quote = True )
|
|
|
|
|
2007-11-08 20:55:45 +00:00
|
|
|
if len( notes ) == 1:
|
|
|
|
title = notes[ 0 ].title
|
|
|
|
else:
|
|
|
|
title = None
|
|
|
|
|
2007-11-10 01:46:56 +00:00
|
|
|
if notebook.name == u"Luminotes":
|
|
|
|
notebook_path = u"/"
|
|
|
|
elif notebook.name == u"Luminotes user guide":
|
|
|
|
notebook_path = u"/guide"
|
|
|
|
elif notebook.name == u"Luminotes blog":
|
|
|
|
notebook_path = u"/blog"
|
|
|
|
else:
|
|
|
|
notebook_path = u"/notebooks/%s" % notebook.object_id
|
|
|
|
|
2007-11-12 10:51:31 +00:00
|
|
|
conversion_html = None
|
|
|
|
|
|
|
|
if conversion:
|
|
|
|
try:
|
|
|
|
conversion_html = file( u"static/html/%s_conversion.html" % conversion ).read()
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
2007-07-16 20:22:38 +00:00
|
|
|
Page.__init__(
|
|
|
|
self,
|
|
|
|
title,
|
2008-03-01 00:26:06 +00:00
|
|
|
Script( type = u"text/javascript", src = u"/static/js/MochiKit.js" ) or None,
|
|
|
|
Script( type = u"text/javascript", src = u"/static/js/Invoker.js" ) or None,
|
|
|
|
Script( type = u"text/javascript", src = u"/static/js/Editor.js" ) or None,
|
|
|
|
Script( type = u"text/javascript", src = u"/static/js/Wiki.js" ) or None,
|
2007-10-16 21:37:12 +00:00
|
|
|
Input( type = u"hidden", name = u"storage_bytes", id = u"storage_bytes", value = user.storage_bytes ),
|
|
|
|
Input( type = u"hidden", name = u"rate_plan", id = u"rate_plan", value = json( rate_plan ) ),
|
|
|
|
Input( type = u"hidden", name = u"notebooks", id = u"notebooks", value = json( notebooks ) ),
|
|
|
|
Input( type = u"hidden", name = u"notebook_id", id = u"notebook_id", value = notebook.object_id ),
|
2007-08-29 00:50:46 +00:00
|
|
|
Input( type = u"hidden", name = u"parent_id", id = u"parent_id", value = parent_id or "" ),
|
2007-10-16 21:37:12 +00:00
|
|
|
Input( type = u"hidden", name = u"startup_notes", id = u"startup_notes", value = json( startup_note_dicts ) ),
|
2007-10-30 23:05:46 +00:00
|
|
|
Input( type = u"hidden", name = u"current_notes", id = u"current_notes", value = json( note_dicts ) ),
|
2007-10-16 21:37:12 +00:00
|
|
|
Input( type = u"hidden", name = u"note_read_write", id = u"note_read_write", value = json( note_read_write ) ),
|
2007-11-15 23:46:30 +00:00
|
|
|
Input( type = u"hidden", name = u"rename", id = u"rename", value = json( rename ) ),
|
2007-11-17 04:21:48 +00:00
|
|
|
Input( type = u"hidden", name = u"deleted_id", id = u"deleted_id", value = deleted_id ),
|
2007-12-12 00:52:34 +00:00
|
|
|
Input( type = u"hidden", name = u"invites", id = u"invites", value = json( invites ) ),
|
2007-12-27 22:16:47 +00:00
|
|
|
Input( type = u"hidden", name = u"invite_id", id = u"invite_id", value = invite_id ),
|
2008-01-10 08:33:19 +00:00
|
|
|
Input( type = u"hidden", name = u"after_login", id = u"after_login", value = after_login ),
|
2007-07-16 20:22:38 +00:00
|
|
|
Div(
|
|
|
|
id = u"status_area",
|
|
|
|
),
|
|
|
|
Div(
|
2007-09-27 22:11:16 +00:00
|
|
|
Div(
|
|
|
|
Br(),
|
2008-01-22 20:29:29 +00:00
|
|
|
Toolbar( hide_toolbar = parent_id or not notebook.read_write ),
|
2007-09-27 22:11:16 +00:00
|
|
|
id = u"toolbar_area",
|
|
|
|
),
|
2007-11-15 22:55:57 +00:00
|
|
|
Link_area( notebooks, notebook, total_notes_count, parent_id, notebook_path, user ),
|
2007-07-16 20:22:38 +00:00
|
|
|
Div(
|
|
|
|
Div(
|
|
|
|
Div(
|
2007-10-16 21:37:12 +00:00
|
|
|
User_area( user, login_url, logout_url ),
|
2007-07-16 20:22:38 +00:00
|
|
|
Div(
|
|
|
|
Search_form(),
|
|
|
|
id = u"search_area",
|
|
|
|
),
|
|
|
|
id = u"search_and_user_area",
|
|
|
|
),
|
|
|
|
Div(
|
2008-03-01 00:26:06 +00:00
|
|
|
A( Img( src = u"/static/images/luminotes_title_full.png", width = u"206", height = u"69" ), href = u"/", title = u"Luminotes personal wiki notebook" ),
|
2007-07-16 20:22:38 +00:00
|
|
|
id = u"title_area",
|
|
|
|
),
|
|
|
|
id = u"top_area",
|
|
|
|
),
|
2007-10-31 07:46:02 +00:00
|
|
|
Rounded_div(
|
|
|
|
( notebook.name == u"trash" ) and u"trash_notebook" or u"current_notebook",
|
2007-11-16 00:26:27 +00:00
|
|
|
( notebook.name == u"trash" or not notebook.read_write ) \
|
2007-11-16 00:46:37 +00:00
|
|
|
and (
|
|
|
|
len( notes ) == 1 and A( Strong( notebook.name ), href = notebook_path ) or Strong( notebook.name )
|
|
|
|
) \
|
2007-11-16 00:26:27 +00:00
|
|
|
or Span( Strong( notebook.name ), id = u"notebook_header_name" ),
|
2007-10-16 21:37:12 +00:00
|
|
|
parent_id and Span(
|
|
|
|
u" | ",
|
|
|
|
A( u"empty trash", href = u"/notebooks/%s" % notebook.object_id, id = u"empty_trash_link" ),
|
|
|
|
u" | ",
|
|
|
|
A( u"return to notebook", href = u"/notebooks/%s" % parent_id ),
|
|
|
|
) or None,
|
2007-08-28 20:36:33 +00:00
|
|
|
id = u"notebook_header_area",
|
2007-10-31 07:46:02 +00:00
|
|
|
corners = ( u"tl", u"tr", u"br" ),
|
2007-08-28 20:36:33 +00:00
|
|
|
),
|
|
|
|
Div(
|
2007-10-31 07:46:02 +00:00
|
|
|
Rounded_div(
|
|
|
|
( notebook.name == u"trash" ) and u"trash_notebook_inner" or u"current_notebook_inner",
|
2007-11-17 22:55:13 +00:00
|
|
|
Div(
|
|
|
|
id = u"deleted_notebooks",
|
|
|
|
),
|
2007-08-28 20:36:33 +00:00
|
|
|
Div(
|
2007-11-09 06:49:26 +00:00
|
|
|
Span( id = u"notes_top" ),
|
2007-08-28 20:36:33 +00:00
|
|
|
id = u"notes",
|
|
|
|
),
|
2007-10-27 03:22:34 +00:00
|
|
|
notebook.read_write and Div(
|
|
|
|
id = u"blank_note_stub",
|
|
|
|
class_ = u"blank_note_stub_hidden_border",
|
|
|
|
) or None,
|
2007-10-16 21:37:12 +00:00
|
|
|
static_notes,
|
|
|
|
# Sort of simulate the <noscript> tag by hiding the static version of the notes.
|
|
|
|
# This code won't be executed if JavaScript is disabled. I'm not actually using
|
|
|
|
# <noscript> because I want to be able to programmatically read the hidden static
|
|
|
|
# notes when JavaScript is enabled.
|
|
|
|
Script(
|
|
|
|
u"document.getElementById( 'static_notes' ).style.display = 'none';",
|
|
|
|
type = u"text/javascript",
|
|
|
|
),
|
2007-11-10 01:46:56 +00:00
|
|
|
# make page navigation for those notebooks that require it (such as the blog)
|
2007-11-10 03:57:27 +00:00
|
|
|
( start is not None and count is not None and len( notes ) > 1 ) and Div(
|
2007-11-10 01:46:56 +00:00
|
|
|
( start > 0 ) and Div( A(
|
|
|
|
u"previous page",
|
|
|
|
href = "%s?start=%d&count=%d" % ( notebook_path, max( start - count, 0 ), count ),
|
|
|
|
) ) or None,
|
|
|
|
( start + count < total_notes_count ) and Div( A(
|
2007-11-10 07:08:55 +00:00
|
|
|
u"next page",
|
2007-11-10 01:46:56 +00:00
|
|
|
href = "%s?start=%d&count=%d" % ( notebook_path, min( start + count, total_notes_count - 1 ), count ),
|
|
|
|
) ) or None,
|
|
|
|
) or None,
|
2007-08-28 20:36:33 +00:00
|
|
|
id = u"notebook_background",
|
2007-10-31 07:46:02 +00:00
|
|
|
corners = ( u"tl", ),
|
2007-08-28 20:36:33 +00:00
|
|
|
),
|
|
|
|
id = u"notebook_border",
|
2007-10-31 07:46:02 +00:00
|
|
|
class_ = ( notebook.name == u"trash" ) and u"trash_notebook_color" or u"current_notebook_color",
|
2007-07-20 19:11:22 +00:00
|
|
|
),
|
2007-07-16 20:22:38 +00:00
|
|
|
id = u"center_area",
|
|
|
|
),
|
2007-11-12 10:51:31 +00:00
|
|
|
Div(
|
|
|
|
conversion_html,
|
|
|
|
id = u"conversion_area",
|
|
|
|
),
|
2007-09-23 20:42:44 +00:00
|
|
|
id = u"everything_area",
|
2007-07-16 20:22:38 +00:00
|
|
|
),
|
|
|
|
)
|