ep2008-dev

Annotated themes/ep2008/ep2008.py

64:c4bb1bf2b9d7
2008-10-25 Paul Boddie Made the RSS link in the theme module compatible with 1.5.x and 1.6.x through the use of a default parameter. Added the CategoryMenu macro and styles. moin-1.6
paul@0 1
# -*- coding: iso-8859-1 -*-
paul@0 2
"""
paul@0 3
    MoinMoin - ep2008 (EuroPython 2008) theme
paul@0 4
paul@50 5
    @copyright: 2003-2008 by Nir Soffer, Thomas Waldmann, Paul Boddie
paul@27 6
    @license: GNU GPL (v2 or later), see COPYING.txt for details.
paul@0 7
"""
paul@0 8
paul@0 9
from MoinMoin.theme import ThemeBase
paul@12 10
from MoinMoin.action import AttachFile
paul@12 11
import random
paul@0 12
paul@0 13
class Theme(ThemeBase):
paul@0 14
paul@0 15
    name = "ep2008"
paul@0 16
paul@64 17
    def rsslink(self, d=None):
paul@50 18
        """ Create rss link in head, used by FireFox
paul@50 19
paul@50 20
        RSS link for FireFox. This shows an rss link in the bottom of
paul@50 21
        the page and let you subscribe to the wiki rss feed.
paul@50 22
paul@50 23
        @rtype: unicode
paul@50 24
        @return: html head
paul@50 25
        """
paul@50 26
paul@57 27
        extra_rss = self.cfg.extra_rss
paul@64 28
        if d is not None:
paul@64 29
            return ThemeBase.rsslink(self, d) + u'\n' + extra_rss
paul@64 30
        else:
paul@64 31
            return ThemeBase.rsslink(self) + u'\n' + extra_rss
paul@50 32
paul@0 33
    def header(self, d, **kw):
paul@0 34
        """ Assemble wiki header
paul@0 35
paul@0 36
        @param d: parameter dictionary
paul@0 37
        @rtype: unicode
paul@0 38
        @return: page header html
paul@0 39
        """
paul@0 40
        html = [
paul@0 41
            # Pre header custom html
paul@0 42
            self.emit_custom_html(self.cfg.page_header1),
paul@0 43
paul@0 44
            # Header
paul@0 45
            u'<div id="header">',
paul@0 46
            self.logo(),
paul@0 47
paul@0 48
            # Banner
paul@12 49
            self.banner(d),
paul@0 50
paul@0 51
            self.searchform(d),
paul@0 52
            self.navibar(d),
paul@0 53
            self.msg(d),
paul@0 54
paul@0 55
            # NOTE: Hack everything into the header
paul@0 56
            u'<div id="end-of-header">',
paul@0 57
            u'</div>',
paul@0 58
            u'</div>',
paul@0 59
paul@0 60
            # Post header custom html (not recommended)
paul@0 61
            self.emit_custom_html(self.cfg.page_header2),
paul@0 62
paul@0 63
            # Start of page
paul@0 64
            u'<div class="page-%s">' % d['page_name'],
paul@0 65
            self.startPage(),
paul@0 66
        ]
paul@0 67
        return u'\n'.join(html)
paul@0 68
paul@0 69
    def editorheader(self, d, **kw):
paul@0 70
        """ Assemble wiki header for editor
paul@0 71
paul@0 72
        @param d: parameter dictionary
paul@0 73
        @rtype: unicode
paul@0 74
        @return: page header html
paul@0 75
        """
paul@0 76
        html = [
paul@0 77
            # Pre header custom html
paul@0 78
            self.emit_custom_html(self.cfg.page_header1),
paul@0 79
paul@0 80
            # Header
paul@0 81
            u'<div id="header">',
paul@0 82
            self.title(d),
paul@0 83
            self.msg(d),
paul@0 84
            u'</div>',
paul@0 85
paul@0 86
            # Post header custom html (not recommended)
paul@0 87
            self.emit_custom_html(self.cfg.page_header2),
paul@0 88
paul@0 89
            # Start of page
paul@0 90
            u'<div class="page-%s">' % d['page_name'],
paul@0 91
            self.startPage(),
paul@0 92
        ]
paul@0 93
        return u'\n'.join(html)
paul@0 94
paul@0 95
    def footer(self, d, **keywords):
paul@0 96
        """ Assemble wiki footer
paul@0 97
paul@0 98
        @param d: parameter dictionary
paul@0 99
        @keyword ...:...
paul@0 100
        @rtype: unicode
paul@0 101
        @return: page footer html
paul@0 102
        """
paul@28 103
        request = self.request
paul@28 104
        formatter = request.formatter
paul@0 105
        page = d['page']
paul@11 106
paul@11 107
        if self.cfg.special_username:
paul@11 108
            username = self.specialUsername(d)
paul@11 109
        else:
paul@11 110
            username = self.username(d)
