PythonからElixir Reportのレポートサーバーにアクセスするサンプルコード
修订版 | fcb3dc76fbaea375c4c55968ec2cadb831527ab0 (tree) |
---|---|
时间 | 2014-12-03 15:41:35 |
作者 | hylom <hylom@user...> |
Commiter | hylom |
implement pdf function
@@ -16,7 +16,7 @@ class ReportServer: | ||
16 | 16 | self.cookies = None |
17 | 17 | self.opener = None |
18 | 18 | |
19 | - def open_path(self, path, param=None): | |
19 | + def open_path(self, path, param=None, method='POST'): | |
20 | 20 | "指定したパスにリクエストを投げる" |
21 | 21 | if self.opener == None: |
22 | 22 | self.login() |
@@ -25,7 +25,14 @@ class ReportServer: | ||
25 | 25 | if param == None: |
26 | 26 | resp = self.opener.open(url) |
27 | 27 | else: |
28 | - resp = self.opener.open(url, urllib.urlencode(param)) | |
28 | + if method == 'POST': | |
29 | + p = urllib.urlencode(param) | |
30 | + resp = self.opener.open(url, p) | |
31 | + else: | |
32 | + p = urllib.urlencode(param) | |
33 | + url_get = url + '?' + p | |
34 | + resp = self.opener.open(url_get) | |
35 | + | |
29 | 36 | return resp |
30 | 37 | |
31 | 38 | def repository(self): |
@@ -47,6 +54,17 @@ class ReportServer: | ||
47 | 54 | else: |
48 | 55 | return None |
49 | 56 | |
57 | + def pdf(self, path, params={}): | |
58 | + "レポートをPDF形式で取得する" | |
59 | + param = params.copy() | |
60 | + param["mime-type"] = "application/pdf" | |
61 | + param["elx.disposition"] = "inline" | |
62 | + resp = self.open_path(path, param, 'GET') | |
63 | + if resp.code == 200: | |
64 | + return resp.read() | |
65 | + else: | |
66 | + return None | |
67 | + | |
50 | 68 | def login(self): |
51 | 69 | "ログイン処理を行う" |
52 | 70 | # 初めにCookieを取得する |