17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
import json as simplejson
27
from paste.httpexceptions import HTTPServerError
24
from cherrypy import HTTPRedirect, session
29
26
from loggerhead import util
30
from loggerhead.controllers import TemplatedBranchView
33
class ChangeLogUI(TemplatedBranchView):
35
template_path = 'loggerhead.templates.changelog'
37
def get_values(self, path, kwargs, headers):
38
history = self._history
39
revid = self.get_revid()
40
filter_file_id = kwargs.get('filter_file_id', None)
41
query = kwargs.get('q', None)
42
start_revid = history.fix_revid(kwargs.get('start_revid', None))
31
class ChangeLogUI (object):
33
def __init__(self, branch):
38
@util.strip_whitespace
39
@turbogears.expose(html='loggerhead.templates.changelog')
40
def default(self, *args, **kw):
42
h = self._branch.get_history()
43
config = self._branch.config
46
revid = h.fix_revid(args[0])
50
file_id = kw.get('file_id', None)
51
query = kw.get('q', None)
52
start_revid = h.fix_revid(kw.get('start_revid', None))
43
53
orig_start_revid = start_revid
44
pagesize = 20#int(config.get('pagesize', '20'))
54
pagesize = int(config.get('pagesize', '20'))
45
55
search_failed = False
47
if filter_file_id is None and path is not None:
48
filter_file_id = history.get_file_id(revid, path)
51
revid, start_revid, revid_list = history.get_view(
52
revid, start_revid, filter_file_id, query)
53
util.set_context(kwargs)
58
revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
59
kw['start_revid'] = start_revid
55
62
if (query is not None) and (len(revid_list) == 0):
56
63
search_failed = True
58
65
if len(revid_list) == 0:
59
66
scan_list = revid_list
61
if revid in revid_list: # XXX is this always true?
62
i = revid_list.index(revid)
65
scan_list = revid_list[i:]
66
change_list = scan_list[:pagesize]
67
changes = list(history.get_changes(change_list))
69
for i, c in enumerate(changes):
71
data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
73
self.log.exception('Exception fetching changes')
74
raise HTTPServerError('Could not fetch changes')
68
scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
69
entry_list = scan_list[:pagesize]
70
entries = h.get_changes(entry_list)
72
self.log.error('Exception fetching changes: %s' % (x,))
73
util.log_exception(self.log)
74
raise HTTPRedirect(self._branch.url('/changes'))
76
navigation = util.Container(
77
pagesize=pagesize, revid=revid, start_revid=start_revid,
78
revid_list=revid_list, filter_file_id=filter_file_id,
79
scan_url='/changes', branch=self._branch, feed=True, history=history)
76
navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
77
file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
80
78
if query is not None:
81
79
navigation.query = query
82
util.fill_in_navigation(navigation)
84
# Directory Breadcrumbs
85
directory_breadcrumbs = (
86
util.directory_breadcrumbs(
87
self._branch.friendly_name,
80
util.fill_in_navigation(h, navigation)
82
entries = list(entries)
83
# add parent & merge-point branch-nick info, in case it's useful
84
h.get_branch_nicks(entries)
92
87
'branch': self._branch,
94
'data': simplejson.dumps(data),
88
'changes': list(entries),
98
92
'navigation': navigation,
99
'filter_file_id': filter_file_id,
100
94
'start_revid': start_revid,
101
'viewing_from': (orig_start_revid is not None) and
102
(orig_start_revid != history.last_revid),
95
'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
104
97
'search_failed': search_failed,
105
'url': self._branch.context_url,
106
'directory_breadcrumbs': directory_breadcrumbs,
100
self.log.info('/changes %r: %r secs' % (revid, time.time() - z))