~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Martin Albisetti
  • Date: 2009-05-27 12:52:49 UTC
  • mto: (352.6.11 serve-config)
  • mto: This revision was merged to the branch mainline in revision 364.
  • Revision ID: martin.albisetti@canonical.com-20090527125249-b9o7ajvls7jvpjf1
Less windows-ism

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