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