witten
/
luminotes
Archived
1
0
Fork 0

You can now print your entire notebook.

This commit is contained in:
Dan Helfman 2009-03-02 16:39:08 -08:00
parent ecbaa091cd
commit c282570539
9 changed files with 117 additions and 5 deletions

1
NEWS
View File

@ -1,4 +1,5 @@
1.6.8: ?
* Added a link to print your entire notebook.
* Changed the order of exported HTML and CSV notebooks so that after all the
"startup" notes are included, the remaining notes are included in
alphabetical order (instead of reverse chronological order).

View File

@ -1,3 +1,3 @@
# for the benefit of py2exe
import export_html
import export_csv
import export_print

View File

@ -1,5 +1,4 @@
import re
import cherrypy
from view.Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
@ -8,7 +7,7 @@ class Html_file( Html ):
FILE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*\/files\/download\?file_id=[^"]+"[^>]*>', re.IGNORECASE )
IMAGE_PATTERN = re.compile( u'<img [^>]* ?/?>', re.IGNORECASE )
def __init__( self, notebook, notes ):
def __init__( self, notebook, notes, response_headers ):
relinked_notes = {} # map from note id to relinked note contents
# relink all note links so they point to named anchors within the page. also, for now, remove all
@ -19,7 +18,7 @@ class Html_file( Html ):
contents = self.IMAGE_PATTERN.sub( '', contents )
relinked_notes[ note.object_id ] = contents
cherrypy.response.headerMap[ u"Content-Disposition" ] = u"attachment; filename=%s.html" % notebook.friendly_id
response_headers[ u"Content-Disposition" ] = u"attachment; filename=%s.html" % notebook.friendly_id
Html.__init__(
self,
@ -38,7 +37,7 @@ class Html_file( Html ):
class_ = u"note_frame",
),
) for note in notes ],
A( "Luminotes", href = "http://luminotes.com/" ),
A( "Luminotes.com", href = "http://luminotes.com/" ),
id = u"center_area",
),
),

View File

@ -9,6 +9,7 @@ def export( database, notebook, notes, response_headers ):
return dict(
notebook = notebook,
notes = notes,
response_headers = response_headers,
view = Html_file,
manual_encode = u"utf8",
)

View File

@ -0,0 +1,39 @@
import re
from view.Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
class Print_notes( Html ):
NOTE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*(?:\/notebooks\/)?[^>]+[?&]note_id=([a-z0-9]*)"[^>]*>', re.IGNORECASE )
def __init__( self, notebook, notes ):
relinked_notes = {} # map from note id to relinked note contents
# relink all note links so they point to named anchors within the page
for note in notes:
contents = self.NOTE_LINK_PATTERN.sub( r'<a href="#note_\1">', note.contents )
relinked_notes[ note.object_id ] = contents
Html.__init__(
self,
Head(
Style( file( u"static/css/download.css" ).read(), type = u"text/css" ),
Style( file( u"static/css/print.css" ).read(), type = u"text/css" ),
Meta( content = u"text/html; charset=UTF-8", http_equiv = u"content-type" ),
Title( notebook.name ),
),
Body(
Div(
H1( notebook.name ),
[ Span(
A( name = u"note_%s" % note.object_id ),
Div(
relinked_notes[ note.object_id ],
class_ = u"note_frame",
),
) for note in notes ],
A( "Luminotes.com", href = "http://luminotes.com/" ),
id = u"center_area",
),
onload = "window.print();",
),
)

View File

@ -0,0 +1,14 @@
from Print_notes import Print_notes
def export( database, notebook, notes, response_headers ):
"""
Format the given notes for printing by relying on controller.Expose.expose() to use Print_notes
as the view.
"""
return dict(
notebook = notebook,
notes = notes,
view = Print_notes,
manual_encode = u"utf8",
)

View File

@ -21,6 +21,7 @@ body {
border: 2px solid #999999;
margin-bottom: 0.75em;
background-color: #ffffff;
clear: both;
}
h1 {
@ -59,3 +60,23 @@ ul li {
ol li {
margin-top: 0.5em;
}
img {
border-width: 0;
}
.left_justified {
float: left;
margin: 0.5em 1.5em 0.5em 0;
}
.center_justified {
display: block;
margin: 0.5em auto 0.5em auto;
text-align: center;
}
.right_justified {
float: right;
margin: 0.5em 0 0.5em 1.5em;
}

15
static/css/print.css Normal file
View File

@ -0,0 +1,15 @@
body {
background-color: #ffffff;
padding: 0;
}
#center_area {
width: 100%;
max-width: none;
}
.note_frame {
padding: 0;
border: none;
margin-bottom: 2em;
}

View File

@ -85,6 +85,17 @@ class Link_area( Div ):
class_ = u"link_area_item",
) or None,
( notebook.read_write != Notebook.READ_WRITE ) and Div(
A(
u"print",
href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
id = u"print_notebook_link",
target = u"_new",
title = u"Print this %s." % notebook_word,
),
class_ = u"link_area_item",
) or None,
( notebook.read_write == Notebook.READ_WRITE ) and Span(
Div(
( notebook.name != u"trash" ) and A(
@ -141,6 +152,17 @@ class Link_area( Div ):
class_ = u"link_area_item",
) or None,
Div(
A(
u"print",
href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
id = u"print_notebook_link",
target = u"_new",
title = u"Print this %s." % notebook_word,
),
class_ = u"link_area_item",
) or None,
( notebook.name == u"trash" ) and Rounded_div(
u"trash_notebook",
A(