~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Max Bowsher
  • Date: 2011-03-04 15:49:43 UTC
  • mfrom: (431 trunk-rich)
  • mto: This revision was merged to the branch mainline in revision 432.
  • Revision ID: maxb@f2s.com-20110304154943-zrtlx1ipy49xc8u0
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
 
2
# Copyright (C) 2008, 2009 Canonical Ltd.
2
3
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
3
4
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
4
5
#
17
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
19
#
19
20
 
20
 
import os
21
 
import time
22
 
 
23
 
import turbogears
24
 
from cherrypy import InternalError, session
 
21
import urllib
 
22
 
 
23
import simplejson
 
24
 
 
25
from paste.httpexceptions import HTTPServerError
25
26
 
26
27
from loggerhead import util
27
 
 
28
 
 
29
 
class ChangeLogUI (object):
30
 
    
31
 
    def __init__(self, branch):
32
 
        # BranchView object
33
 
        self._branch = branch
34
 
        self.log = branch.log
35
 
        
36
 
    @util.strip_whitespace
37
 
    @turbogears.expose(html='loggerhead.templates.changelog')
38
 
    def default(self, *args, **kw):
39
 
        z = time.time()
40
 
        h = self._branch.get_history()
41
 
        config = self._branch.config
42
 
 
43
 
        h._branch.lock_read()
 
28
from loggerhead.controllers import TemplatedBranchView
 
29
 
 
30
 
 
31
class ChangeLogUI(TemplatedBranchView):
 
32
 
 
33
    template_path = 'loggerhead.templates.changelog'
 
34
 
 
35
    def get_values(self, path, kwargs, headers):
 
36
        history = self._history
 
37
        revid = self.get_revid()
 
38
        filter_file_id = kwargs.get('filter_file_id', None)
 
39
        query = kwargs.get('q', None)
 
40
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
 
41
        orig_start_revid = start_revid
 
42
        pagesize = 20#int(config.get('pagesize', '20'))
 
43
        search_failed = False
 
44
 
 
45
        if filter_file_id is None and path is not None:
 
46
            filter_file_id = history.get_file_id(revid, path)
 
47
 
44
48
        try:
45
 
            if len(args) > 0:
46
 
                revid = h.fix_revid(args[0])
 
49
            revid, start_revid, revid_list = history.get_view(
 
50
                revid, start_revid, filter_file_id, query)
 
51
            util.set_context(kwargs)
 
52
 
 
53
            if (query is not None) and (len(revid_list) == 0):
 
54
                search_failed = True
 
55
 
 
56
            if len(revid_list) == 0:
 
57
                scan_list = revid_list
47
58
            else:
48
 
                revid = None
49
 
 
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))
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(revid, start_revid, file_id, query)
59
 
                kw['start_revid'] = start_revid
60
 
                util.set_context(kw)
61
 
 
62
 
                if (query is not None) and (len(revid_list) == 0):
63
 
                    search_failed = True
64
 
 
65
 
                if len(revid_list) == 0:
66
 
                    scan_list = revid_list
 
59
                if revid in revid_list: # XXX is this always true?
 
60
                    i = revid_list.index(revid)
67
61
                else:
68
 
                    if revid in revid_list: # XXX is this always true?
69
 
                        i = revid_list.index(revid)
70
 
                    else:
71
 
                        i = None
72
 
                    scan_list = revid_list[i:]
73
 
                change_list = scan_list[:pagesize]
74
 
                changes = list(h.get_changes(change_list))
75
 
                h.add_changes(changes)
76
 
            except:
77
 
                self.log.exception('Exception fetching changes')
78
 
                raise InternalError('Could not fetch changes')
79
 
 
80
 
            navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
81
 
                                        file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
82
 
            if query is not None:
83
 
                navigation.query = query
84
 
            util.fill_in_navigation(navigation)
85
 
 
86
 
            # add parent & merge-point branch-nick info, in case it's useful
87
 
            h.get_branch_nicks(changes)
88
 
 
89
 
            # does every change on this page have the same committer?  if so,
90
 
            # tell the template to show committer info in the "details block"
91
 
            # instead of on each line.
92
 
            all_same_author = True
93
 
 
94
 
            if changes:
95
 
                author = changes[0].author
96
 
                for e in changes[1:]:
97
 
                    if e.author != author:
98
 
                        all_same_author = False
99
 
                        break
100
 
 
101
 
            vals = {
102
 
                'branch': self._branch,
103
 
                'changes': changes,
104
 
                'util': util,
105
 
                'history': h,
106
 
                'revid': revid,
107
 
                'navigation': navigation,
108
 
                'file_id': file_id,
109
 
                'start_revid': start_revid,
110
 
                'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
111
 
                'query': query,
112
 
                'search_failed': search_failed,
113
 
                'all_same_author': all_same_author,
114
 
            }
115
 
            h.flush_cache()
116
 
            self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
117
 
            return vals
118
 
        finally:
119
 
            h._branch.unlock()
 
62
                    i = None
 
63
                scan_list = revid_list[i:]
 
64
            change_list = scan_list[:pagesize]
 
65
            changes = list(history.get_changes(change_list))
 
66
            data = {}
 
67
            for i, c in enumerate(changes):
 
68
                c.index = i
 
69
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
 
70
        except:
 
71
            self.log.exception('Exception fetching changes')
 
72
            raise HTTPServerError('Could not fetch changes')
 
73
 
 
74
        navigation = util.Container(
 
75
            pagesize=pagesize, revid=revid, start_revid=start_revid,
 
76
            revid_list=revid_list, filter_file_id=filter_file_id,
 
77
            scan_url='/changes', branch=self._branch, feed=True, history=history)
 
78
        if query is not None:
 
79
            navigation.query = query
 
80
        util.fill_in_navigation(navigation)
 
81
 
 
82
        # Directory Breadcrumbs
 
83
        directory_breadcrumbs = (
 
84
            util.directory_breadcrumbs(
 
85
                self._branch.friendly_name,
 
86
                self._branch.is_root,
 
87
                'changes'))
 
88
 
 
89
        show_tag_col = False
 
90
        for change in changes:
 
91
            if change.tags is not None:
 
92
                show_tag_col = True
 
93
                break
 
94
 
 
95
        return {
 
96
            'branch': self._branch,
 
97
            'changes': changes,
 
98
            'show_tag_col': show_tag_col,
 
99
            'data': simplejson.dumps(data),
 
100
            'util': util,
 
101
            'history': history,
 
102
            'revid': revid,
 
103
            'navigation': navigation,
 
104
            'filter_file_id': filter_file_id,
 
105
            'start_revid': start_revid,
 
106
            'viewing_from': (orig_start_revid is not None) and
 
107
                            (orig_start_revid != history.last_revid),
 
108
            'query': query,
 
109
            'search_failed': search_failed,
 
110
            'url': self._branch.context_url,
 
111
            'directory_breadcrumbs': directory_breadcrumbs,
 
112
        }