~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/directory_ui.py

  • Committer: Martin Albisetti
  • Date: 2008-08-13 19:59:14 UTC
  • mfrom: (207.1.10 unify-templates)
  • Revision ID: argentina@gmail.com-20080813195914-hmx1fcoaqgl2g9xk
Fixed an issue with the feed link (Paul Hummer with Matt Nordhoff's reviewing superpowers)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import branch
24
24
 
25
 
from loggerhead import util
26
25
from loggerhead.controllers import TemplatedBranchView
27
26
 
28
 
 
29
27
class DirEntry(object):
30
 
 
31
28
    def __init__(self, dirname, parity, branch):
32
29
        self.dirname = dirname
33
30
        self.parity = parity
35
32
        if branch is not None:
36
33
            # If a branch is empty, bzr raises an exception when trying this
37
34
            try:
38
 
                self.last_change = datetime.datetime.fromtimestamp(
39
 
                    branch.repository.get_revision(
40
 
                        branch.last_revision()).timestamp)
 
35
                self.last_change =  datetime.datetime.fromtimestamp(
 
36
                    branch.repository.get_revision(branch.last_revision()).timestamp)
41
37
            except:
42
38
                self.last_change = None
43
39
 
44
 
 
45
40
class DirectoryUI(TemplatedBranchView):
46
41
    """
47
42
    """
49
44
    template_path = 'loggerhead.templates.directory'
50
45
 
51
46
    def __init__(self, static_url_base, path, name):
52
 
 
53
47
        class _branch(object):
54
48
            context_url = 1
55
 
 
56
 
            @staticmethod
57
 
            def static_url(path):
58
 
                return self._static_url_base + path
59
49
        self._branch = _branch
60
50
        self._history = None
61
51
        self._path = path
63
53
        self._static_url_base = static_url_base
64
54
        self.log = logging.getLogger('')
65
55
 
66
 
    def get_values(self, h, revid, path, kwargs, response):
 
56
    def get_values(self, h, args, kwargs, response):
67
57
        listing = [d for d in os.listdir(self._path)
68
58
                   if not d.startswith('.')
69
59
                   and os.path.isdir(os.path.join(self._path, d))]
70
60
        listing.sort(key=lambda x: x.lower())
71
61
        dirs = []
72
62
        parity = 0
 
63
        def static_url(path):
 
64
            return self._static_url_base + path
73
65
        for d in listing:
74
66
            p = os.path.join(self._path, d)
75
67
            try:
78
70
                b = None
79
71
            dirs.append(DirEntry(d, parity, b))
80
72
            parity = 1 - parity
81
 
        # Create breadcrumb trail
82
 
        directory_breadcrumbs = util.directory_breadcrumbs(
83
 
                self._name,
84
 
                False,
85
 
                'directory')
86
73
        return {
87
74
            'dirs': dirs,
88
75
            'name': self._name,
89
 
            'directory_breadcrumbs': directory_breadcrumbs,
 
76
            'static_url': static_url,
90
77
            }