TicketCountTableが便利そうだったので使ってみて、改造してみた。
qの部分にカスタムフィールドを使えるように。
--- C:/Users/matobaa/Downloads/TicketCountTable-r191/TicketCountTable/ticketcounttable/TicketCountTable.py.org 12 23 22:47:44 2012
+++ C:/Users/matobaa/Downloads/TicketCountTable-r191/TicketCountTable/ticketcounttable/TicketCountTable.py 12 23 22:58:14 2012
@@ -114,7 +114,7 @@
query += " left outer join ticket_custom as cy on cy.ticket=id and cy.name='%s'" % yaxiscolname
# 条件文及びgroup値を追加
- query += " where %s group by ifnull(%s,'')" % (condition, yaxiskey)
+ query += " %s group by ifnull(%s,'')" % (condition, yaxiskey)
query += " order by 1"
#self.env.log.info(query)
@@ -239,11 +239,12 @@
# DBからデータを取得する
if custom:
# カスタムフィールドの場合
- query = u"select distinct ifnull(value,'') as v from ticket t left outer join ticket_custom c on c.ticket=t.id on c.name='%s' where %s order by 1" % (axiscolname, condition)
+ query = u"select distinct ifnull(value,'') as v from ticket t left outer join ticket_custom c on c.ticket=t.id on c.name='%s' %s order by 1" % (axiscolname, condition)
else:
# それ以外の場合
- query = u"select distinct ifnull(%s,'') as v from ticket t where %s order by 1" % (axiskey, condition)
+ query = u"select distinct ifnull(%s,'') as v from ticket t %s order by 1" % (axiskey, condition)
+ self.env.log.debug(query)
axis = []
cursor = db.cursor()
cursor.execute(query)
@@ -255,11 +256,15 @@
# int型のものに対しても文字型と同様に''で囲んでいるが、SQLiteなら大丈夫のはず。
def createcondition(self, params):
conditions = None
+ join = ''
condition = '('
if params.has_key('q'):
conditions = params['q'].split('&')
for cond in conditions:
p = cond.split('=')
+ if len([p[0] for field in TicketSystem(self.env).custom_fields if field['name'] == p[0]]) > 0:
+ join += " left outer join ticket_custom as %s on %s.ticket=id and %s.name='%s' " % (p[0],p[0],p[0],p[0])
+ p[0] += '.value'
if len(p) == 2:
if condition != '(':
condition += ') AND ('
@@ -269,6 +274,8 @@
orstrs.append("%s='%s'" % (unicode(p[0]), unicode(orcond)))
orvalues = ' OR '.join(orstrs)
condition += orvalues
+ else:
+ condition += '1=1'
condition += ')'
- return condition
+ return join + ' where ' + condition
これ、もうちょっといろいろ手を加えたい。