自然きらめき、 ひと・まちときめく、 交流のまち‚がまちわがむら.pdf · 自然きらめき、 ひと・まちときめく、 交流のまち 滋賀県米原市
pyramid_layoutと僕と、ときどきzope.interface
-
Upload
hirokiky -
Category
Technology
-
view
282 -
download
2
description
Transcript of pyramid_layoutと僕と、ときどきzope.interface
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日木曜日
最終的に<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日木曜日
折れ線グラフに必要な処理
✤ リクエストパラメーターから集計期間を取る
✤ リクエストパラメーターのバリデーションチェック
✤ 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日木曜日
▂▅▇█▓▒░('ω')░▒▓█▇▅▂
@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日木曜日
例えばこんな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日木曜日