~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Michael Hudson
  • Date: 2007-05-23 17:42:19 UTC
  • Revision ID: michael.hudson@canonical.com-20070523174219-6lr3fgv9nciyjalu
only serve up unescaped user content with Content-Disposition: attachment

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
#
19
19
 
 
20
import os
20
21
import time
21
22
 
22
23
import turbogears
23
 
from cherrypy import InternalError
 
24
from cherrypy import InternalError, session
24
25
 
25
26
from loggerhead import util
26
 
from loggerhead.templatefunctions import templatefunctions
27
27
 
28
28
 
29
29
class ChangeLogUI (object):
34
34
        self.log = branch.log
35
35
        
36
36
    @util.strip_whitespace
37
 
    @turbogears.expose(html='zpt:loggerhead.templates.changelog')
 
37
    @turbogears.expose(html='loggerhead.templates.changelog')
38
38
    def default(self, *args, **kw):
39
39
        z = time.time()
40
40
        h = self._branch.get_history()
41
41
        config = self._branch.config
 
42
        
 
43
        if len(args) > 0:
 
44
            revid = h.fix_revid(args[0])
 
45
        else:
 
46
            revid = None
42
47
 
43
 
        h._branch.lock_read()
 
48
        file_id = kw.get('file_id', None)
 
49
        query = kw.get('q', None)
 
50
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
51
        orig_start_revid = start_revid
 
52
        pagesize = int(config.get('pagesize', '20'))
 
53
        search_failed = False
 
54
        
44
55
        try:
45
 
            if len(args) > 0:
46
 
                revid = h.fix_revid(args[0])
 
56
            revid, start_revid, revid_list = h.get_view(revid, start_revid, file_id, query)
 
57
            kw['start_revid'] = start_revid
 
58
            util.set_context(kw)
 
59
            
 
60
            if (query is not None) and (len(revid_list) == 0):
 
61
                search_failed = True
 
62
 
 
63
            if len(revid_list) == 0:
 
64
                scan_list = revid_list
47
65
            else:
48
 
                revid = None
49
 
 
50
 
            filter_file_id = kw.get('filter_file_id', None)
51
 
            query = kw.get('q', None)
52
 
            start_revid = h.fix_revid(kw.get('start_revid', None))
53
 
            orig_start_revid = start_revid
54
 
            pagesize = int(config.get('pagesize', '20'))
55
 
            search_failed = False
56
 
 
57
 
            try:
58
 
                revid, start_revid, revid_list = h.get_view(
59
 
                    revid, start_revid, filter_file_id, query)
60
 
                kw['start_revid'] = start_revid
61
 
                util.set_context(kw)
62
 
 
63
 
                if (query is not None) and (len(revid_list) == 0):
64
 
                    search_failed = True
65
 
 
66
 
                if len(revid_list) == 0:
67
 
                    scan_list = revid_list
68
 
                else:
69
 
                    if revid in revid_list: # XXX is this always true?
70
 
                        i = revid_list.index(revid)
71
 
                    else:
72
 
                        i = None
73
 
                    scan_list = revid_list[i:]
74
 
                change_list = scan_list[:pagesize]
75
 
                changes = list(h.get_changes(change_list))
76
 
                h.add_changes(changes)
77
 
            except:
78
 
                self.log.exception('Exception fetching changes')
79
 
                raise InternalError('Could not fetch changes')
80
 
 
81
 
            navigation = util.Container(
82
 
                pagesize=pagesize, revid=revid, start_revid=start_revid,
83
 
                revid_list=revid_list, filter_file_id=filter_file_id,
84
 
                scan_url='/changes', branch=self._branch, feed=True)
85
 
            if query is not None:
86
 
                navigation.query = query
87
 
            util.fill_in_navigation(navigation)
88
 
 
89
 
            # add parent & merge-point branch-nick info, in case it's useful
90
 
            h.get_branch_nicks(changes)
91
 
 
92
 
            # does every change on this page have the same committer?  if so,
93
 
            # tell the template to show committer info in the "details block"
94
 
            # instead of on each line.
95
 
            all_same_author = True
96
 
 
97
 
            if changes:
98
 
                author = changes[0].author
99
 
                for e in changes[1:]:
100
 
                    if e.author != author:
101
 
                        all_same_author = False
102
 
                        break
103
 
 
104
 
            def url(pathargs, **kw):
105
 
                return self._branch.url(pathargs, **util.get_context(**kw))
106
 
 
107
 
            vals = {
108
 
                'branch': self._branch,
109
 
                'changes': changes,
110
 
                'util': util,
111
 
                'history': h,
112
 
                'revid': revid,
113
 
                'navigation': navigation,
114
 
                'filter_file_id': filter_file_id,
115
 
                'start_revid': start_revid,
116
 
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
117
 
                'query': query,
118
 
                'search_failed': search_failed,
119
 
                'all_same_author': all_same_author,
120
 
                'url': url,
121
 
            }
122
 
            vals.update(templatefunctions)
123
 
            h.flush_cache()
124
 
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
125
 
            return vals
126
 
        finally:
127
 
            h._branch.unlock()
 
66
                scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
 
67
            entry_list = scan_list[:pagesize]
 
68
            entries = h.get_changes(entry_list)
 
69
        except:
 
70
            self.log.exception('Exception fetching changes')
 
71
            raise InternalError('Could not fetch changes')
 
72
 
 
73
        navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
 
74
                                    file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
 
75
        if query is not None:
 
76
            navigation.query = query
 
77
        util.fill_in_navigation(h, navigation)
 
78
        
 
79
        entries = list(entries)
 
80
        # add parent & merge-point branch-nick info, in case it's useful
 
81
        h.get_branch_nicks(entries)
 
82
 
 
83
        vals = {
 
84
            'branch': self._branch,
 
85
            'changes': list(entries),
 
86
            'util': util,
 
87
            'history': h,
 
88
            'revid': revid,
 
89
            'navigation': navigation,
 
90
            'file_id': file_id,
 
91
            'start_revid': start_revid,
 
92
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
93
            'query': query,
 
94
            'search_failed': search_failed,
 
95
        }
 
96
        h.flush_cache()
 
97
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
98
        return vals