Edgewall Software

source: trunk/svntrac/Timeline.py@ 1

Last change on this file since 1 was 1, checked in by Jonas Borgström, 20 years ago

Initial import

File size: 4.3 KB
Line 
1# svntrac
2#
3# Copyright (C) 2003 Jonas Borgström <jonas@xyche.com>
4#
5# svntrac is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as
7# published by the Free Software Foundation; either version 2 of the
8# License, or (at your option) any later version.
9#
10# svntrac is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18#
19# Author: Jonas Borgström <jonas@xyche.com>
20
21from util import *
22from Module import Module
23import db
24import perm
25
26import StringIO
27import time
28
29class Timeline (Module):
30 template_key = 'timeline_template'
31
32 MAX_MESSAGE_LEN = 75
33
34 def __init__(self, config, args, pool):
35 Module.__init__(self, config, args, pool)
36
37 def get_info (self, start, stop):
38 cnx = db.get_connection()
39 cursor = cnx.cursor ()
40
41 # 1: change set
42 # 2: new tickets
43 # 3: closed tickets
44
45 cursor.execute ("SELECT time, rev AS data, 1 AS type, message "
46 "FROM revision WHERE time>=%s AND time<=%s UNION ALL "
47 "SELECT time, id AS data, 2 AS type, summary AS message "
48 "FROM ticket WHERE time>=%s AND time<=%s UNION ALL "
49 "SELECT time, ticket AS data, 3 AS type, '' AS message "
50 "FROM ticket_change WHERE field='status' "
51 "AND newvalue='closed' AND time>=%s AND time<=%s "
52 "ORDER BY time DESC, message, type",
53 start, stop, start, stop, start, stop)
54 return cursor.fetchall()
55
56 def day_separator(self, out, date):
57 if date < self.current_day:
58 self.current_day = (date / 86400) * 86400 + time.timezone
59 out.write ('<tr>')
60 out.write ('<td colspan="2" class="timeline-day">%s</td>'
61 % time.strftime('%A, %F', time.localtime(date)))
62 out.write ('</tr>')
63
64 def print_changeset (self, out, item):
65 date = int(item['time'])
66 self.day_separator (out, date)
67
68 out.write ('<tr>')
69 out.write ('<td>%s</td><td>change set [<a href="%s">%s</a>]: %s</td>'
70 % (time.strftime('%H:%M', time.localtime(date)),
71 changeset_href (item['data']),
72 item['data'], get_first_line(item['message'],
73 self.MAX_MESSAGE_LEN)))
74 out.write ('</tr>')
75
76 def print_new_ticket (self, out, item):
77 date = int(item['time'])
78 self.day_separator (out, date)
79
80 out.write ('<tr>')
81 out.write ('<td>%s</td><td>ticket <a href="%s">#%s</a> created: %s</td>'
82 % (time.strftime('%H:%M', time.localtime(date)),
83 ticket_href (item['data']), item['data'],
84 get_first_line(item['message'], self.MAX_MESSAGE_LEN)))
85 out.write ('</tr>')
86
87 def print_closed_ticket (self, out, item):
88 date = int(item['time'])
89 self.day_separator (out, date)
90
91 out.write ('<tr>')
92 out.write ('<td>%s</td><td>ticket <a href="%s">#%s</a> closed</td>'
93 % (time.strftime('%H:%M', time.localtime(date)),
94 ticket_href (item['data']), item['data']))
95 out.write ('</tr>')
96
97 def render (self):
98 perm.assert_permission (perm.TIMELINE_VIEW)
99
100 out = StringIO.StringIO()
101 stop = int(time.time() - time.timezone)
102 start = stop - 90 * 86400
103
104 info = self.get_info (start, stop)
105
106 self.current_day = stop + 1
107
108 for item in info:
109 if item['type'] == '1':
110 self.print_changeset (out, item)
111 elif item['type'] == '2':
112 self.print_new_ticket (out, item)
113 elif item['type'] == '3':
114 self.print_closed_ticket (out, item)
115
116 self.namespace['content'] = out.getvalue()
Note: See TracBrowser for help on using the repository browser.