SlideShare a Scribd company logo
1 of 25
Download to read offline
2012/5/13
pyramid_layoutと
僕と
ときどきzope.interface
hirokiky
13年5月16日木曜日
Pyramidでアプリ作る
✤ 集計アプリを作りたい
✤ panelやべぇ
13年5月16日木曜日
panelって?
✤ pyramid_layoutの一機能
✤ 部分的なview, templateをテンプレートから指定する感じ
13年5月16日木曜日
panel
@panel_config(
name='sidebar',
renderer='sakila:templates/panels/sidebar.mako'
)
def sidebar(context, request):
return dict(menus=[
(u'速報', request.route_url('home')),
(u'ランキング', '#'),
])
13年5月16日木曜日
panelのテンプレート
<div class="well sidebar-nav">
<ul class="nav nav-list">
% for menu, url in menus:
<li><a href="${url}">${menu}</a></li>
% endfor
</ul>
</div><!--/.well -->
sidebar関数の返り値がpanelのテンプレートに渡る
13年5月16日木曜日
Template
<html>
## ...
${panel('sidebar')}
## ...
</html>
実際のTemplateからはpanelの名前を指定するだけ
13年5月16日木曜日
最終的に
<html>
## ...
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li><a href="/">売上速報</a></li>
<li><a href="#">ランキング</a></li>
</ul>
</div><!--/.well -->
## ...
</html>
13年5月16日木曜日
panelやべぇ
✤ 画面要素を自由に切り貼りできる
✤ iGoogleのように画面を組み立てれるのでは
夢のよう!!
13年5月16日木曜日
できつぅあ
サイドバーpanel
折れ線グラフpanel
13年5月16日木曜日
実は
この前に一回panel諦めてviewで書いた
request.contextから値とるようにしたらpanelで書けた
13年5月16日木曜日
panel良い
✤ 好きなだけ置くことができる
✤ テンプレートから引数も取れる
13年5月16日木曜日
panelつらい
✤ NotFoundが投げれない(Templateの描画エラーになる)
✤ 画面で共通の引数を渡すのが面倒くさい
13年5月16日木曜日
折れ線グラフに必要な処理
✤ リクエストパラメーターから集計期間を取る
✤ リクエストパラメーターのバリデーションチェック
✤ DBアクセス、折れ線グラフ集計 (ペアのリスト)
✤ 折れ線グラフ化 (x, yなど分割して取れるようにする)
✤ JSライブラリ依存の形式に変換
✤ テンプレートに適切に値を与えて表示
13年5月16日木曜日
折れ線グラフに必要な処理
✤ リクエストパラメーターから集計期間を取る
✤ リクエストパラメーターのバリデーションチェック
✤ DBアクセス、折れ線グラフ集計 (ペアのリスト)
✤ 折れ線グラフ化 (x, yなど分割して取れるようにする)
✤ JSライブラリ依存の形式に変換
✤ テンプレートに適切に値を与えて表示
request.context
アダプタ
関数
panel
13年5月16日木曜日
request.context.summary
class SakilaResource(object):
# ...
@property
def linechart(self):
c = DBSession.query(
sql.func.date(Payment.payment_date).label('date'),
sql.func.sum(Payment.amount),
).
filter(self.conditions).group_by('date').all()
return c
ユーザー入力から条件を取るプロパティ
13年5月16日木曜日
panel
@panel_config(
name='linechart',
renderer='sakila:templates/panels/linechart.mako')
def line_chart(context, request, renderTo='container'):
highcharts.need()
adapter = LinechartDataAdapter(request.context.linechart)
options = daily_linechart_options(adapter.x, adapter.y,
renderTo=renderTo)
return {'options': options,
'renderTo': renderTo}
options, rendecToからHighchartsを表示
13年5月16日木曜日
( ˘⊖˘) 。o(待てよ
✤ 折れ線グラフで例えば日次、月次、年次のグラフを切り替えたい
✤ Highchartsだけでなく、その他のJSライブラリにも切り替えたい
13年5月16日木曜日
▂▅▇█▓▒░('ω')░▒▓█▇▅▂
@panel_config(
name='linechart',
renderer='sakila:templates/panels/linechart.mako')
def line_chart(context, request, renderTo='container'):
highcharts.need()
adapter = LinechartDataAdapter(request.context.linechart)
options = daily_linechart_options(adapter.x, adapter.y,
renderTo=renderTo)
return {'options': options,
'renderTo': renderTo}
何らかの指定によって色々変えたい
13年5月16日木曜日
zope.interface
✤ まずInterfaceを定めて、そこにあとから実装を付ける
✤ Adaptationしたい
13年5月16日木曜日
もさく
IResource
ILinechart
IRenderer
ResourceDailyLinechart
LinechartHighchartsRenderer
13年5月16日木曜日
もさく
list
ILinechart
IHighcharts
ListLinechart
LinechartHighcharts
13年5月16日木曜日
例えばこんなpanel
def linechart(context, request, renderTo='container', type=‘daily’):
highcharts.need()
reg = request.registry.getAdapter(request.context.linechart,
IHighchart, type)
options = reg.getOptions(renderTo=renderTo)
return dict(options=options,
renderTo=renderTo)
panelがhighchartsに依存してる
13年5月16日木曜日
あとzope.interfaceは隠したい
✤ zope.interfaceは隠すとお行儀がいいらしい
✤ 利用者(アプリ開発者)にはapiだけ提供する
✤ 開発者(ライブラリ開発者)は内部でzope.interfaceを使う
✤ まぁzope.interfaceわかりにくいし
13年5月16日木曜日
妄想色々
@tochart_config('daily.linechart.highcharts',
chart_type='linechart',
chart_backend='highcharts')
@tochart_config(‘daily.linechart.graphel’,
chart_type=‘linechart’,
chart_backend=‘graphel’)
def daily(request, data)
x = 1
y = 2
return [(x, y), (x, y)]
 
chart = tochart(request, data, 'daily.linechart.highcharts')
chart.render()
https://gist.github.com/hirokiky/5567640
13年5月16日木曜日
やってるとこです
✤ MySQLのサンプルデータベース「sakila」を集計していますのよ
✤ https://github.com/hirokiky/aggregating_sakila
13年5月16日木曜日

More Related Content

More from hirokiky

How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015hirokiky
 
価値を届ける技術 #bpstudy 96
価値を届ける技術 #bpstudy 96価値を届ける技術 #bpstudy 96
価値を届ける技術 #bpstudy 96hirokiky
 
Pycon2014 django performance
Pycon2014 django performancePycon2014 django performance
Pycon2014 django performancehirokiky
 
gargant.dispatch, a flexible dispatcher for WSGI
gargant.dispatch, a flexible dispatcher for WSGIgargant.dispatch, a flexible dispatcher for WSGI
gargant.dispatch, a flexible dispatcher for WSGIhirokiky
 
軽量のススメ
軽量のススメ軽量のススメ
軽量のススメhirokiky
 
django-websettingsの紹介
django-websettingsの紹介django-websettingsの紹介
django-websettingsの紹介hirokiky
 
My pyhack 1301
My pyhack 1301My pyhack 1301
My pyhack 1301hirokiky
 
Useful Django 1.4
Useful Django 1.4Useful Django 1.4
Useful Django 1.4hirokiky
 
使えるDjango1.4
使えるDjango1.4使えるDjango1.4
使えるDjango1.4hirokiky
 
個人の嗜好を学習し記事を推奨するフィードリーダ
個人の嗜好を学習し記事を推奨するフィードリーダ個人の嗜好を学習し記事を推奨するフィードリーダ
個人の嗜好を学習し記事を推奨するフィードリーダhirokiky
 
卒研中間発表資料:個人に最適化したフィードリーダの構築
卒研中間発表資料:個人に最適化したフィードリーダの構築卒研中間発表資料:個人に最適化したフィードリーダの構築
卒研中間発表資料:個人に最適化したフィードリーダの構築hirokiky
 

More from hirokiky (11)

How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015
 
価値を届ける技術 #bpstudy 96
価値を届ける技術 #bpstudy 96価値を届ける技術 #bpstudy 96
価値を届ける技術 #bpstudy 96
 
Pycon2014 django performance
Pycon2014 django performancePycon2014 django performance
Pycon2014 django performance
 
gargant.dispatch, a flexible dispatcher for WSGI
gargant.dispatch, a flexible dispatcher for WSGIgargant.dispatch, a flexible dispatcher for WSGI
gargant.dispatch, a flexible dispatcher for WSGI
 
軽量のススメ
軽量のススメ軽量のススメ
軽量のススメ
 
django-websettingsの紹介
django-websettingsの紹介django-websettingsの紹介
django-websettingsの紹介
 
My pyhack 1301
My pyhack 1301My pyhack 1301
My pyhack 1301
 
Useful Django 1.4
Useful Django 1.4Useful Django 1.4
Useful Django 1.4
 
使えるDjango1.4
使えるDjango1.4使えるDjango1.4
使えるDjango1.4
 
個人の嗜好を学習し記事を推奨するフィードリーダ
個人の嗜好を学習し記事を推奨するフィードリーダ個人の嗜好を学習し記事を推奨するフィードリーダ
個人の嗜好を学習し記事を推奨するフィードリーダ
 
卒研中間発表資料:個人に最適化したフィードリーダの構築
卒研中間発表資料:個人に最適化したフィードリーダの構築卒研中間発表資料:個人に最適化したフィードリーダの構築
卒研中間発表資料:個人に最適化したフィードリーダの構築
 

Recently uploaded

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 

Recently uploaded (9)

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 

pyramid_layoutと僕と、ときどきzope.interface