Browse Source

You can now print your entire notebook.

Dan Helfman 9 years ago
parent
commit
c282570539

+ 1
- 0
NEWS View File

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

+ 1
- 1
plugins/__init__.py View File

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

+ 3
- 4
plugins/export_html/Html_file.py View File

@@ -1,5 +1,4 @@
1 1
 import re
2
-import cherrypy
3 2
 from view.Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
4 3
 
5 4
 
@@ -8,7 +7,7 @@ class Html_file( Html ):
8 7
   FILE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*\/files\/download\?file_id=[^"]+"[^>]*>', re.IGNORECASE )
9 8
   IMAGE_PATTERN = re.compile( u'<img [^>]* ?/?>', re.IGNORECASE )
10 9
 
11
-  def __init__( self, notebook, notes ):
10
+  def __init__( self, notebook, notes, response_headers ):
12 11
     relinked_notes = {} # map from note id to relinked note contents
13 12
 
14 13
     # 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 ):
19 18
       contents = self.IMAGE_PATTERN.sub( '', contents )
20 19
       relinked_notes[ note.object_id ] = contents
21 20
 
22
-    cherrypy.response.headerMap[ u"Content-Disposition" ] = u"attachment; filename=%s.html" % notebook.friendly_id
21
+    response_headers[ u"Content-Disposition" ] = u"attachment; filename=%s.html" % notebook.friendly_id
23 22
 
24 23
     Html.__init__(
25 24
       self,
@@ -38,7 +37,7 @@ class Html_file( Html ):
38 37
               class_ = u"note_frame",
39 38
             ),
40 39
           ) for note in notes ],
41
-          A( "Luminotes", href = "http://luminotes.com/" ),
40
+          A( "Luminotes.com", href = "http://luminotes.com/" ),
42 41
           id = u"center_area",
43 42
         ),
44 43
       ),

+ 1
- 0
plugins/export_html/__init__.py View File

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

+ 39
- 0
plugins/export_print/Print_notes.py View File

@@ -0,0 +1,39 @@
1
+import re
2
+from view.Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
3
+
4
+
5
+class Print_notes( Html ):
6
+  NOTE_LINK_PATTERN = re.compile( u'<a\s+href="[^"]*(?:\/notebooks\/)?[^>]+[?&]note_id=([a-z0-9]*)"[^>]*>', re.IGNORECASE )
7
+
8
+  def __init__( self, notebook, notes ):
9
+    relinked_notes = {} # map from note id to relinked note contents
10
+
11
+    # relink all note links so they point to named anchors within the page
12
+    for note in notes:
13
+      contents = self.NOTE_LINK_PATTERN.sub( r'<a href="#note_\1">', note.contents )
14
+      relinked_notes[ note.object_id ] = contents
15
+
16
+    Html.__init__(
17
+      self,
18
+      Head(
19
+        Style( file( u"static/css/download.css" ).read(), type = u"text/css" ),
20
+        Style( file( u"static/css/print.css" ).read(), type = u"text/css" ),
21
+        Meta( content = u"text/html; charset=UTF-8", http_equiv = u"content-type" ),
22
+        Title( notebook.name ),
23
+      ),
24
+      Body(
25
+        Div(
26
+          H1( notebook.name ),
27
+          [ Span(
28
+            A( name = u"note_%s" % note.object_id ),
29
+            Div(
30
+              relinked_notes[ note.object_id ],
31
+              class_ = u"note_frame",
32
+            ),
33
+          ) for note in notes ],
34
+          A( "Luminotes.com", href = "http://luminotes.com/" ),
35
+          id = u"center_area",
36
+        ),
37
+        onload = "window.print();",
38
+      ),
39
+    )

+ 14
- 0
plugins/export_print/__init__.py View File

@@ -0,0 +1,14 @@
1
+from Print_notes import Print_notes
2
+
3
+
4
+def export( database, notebook, notes, response_headers ):
5
+  """
6
+  Format the given notes for printing by relying on controller.Expose.expose() to use Print_notes
7
+  as the view.
8
+  """
9
+  return dict(
10
+    notebook = notebook,
11
+    notes = notes,
12
+    view = Print_notes,
13
+    manual_encode = u"utf8",
14
+  )

+ 21
- 0
static/css/download.css View File

@@ -21,6 +21,7 @@ body {
21 21
   border: 2px solid #999999;
22 22
   margin-bottom: 0.75em;
23 23
   background-color: #ffffff;
24
+  clear: both;
24 25
 }
25 26
 
26 27
 h1 {
@@ -59,3 +60,23 @@ ul li {
59 60
 ol li {
60 61
   margin-top: 0.5em;
61 62
 }
63
+
64
+img {
65
+  border-width: 0;
66
+}
67
+
68
+.left_justified {
69
+  float: left;
70
+  margin: 0.5em 1.5em 0.5em 0;
71
+}
72
+
73
+.center_justified {
74
+  display: block;
75
+  margin: 0.5em auto 0.5em auto;
76
+  text-align: center;
77
+}
78
+
79
+.right_justified {
80
+  float: right;
81
+  margin: 0.5em 0 0.5em 1.5em;
82
+}

+ 15
- 0
static/css/print.css View File

@@ -0,0 +1,15 @@
1
+body {
2
+  background-color: #ffffff;
3
+  padding: 0;
4
+}
5
+
6
+#center_area {
7
+  width: 100%;
8
+  max-width: none;
9
+}
10
+
11
+.note_frame {
12
+  padding: 0;
13
+  border: none;
14
+  margin-bottom: 2em;
15
+}

+ 22
- 0
view/Link_area.py View File

@@ -85,6 +85,17 @@ class Link_area( Div ):
85 85
             class_ = u"link_area_item",
86 86
           ) or None,
87 87
 
88
+          ( notebook.read_write != Notebook.READ_WRITE ) and Div(
89
+            A(
90
+              u"print",
91
+              href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
92
+              id = u"print_notebook_link",
93
+              target = u"_new",
94
+              title = u"Print this %s." % notebook_word,
95
+             ),
96
+             class_ = u"link_area_item",
97
+          ) or None,
98
+
88 99
           ( notebook.read_write == Notebook.READ_WRITE ) and Span(
89 100
             Div(
90 101
               ( notebook.name != u"trash" ) and A(
@@ -141,6 +152,17 @@ class Link_area( Div ):
141 152
               class_ = u"link_area_item",
142 153
             ) or None,
143 154
 
155
+            Div(
156
+              A(
157
+                u"print",
158
+                href = u"/notebooks/export?notebook_id=%s&format=print" % notebook.object_id,
159
+                id = u"print_notebook_link",
160
+                target = u"_new",
161
+                title = u"Print this %s." % notebook_word,
162
+               ),
163
+               class_ = u"link_area_item",
164
+            ) or None,
165
+
144 166
             ( notebook.name == u"trash" ) and Rounded_div(
145 167
               u"trash_notebook",
146 168
               A(

Loading…
Cancel
Save