• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

PythonからElixir Reportのレポートサーバーにアクセスするサンプルコード


Commit MetaInfo

修订版fcb3dc76fbaea375c4c55968ec2cadb831527ab0 (tree)
时间2014-12-03 15:41:35
作者hylom <hylom@user...>
Commiterhylom

Log Message

implement pdf function

更改概述

差异

--- a/report_server.py
+++ b/report_server.py
@@ -16,7 +16,7 @@ class ReportServer:
1616 self.cookies = None
1717 self.opener = None
1818
19- def open_path(self, path, param=None):
19+ def open_path(self, path, param=None, method='POST'):
2020 "指定したパスにリクエストを投げる"
2121 if self.opener == None:
2222 self.login()
@@ -25,7 +25,14 @@ class ReportServer:
2525 if param == None:
2626 resp = self.opener.open(url)
2727 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+
2936 return resp
3037
3138 def repository(self):
@@ -47,6 +54,17 @@ class ReportServer:
4754 else:
4855 return None
4956
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+
5068 def login(self):
5169 "ログイン処理を行う"
5270 # 初めにCookieを取得する