~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/changelog_ui.py

  • Committer: Robey Pointer
  • Date: 2007-05-21 07:46:30 UTC
  • Revision ID: robey@lag.net-20070521074630-afkk5g3x2654wfpm
bug 113313: remove 0x0C (page break) from the list of characters that
identify a file as binary.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# Copyright (C) 2008, 2009 Canonical Ltd.
3
2
# Copyright (C) 2006  Robey Pointer <robey@lag.net>
4
3
# Copyright (C) 2006  Goffredo Baroncelli <kreijack@inwind.it>
5
4
#
18
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
18
#
20
19
 
21
 
import urllib
22
 
 
23
 
import simplejson
24
 
 
25
 
from paste.httpexceptions import HTTPServerError
 
20
import os
 
21
import time
 
22
 
 
23
import turbogears
 
24
from cherrypy import InternalError, session
26
25
 
27
26
from loggerhead import util
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))
 
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
        if len(args) > 0:
 
44
            revid = h.fix_revid(args[0])
 
45
        else:
 
46
            revid = None
 
47
 
 
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))
41
51
        orig_start_revid = start_revid
42
 
        pagesize = 20#int(config.get('pagesize', '20'))
 
52
        pagesize = int(config.get('pagesize', '20'))
43
53
        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
 
 
 
54
        
48
55
        try:
49
 
            revid, start_revid, revid_list = history.get_view(
50
 
                revid, start_revid, filter_file_id, query,
51
 
                extra_rev_count=pagesize+1)
52
 
            util.set_context(kwargs)
53
 
 
 
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
            
54
60
            if (query is not None) and (len(revid_list) == 0):
55
61
                search_failed = True
56
62
 
57
63
            if len(revid_list) == 0:
58
64
                scan_list = revid_list
59
65
            else:
60
 
                if revid in revid_list: # XXX is this always true?
61
 
                    i = revid_list.index(revid)
62
 
                else:
63
 
                    i = None
64
 
                scan_list = revid_list[i:]
65
 
            change_list = scan_list[:pagesize]
66
 
            changes = list(history.get_changes(change_list))
67
 
            data = {}
68
 
            for i, c in enumerate(changes):
69
 
                c.index = i
70
 
                data[str(i)] = urllib.quote(urllib.quote(c.revid, safe=''))
 
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)
71
69
        except:
72
70
            self.log.exception('Exception fetching changes')
73
 
            raise HTTPServerError('Could not fetch changes')
 
71
            raise InternalError('Could not fetch changes')
74
72
 
75
 
        navigation = util.Container(
76
 
            pagesize=pagesize, revid=revid, start_revid=start_revid,
77
 
            revid_list=revid_list, filter_file_id=filter_file_id,
78
 
            scan_url='/changes', branch=self._branch, feed=True, history=history)
 
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)
79
75
        if query is not None:
80
76
            navigation.query = query
81
 
        util.fill_in_navigation(navigation)
82
 
 
83
 
        # Directory Breadcrumbs
84
 
        directory_breadcrumbs = (
85
 
            util.directory_breadcrumbs(
86
 
                self._branch.friendly_name,
87
 
                self._branch.is_root,
88
 
                'changes'))
89
 
 
90
 
        show_tag_col = False
91
 
        for change in changes:
92
 
            if change.tags is not None:
93
 
                show_tag_col = True
94
 
                break
95
 
 
96
 
        return {
 
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 = {
97
84
            'branch': self._branch,
98
 
            'changes': changes,
99
 
            'show_tag_col': show_tag_col,
100
 
            'data': simplejson.dumps(data),
 
85
            'changes': list(entries),
101
86
            'util': util,
102
 
            'history': history,
 
87
            'history': h,
103
88
            'revid': revid,
104
89
            'navigation': navigation,
105
 
            'filter_file_id': filter_file_id,
 
90
            'file_id': file_id,
106
91
            'start_revid': start_revid,
107
 
            'viewing_from': (orig_start_revid is not None) and
108
 
                            (orig_start_revid != history.last_revid),
 
92
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
109
93
            'query': query,
110
94
            'search_failed': search_failed,
111
 
            'url': self._branch.context_url,
112
 
            'directory_breadcrumbs': directory_breadcrumbs,
113
95
        }
 
96
        h.flush_cache()
 
97
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
98
        return vals