diff --git a/NEWS b/NEWS
index 8009a4d..2ede5c2 100644
--- a/NEWS
+++ b/NEWS
@@ -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).
diff --git a/plugins/__init__.py b/plugins/__init__.py
index a4d69c4..fa36f29 100644
--- a/plugins/__init__.py
+++ b/plugins/__init__.py
@@ -1,3 +1,3 @@
-# for the benefit of py2exe
import export_html
import export_csv
+import export_print
diff --git a/plugins/export_html/Html_file.py b/plugins/export_html/Html_file.py
index 041899e..9ab6d5d 100644
--- a/plugins/export_html/Html_file.py
+++ b/plugins/export_html/Html_file.py
@@ -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']*>', re.IGNORECASE )
IMAGE_PATTERN = re.compile( u']* ?/?>', 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",
),
),
diff --git a/plugins/export_html/__init__.py b/plugins/export_html/__init__.py
index fd62b0d..089066c 100644
--- a/plugins/export_html/__init__.py
+++ b/plugins/export_html/__init__.py
@@ -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",
)
diff --git a/plugins/export_print/Print_notes.py b/plugins/export_print/Print_notes.py
new file mode 100644
index 0000000..77c17ed
--- /dev/null
+++ b/plugins/export_print/Print_notes.py
@@ -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']+[?&]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'', 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();",
+ ),
+ )
diff --git a/plugins/export_print/__init__.py b/plugins/export_print/__init__.py
new file mode 100644
index 0000000..97c2ad9
--- /dev/null
+++ b/plugins/export_print/__init__.py
@@ -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",
+ )
diff --git a/static/css/download.css b/static/css/download.css
index 531e607..21725a1 100644
--- a/static/css/download.css
+++ b/static/css/download.css
@@ -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;
+}
diff --git a/static/css/print.css b/static/css/print.css
new file mode 100644
index 0000000..af97be0
--- /dev/null
+++ b/static/css/print.css
@@ -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;
+}
diff --git a/view/Link_area.py b/view/Link_area.py
index 77b719e..edc962c 100644
--- a/view/Link_area.py
+++ b/view/Link_area.py
@@ -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(