paul@11 111
paul@0 112
        html = [
paul@0 113
            # End of page
paul@46 114
            #self.pageinfo(page),
paul@0 115
            self.endPage(),
paul@0 116
            u'</div>',
paul@0 117
paul@0 118
            # Pre footer custom html (not recommended!)
paul@0 119
            self.emit_custom_html(self.cfg.page_footer1),
paul@0 120
paul@0 121
            # Footer
paul@0 122
            u'<div id="footer">',
paul@28 123
            u'<div id="contact">',
paul@28 124
            formatter.pagelink(1, self.cfg.contact_page),
paul@28 125
            self.cfg.contact_label,
paul@28 126
            formatter.pagelink(0),
paul@28 127
            u'</div>',
paul@10 128
            u'<div id="contribute">',
paul@10 129
            #self.cfg.contribute_string,
paul@10 130
            #u'<div class="contribute-hidden">',
paul@10 131
            #self.username(d),
paul@10 132
            #u'<div id="locationline">',
paul@10 133
            #self.interwiki(d),
paul@10 134
            #self.title(d),
paul@10 135
            #u'</div>',
paul@11 136
            username,
paul@10 137
            self.editbar(d),
paul@0 138
            self.trail(d),
paul@10 139
            #u'</div>',
paul@0 140
            u'</div>',
paul@0 141
            self.credits(d),
paul@0 142
            self.showversion(d, **keywords),
paul@0 143
            u'</div>',
paul@0 144
paul@0 145
            # Post footer custom html
paul@0 146
            self.emit_custom_html(self.cfg.page_footer2),
paul@0 147
            ]
paul@0 148
        return u'\n'.join(html)
paul@0 149
paul@10 150
    def editbarItems(self, page):
paul@10 151
        """ Return list of items to show on the editbar
paul@10 152
paul@10 153
        This is separate method to make it easy to customize the
paul@10 154
        editbar in sub classes.
paul@10 155
        """
paul@10 156
paul@10 157
        request = self.request
paul@10 158
paul@10 159
        items = [self.editorLink(page),
paul@10 160
                self.infoLink(page),
paul@10 161
                self.subscribeLink(page),
paul@10 162
                self.quicklinkLink(page),]
paul@10 163
paul@10 164
        if page.isWritable() and request.user.valid and request.user.may.write(page.page_name):
paul@10 165
            items.append(self.attachmentsLink(page))
paul@10 166
paul@10 167
        if request.user.valid:
paul@10 168
            items.append(self.actionsMenu(page))
paul@10 169
paul@10 170
        return items
paul@10 171
paul@10 172
    def specialUsername(self, d):
paul@10 173
        request = self.request
paul@10 174
        _ = request.getText
paul@10 175
paul@10 176
        if request.user.valid and request.user.name:
paul@10 177
            return u'<div class="username">%s</div>' % request.formatter.text(request.user.name)
paul@10 178
        else:
paul@10 179
            # NOTE: Using the contribute string!
paul@10 180
            return u'<div class="no-username">%s</div>' % \
paul@10 181
                d['page'].link_to(request, text=self.cfg.contribute_string,
paul@10 182
                                  querystr={'action': 'login'}, id="login")
paul@10 183
paul@12 184
    def banner(self, d):
paul@12 185
        request = self.request
paul@12 186
        formatter = request.formatter
paul@12 187
paul@12 188
        # Either get banners per page or acquire them from a central source.
paul@12 189
paul@12 190
        if self.cfg.banner_per_page:
paul@12 191
            pagename = d["page"].page_name
paul@12 192
        else:
paul@12 193
            pagename = self.cfg.banner_attachment_page
paul@12 194
paul@12 195
        # Only get attachments with a certain prefix.
paul@12 196
paul@12 197
        attachments = []
paul@12 198
        for filename in AttachFile._get_files(request, pagename):
paul@12 199
            if filename.startswith(self.cfg.banner_prefix):
paul@12 200
                attachments.append(filename)
paul@12 201
paul@12 202
        # Display the default banner if no attachments are found.
paul@12 203
paul@14 204
        target = self.cfg.banner_link_page
paul@14 205
paul@12 206
        if not attachments:
paul@14 207
            return "%s%s%s" % (formatter.pagelink(1, target),
paul@14 208
                               self.cfg.banner_string,
paul@14 209
                               formatter.pagelink(0))
paul@12 210
paul@12 211
        # Choose an attachment at random and return the HTML to show it.
paul@12 212
paul@12 213
        attachment = random.choice(attachments)
paul@12 214
paul@12 215
        kw = {}
paul@12 216
        kw['src'] = AttachFile.getAttachUrl(pagename, attachment, request)
paul@12 217
        kw['alt'] = self.cfg.banner_alt_text
paul@12 218
        kw['id'] = u'banner'
paul@12 219
paul@12 220
        return "%s%s%s" % (formatter.pagelink(1, target),
paul@12 221
                           formatter.image(**kw),
paul@12 222
                           formatter.pagelink(0))
paul@12 223
paul@0 224
def execute(request):
paul@0 225
    """
paul@0 226
    Generate and return a theme object
paul@0 227
paul@0 228
    @param request: the request object
paul@0 229
    @rtype: MoinTheme
paul@0 230
    @return: Theme object
paul@0 231
    """
paul@0 232
    return Theme(request)
paul@0 233
paul@0 234
# vim: tabstop=4 expandtab shiftwidth=4