File: ex_76_printing_translate.py

package info (click to toggle)
sqlkit 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,184 kB
  • sloc: python: 17,477; sql: 166; makefile: 95; xml: 23; sh: 11
file content (30 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""printing/preparing Context

You can customize the context you pass to the PrintTool eather subclassing
and overriding prepare_context or connecting to signal 'context-ready'
"""

from sqlkit.misc.printing import PrintTool

class MyPrinter(PrintTool):

    def prepare_context(self, context):
        """
        substitue director's films as table objects
        """
        context.translate['d'] = 'director'
        context.translate['nation'] = 'director.nation'
        return context

    

t = SqlTable(model.Movie, dbproxy=db)
t.printing = MyPrinter(t)
t.printing.add_menu_entry('Print to pdf', 'movies-translate.odt', mode='pdf',
                          accel="<alt>p",
                          tip="Generate a pdf file with these movies")
t.printing.add_menu_entry('Print to odt', 'movies-translate.odt', mode='odt',
                          tip="Generate an odt file with these movies")
t.reload()