~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

[rs=thumper][!log] Michael Hudson's branch to apply the new
        loggerhead theme - failed previously due to transient PQM issues

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 time
21
 
 
22
20
from paste.httpexceptions import HTTPServerError
23
 
from paste.request import path_info_pop
24
21
 
25
22
from loggerhead import util
26
 
from loggerhead.templatefunctions import templatefunctions
27
 
 
28
 
 
29
 
from turbosimpletal import TurboZpt
30
 
 
31
 
t = TurboZpt()
32
 
tt = t.load_template('loggerhead.templates.changelog')
33
 
 
34
 
class ChangeLogUI (object):
35
 
    
36
 
    def __init__(self, branch):
37
 
        # BranchView object
38
 
        self._branch = branch
39
 
        self.log = branch.log
40
 
        
41
 
    def default(self, request, response):
42
 
        z = time.time()
43
 
        h = self._branch.history
44
 
        #config = self._branch.config
45
 
 
46
 
        h._branch.lock_read()
 
23
from loggerhead.controllers import TemplatedBranchView
 
24
 
 
25
 
 
26
class ChangeLogUI(TemplatedBranchView):
 
27
 
 
28
    template_path = 'loggerhead.templates.changelog'
 
29
 
 
30
    def get_values(self, h, args, kw, headers):
 
31
        if args:
 
32
            revid = h.fix_revid(args[0])
 
33
        else:
 
34
            revid = None
 
35
 
 
36
        filter_file_id = kw.get('filter_file_id', None)
 
37
        query = kw.get('q', None)
 
38
        start_revid = h.fix_revid(kw.get('start_revid', None))
 
39
        orig_start_revid = start_revid
 
40
        pagesize = 20#int(config.get('pagesize', '20'))
 
41
        search_failed = False
 
42
 
47
43
        try:
48
 
            kw = request.GET
49
 
            arg = path_info_pop(request.environ)
50
 
            if arg:
51
 
                revid = h.fix_revid(arg)
 
44
            revid, start_revid, revid_list = h.get_view(
 
45
                revid, start_revid, filter_file_id, query)
 
46
            util.set_context(kw)
 
47
 
 
48
            if (query is not None) and (len(revid_list) == 0):
 
49
                search_failed = True
 
50
 
 
51
            if len(revid_list) == 0:
 
52
                scan_list = revid_list
52
53
            else:
53
 
                revid = None
54
 
 
55
 
            filter_file_id = kw.get('filter_file_id', None)
56
 
            query = kw.get('q', None)
57
 
            start_revid = h.fix_revid(kw.get('start_revid', None))
58
 
            orig_start_revid = start_revid
59
 
            pagesize = 20#int(config.get('pagesize', '20'))
60
 
            search_failed = False
61
 
 
62
 
            try:
63
 
                revid, start_revid, revid_list = h.get_view(
64
 
                    revid, start_revid, filter_file_id, query)
65
 
                util.set_context(kw)
66
 
 
67
 
                if (query is not None) and (len(revid_list) == 0):
68
 
                    search_failed = True
69
 
 
70
 
                if len(revid_list) == 0:
71
 
                    scan_list = revid_list
 
54
                if revid in revid_list: # XXX is this always true?
 
55
                    i = revid_list.index(revid)
72
56
                else:
73
 
                    if revid in revid_list: # XXX is this always true?
74
 
                        i = revid_list.index(revid)
75
 
                    else:
76
 
                        i = None
77
 
                    scan_list = revid_list[i:]
78
 
                change_list = scan_list[:pagesize]
79
 
                changes = list(h.get_changes(change_list))
80
 
                h.add_changes(changes)
81
 
            except:
82
 
                self.log.exception('Exception fetching changes')
83
 
                raise HTTPServerError('Could not fetch changes')
84
 
 
85
 
            navigation = util.Container(
86
 
                pagesize=pagesize, revid=revid, start_revid=start_revid,
87
 
                revid_list=revid_list, filter_file_id=filter_file_id,
88
 
                scan_url='/changes', branch=self._branch, feed=True)
89
 
            if query is not None:
90
 
                navigation.query = query
91
 
            util.fill_in_navigation(navigation)
92
 
 
93
 
            # add parent & merge-point branch-nick info, in case it's useful
94
 
            h.get_branch_nicks(changes)
95
 
 
96
 
            # does every change on this page have the same committer?  if so,
97
 
            # tell the template to show committer info in the "details block"
98
 
            # instead of on each line.
99
 
            all_same_author = True
100
 
 
101
 
            if changes:
102
 
                author = changes[0].author
103
 
                for e in changes[1:]:
104
 
                    if e.author != author:
105
 
                        all_same_author = False
106
 
                        break
107
 
 
108
 
            def url(pathargs, **kw):
109
 
                return self._branch.url(pathargs, **kw)
110
 
 
111
 
            vals = {
112
 
                'branch': self._branch,
113
 
                'changes': changes,
114
 
                'util': util,
115
 
                'history': h,
116
 
                'revid': revid,
117
 
                'navigation': navigation,
118
 
                'filter_file_id': filter_file_id,
119
 
                'start_revid': start_revid,
120
 
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
121
 
                'query': query,
122
 
                'search_failed': search_failed,
123
 
                'all_same_author': all_same_author,
124
 
                'url': self._branch.context_url,
125
 
            }
126
 
            vals.update(templatefunctions)
127
 
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
128
 
            response.headers['Content-Type'] = 'text/html'
129
 
            tt.expand_(response, **vals)
130
 
        finally:
131
 
            h._branch.unlock()
 
57
                    i = None
 
58
                scan_list = revid_list[i:]
 
59
            change_list = scan_list[:pagesize]
 
60
            changes = list(h.get_changes(change_list))
 
61
            h.add_changes(changes)
 
62
        except:
 
63
            self.log.exception('Exception fetching changes')
 
64
            raise HTTPServerError('Could not fetch changes')
 
65
 
 
66
        navigation = util.Container(
 
67
            pagesize=pagesize, revid=revid, start_revid=start_revid,
 
68
            revid_list=revid_list, filter_file_id=filter_file_id,
 
69
            scan_url='/changes', branch=self._branch, feed=True, history=h)
 
70
        if query is not None:
 
71
            navigation.query = query
 
72
        util.fill_in_navigation(navigation)
 
73
 
 
74
        # add parent & merge-point branch-nick info, in case it's useful
 
75
        h.get_branch_nicks(changes)
 
76
 
 
77
        # does every change on this page have the same committer?  if so,
 
78
        # tell the template to show committer info in the "details block"
 
79
        # instead of on each line.
 
80
        all_same_author = True
 
81
 
 
82
        if changes:
 
83
            author = changes[0].author
 
84
            for e in changes[1:]:
 
85
                if e.author != author:
 
86
                    all_same_author = False
 
87
                    break
 
88
 
 
89
        return {
 
90
            'branch': self._branch,
 
91
            'changes': changes,
 
92
            'util': util,
 
93
            'history': h,
 
94
            'revid': revid,
 
95
            'navigation': navigation,
 
96
            'filter_file_id': filter_file_id,
 
97
            'start_revid': start_revid,
 
98
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
99
            'query': query,
 
100
            'search_failed': search_failed,
 
101
            'all_same_author': all_same_author,
 
102
            'url': self._branch.context_url,
 
103
        }