~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-01-24 23:37:31 UTC
  • Revision ID: robey@lag.net-20070124233731-xga5g9b721hfwjmj
augh! wtf! this year is 2007! not 2006!

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 urllib
21
 
 
22
 
try:
23
 
    import simplejson
24
 
except ImportError:
25
 
    import json as simplejson
26
 
 
27
 
from paste.httpexceptions import HTTPServerError
 
20
import os
 
21
import time
 
22
 
 
23
import turbogears
 
24
from cherrypy import HTTPRedirect, session
28
25
 
29
26
from loggerhead import util
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))
 
27
 
 
28
 
 
29
 
 
30
 
 
31
class ChangeLogUI (object):
 
32
    
 
33
    def __init__(self, branch):
 
34
        # BranchView object
 
35
        self._branch = branch
 
36
        self.log = branch.log
 
37
        
 
38
    @util.strip_whitespace
 
39
    @turbogears.expose(html='loggerhead.templates.changelog')
 
40
    def default(self, *args, **kw):
 
41
        z = time.time()
 
42
        h = self._branch.get_history()
 
43
        config = self._branch.config
 
44
        
 
45
        if len(args) > 0:
 
46
            revid = h.fix_revid(args[0])
 
47
        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))
43
53
        orig_start_revid = start_revid
44
 
        pagesize = 20#int(config.get('pagesize', '20'))
 
54
        pagesize = int(config.get('pagesize', '20'))
45
55
        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
 
 
 
56
        
50
57
        try:
51
 
            revid, start_revid, revid_list = history.get_view(
52
 
                revid, start_revid, filter_file_id, query)
53
 
            util.set_context(kwargs)
54
 
 
 
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
            
55
62
            if (query is not None) and (len(revid_list) == 0):
56
63
                search_failed = True
57
64
 
58
65
            if len(revid_list) == 0:
59
66
                scan_list = revid_list
60
67
            else:
61
 
                if revid in revid_list: # XXX is this always true?
62
 
                    i = revid_list.index(revid)
63
 
                else:
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')
 
68
                scan_list = revid_list[h.get_revid_sequence(revid_list, revid):]
 
69
            entry_list = scan_list[:pagesize]
 
70
            entries = h.get_changes(entry_list)
 
71
        except Exception, x:
 
72
            self.log.error('Exception fetching changes: %s' % (x,))
 
73
            util.log_exception(self.log)
 
74
            raise HTTPRedirect(self._branch.url('/changes'))
75
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)
 
76
        navigation = util.Container(pagesize=pagesize, revid=revid, start_revid=start_revid, revid_list=revid_list,
 
77
                                    file_id=file_id, scan_url='/changes', branch=self._branch, feed=True)
80
78
        if query is not None:
81
79
            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 {
 
80
        util.fill_in_navigation(h, navigation)
 
81
        
 
82
        entries = list(entries)
 
83
        # add parent & merge-point branch-nick info, in case it's useful
 
84
        h.get_branch_nicks(entries)
 
85
 
 
86
        vals = {
92
87
            'branch': self._branch,
93
 
            'changes': changes,
94
 
            'data': simplejson.dumps(data),
 
88
            'changes': list(entries),
95
89
            'util': util,
96
 
            'history': history,
 
90
            'history': h,
97
91
            'revid': revid,
98
92
            'navigation': navigation,
99
 
            'filter_file_id': filter_file_id,
 
93
            'file_id': file_id,
100
94
            'start_revid': start_revid,
101
 
            'viewing_from': (orig_start_revid is not None) and 
102
 
                            (orig_start_revid != history.last_revid),
 
95
            'viewing_from': (orig_start_revid is not None) and (orig_start_revid != h.last_revid),
103
96
            'query': query,
104
97
            'search_failed': search_failed,
105
 
            'url': self._branch.context_url,
106
 
            'directory_breadcrumbs': directory_breadcrumbs,
107
98
        }
 
99
        h.flush_cache()
 
100
        self.log.info('/changes %r: %r secs' % (revid, time.time() - z))
 
101
        return vals