~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: John Arbash Meinel
  • Date: 2011-02-10 23:06:59 UTC
  • mfrom: (423.2.8 load-test)
  • Revision ID: john@arbash-meinel.com-20110210230659-ejcgl2r4z768beho
Land the load-test code into 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
 
 
21
import urllib
 
22
 
 
23
try:
 
24
    import simplejson
 
25
except ImportError:
 
26
    import json as simplejson
 
27
 
20
28
from paste.httpexceptions import HTTPServerError
21
29
 
22
30
from loggerhead import util
27
35
 
28
36
    template_path = 'loggerhead.templates.changelog'
29
37
 
30
 
    def get_values(self, h, args, kw, response):
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))
 
38
    def get_values(self, path, kwargs, headers):
 
39
        history = self._history
 
40
        revid = self.get_revid()
 
41
        filter_file_id = kwargs.get('filter_file_id', None)
 
42
        query = kwargs.get('q', None)
 
43
        start_revid = history.fix_revid(kwargs.get('start_revid', None))
39
44
        orig_start_revid = start_revid
40
45
        pagesize = 20#int(config.get('pagesize', '20'))
41
46
        search_failed = False
42
47
 
 
48
        if filter_file_id is None and path is not None:
 
49
            filter_file_id = history.get_file_id(revid, path)
 
50
 
43
51
        try:
44
 
            revid, start_revid, revid_list = h.get_view(
 
52
            revid, start_revid, revid_list = history.get_view(
45
53
                revid, start_revid, filter_file_id, query)
46
 
            util.set_context(kw)
 
54
            util.set_context(kwargs)
47
55
 
48
56
            if (query is not None) and (len(revid_list) == 0):
49
57
                search_failed = True
57
65
                    i = None
58
66
                scan_list = revid_list[i:]
59
67
            change_list = scan_list[:pagesize]
60
 
            changes = list(h.get_changes(change_list))
61
 
            h.add_changes(changes)
 
68
            changes = list(history.get_changes(change_list))
 
69
            data = {}
 
70
            for i, c in enumerate(changes):
 
71
                c.index = i
 
72
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
62
73
        except:
63
74
            self.log.exception('Exception fetching changes')
64
75
            raise HTTPServerError('Could not fetch changes')
66
77
        navigation = util.Container(
67
78
            pagesize=pagesize, revid=revid, start_revid=start_revid,
68
79
            revid_list=revid_list, filter_file_id=filter_file_id,
69
 
            scan_url='/changes', branch=self._branch, feed=True)
 
80
            scan_url='/changes', branch=self._branch, feed=True, history=history)
70
81
        if query is not None:
71
82
            navigation.query = query
72
83
        util.fill_in_navigation(navigation)
73
84
 
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
 
85
        # Directory Breadcrumbs
 
86
        directory_breadcrumbs = (
 
87
            util.directory_breadcrumbs(
 
88
                self._branch.friendly_name,
 
89
                self._branch.is_root,
 
90
                'changes'))
 
91
 
 
92
        show_tag_col = False
 
93
        for change in changes:
 
94
            if change.tags is not None:
 
95
                show_tag_col = True
 
96
                break
88
97
 
89
98
        return {
90
99
            'branch': self._branch,
91
100
            'changes': changes,
 
101
            'show_tag_col': show_tag_col,
 
102
            'data': simplejson.dumps(data),
92
103
            'util': util,
93
 
            'history': h,
 
104
            'history': history,
94
105
            'revid': revid,
95
106
            'navigation': navigation,
96
107
            'filter_file_id': filter_file_id,
97
108
            'start_revid': start_revid,
98
 
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
 
109
            'viewing_from': (orig_start_revid is not None) and
 
110
                            (orig_start_revid != history.last_revid),
99
111
            'query': query,
100
112
            'search_failed': search_failed,
101
 
            'all_same_author': all_same_author,
102
113
            'url': self._branch.context_url,
 
114
            'directory_breadcrumbs': directory_breadcrumbs,
103
115
        }