annotate modules/web_view/webview_template.py @ 16:f89ad628f831

adding the renamed files
author sean
date Wed, 05 Aug 2015 13:33:15 +0200
parents
children
rev   line source
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
1 #!/usr/bin/env python3
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
2
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
3 """ Simple Template to use the Web-View Module
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
4
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
5 author: Sean Engelhardt <sean.engelhardt@intevation.de>
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
6
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
7 (c) 2010,2015 by Intevation GmbH
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
8
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
9 This is Free Software unter the terms of the
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
10 GNU GENERAL PUBLIC LICENSE Version 3 or later.
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
11 See http://www.gnu.org/licenses/gpl-3.0.txt for details
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
12
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
13 ---
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
14 How to write a web-view module?
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
15 ---
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
16
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
17 declare a specific tile in the dash.conf. for example:
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
18
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
19 ---
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
20 [tile5]
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
21 type=d3js
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
22 div_name=webview_test
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
23 script=webview_template
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
24 ---
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
25 (this will work for this file, see dash.conf for details)
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
26
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
27 bottledash will look for a "get_chart(target_div_name)"-methode wich shall
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
28 return valid HTML-code (as string!).
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
29
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
30 the "target_div_name" is the "div_name" you delared in the dash.conf-file.
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
31 In our case, "tile5" would be in the css-class "webview_test". You can use
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
32 the "target_div_name" for dynamic DOM-Manipulations (like with d3js and jQuery)
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
33
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
34 If you want to use a python import, please use "importlib" inside the
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
35 get_chart-function.
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
36
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
37 see <https://docs.python.org/3/library/importlib.html> for details
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
38
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
39 To not try to import your own modules using the regular
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
40 python import-keyword! You can however import every regular
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
41 python-standard-library using the "import" keyword
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
42
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
43 """
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
44
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
45 import importlib
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
46
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
47 def get_chart(target_div_name):
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
48 html_string = """
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
49 <style type = text/css>
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
50
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
51 .%s {
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
52 color: red;
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
53 }
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
54
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
55 </style>
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
56
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
57 <div id = "hello">
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
58 Hello World!
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
59 </div>
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
60 """ % target_div_name
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
61
f89ad628f831 adding the renamed files
sean
parents:
diff changeset
62 return html_string
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)