annotate MoinMoin/themes/__init__.py @ 1907:7324a1d71443

simplify and standardize headings and page titles on user and admin pages
author Roger Haase <crosseyedpenguin@yahoo.com>
date Sun, 06 Jan 2013 12:42:47 -0700
parents 063c879ef79b
children 2bd864ed640e 5281fec759b1
rev   line source
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
1 # Copyright: 2003-2010 MoinMoin:ThomasWaldmann
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
2 # Copyright: 2008 MoinMoin:RadomirDopieralski
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
3 # Copyright: 2010 MoinMoin:DiogenesAugusto
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
4 # License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
5
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 MoinMoin - Theme Support
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
8 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 import urllib
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12
1144
9ab81e421631 Use dumps() for json escaping
Sam Toyer <samATqxcvDOTnet>
parents: 1142
diff changeset
13 from json import dumps
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1414
diff changeset
14 from operator import attrgetter
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
15
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 from flask import current_app as app
109
e4c332436733 remove flask monkeypatch, use 'from flask import g as flaskg'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 106
diff changeset
17 from flask import g as flaskg
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 from flask import url_for, request
1767
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1764
diff changeset
19 from flask.ext.themes import get_theme, render_theme_template
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 from MoinMoin import log
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 logging = log.getLogger(__name__)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 from MoinMoin.i18n import _, L_, N_
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 from MoinMoin import wikiutil, user
102
c084c1369078 move metadata name constant defs to MoinMoin.config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 73
diff changeset
26 from MoinMoin.config import USERID, ADDRESS, HOSTNAME
1227
18cb4213fc4d Always show search box in layout.html
Sam Toyer <samATqxcvDOTnet>
parents: 1145
diff changeset
27 from MoinMoin.search import SearchForm
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
28 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 150
diff changeset
29 from MoinMoin.util.crypto import cache_key
248
1a1dab306214 move the flatland form html generator to the global environment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
30 from MoinMoin.util.forms import make_generator
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
31 from MoinMoin.util.clock import timed
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
32 from MoinMoin.util.mime import Type
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 def get_current_theme():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 # this might be called at a time when flaskg.user is not setup yet:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 u = getattr(flaskg, 'user', None)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 if u and u.theme_name is not None:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 theme_name = u.theme_name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 theme_name = app.cfg.theme_default
104
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
42 try:
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
43 return get_theme(theme_name)
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
44 except KeyError:
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
45 logging.warning("Theme {0!r} was not found; using default of {1!r} instead.".format(theme_name, app.cfg.theme_default))
104
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
46 theme_name = app.cfg.theme_default
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
47 return get_theme(theme_name)
9ca492c52070 use default theme if we cannot get the one that was requested (instead of crashing)
MattMaker <trip@entropyreductionservices.com>
parents: 64
diff changeset
48
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
50 @timed()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 def render_template(template, **context):
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
52 return render_theme_template(get_current_theme(), template, **context)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 def themed_error(e):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 item_name = request.view_args.get('item_name', u'')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 if e.code == 403:
1907
7324a1d71443 simplify and standardize headings and page titles on user and admin pages
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1885
diff changeset
57 title = L_('Access Denied')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 description = L_('You are not allowed to access this resource.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 # if we have no special code, we just return the HTTPException instance
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 return e
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 content = render_template('error.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 item_name=item_name,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 title=title, description=description)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 return content, e.code
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 class ThemeSupport(object):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 Support code for template feeding.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 def __init__(self, cfg):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 self.cfg = cfg
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 self.user = flaskg.user
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 self.storage = flaskg.storage
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 self.ui_lang = 'en' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 self.ui_dir = 'ltr' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 self.content_lang = flaskg.content_lang # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 self.content_dir = 'ltr' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 self.meta_items = [] # list of (name, content) for html head <meta>
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 def location_breadcrumbs(self, item_name):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 Assemble the location using breadcrumbs (was: title)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
86 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
87 :returns: location breadcrumbs items in tuple (segment_name, item_name, exists)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 breadcrumbs = []
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 current_item = ''
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 for segment in item_name.split('/'):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 current_item += segment
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 breadcrumbs.append((segment, current_item, self.storage.has_item(current_item)))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 current_item += '/'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 return breadcrumbs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 def path_breadcrumbs(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 Assemble the path breadcrumbs (a.k.a.: trail)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
101 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
102 :returns: path breadcrumbs items in tuple (wiki_name, item_name, url, exists, err)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 user = self.user
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 breadcrumbs = []
1281
0a70177ce4de user: changed method names for better PEP8 compliance
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1278
diff changeset
106 trail = user.get_trail()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 for interwiki_item_name in trail:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 wiki_name, item_name = split_interwiki(interwiki_item_name)
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
109 err = not is_known_wiki(wiki_name)
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
110 href = url_for_item(item_name, wiki_name=wiki_name)
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
111 if is_local_wiki(wiki_name):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 exists = self.storage.has_item(item_name)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 wiki_name = '' # means "this wiki" for the theme code
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 exists = True # we can't detect existance of remote items
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 breadcrumbs.append((wiki_name, item_name, href, exists, err))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 return breadcrumbs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
119 def subitem_index(self, item_name):
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
120 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
121 Get a list of subitems for the given item_name
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
122
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
123 :rtype: list
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
124 :returns: list of item tuples (item_name, item_title, item_mime_type, has_children)
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
125 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
126 from MoinMoin.items import Item
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
127 item = Item.create(item_name)
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1767
diff changeset
128 return item.get_mixed_index()
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
129
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 def userhome(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 Assemble arguments used to build user homepage link
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
134 :rtype: tuple
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
135 :returns: arguments of user homepage link in tuple (wiki_href, aliasname, title, exists)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 user = self.user
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 name = user.name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 aliasname = user.aliasname
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 if not aliasname:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 aliasname = name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 wikiname, itemname = getInterwikiHome(name)
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
144 title = u"{0} @ {1}".format(aliasname, wikiname)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 # link to (interwiki) user homepage
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
146 if is_local_wiki(wikiname):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 exists = self.storage.has_item(itemname)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 # We cannot check if wiki pages exists in remote wikis
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 exists = True
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
151 wiki_href = url_for_item(itemname, wiki_name=wikiname)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 return wiki_href, aliasname, title, exists
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153
63
14832b8cc7ed navibar/split_navilink: remove i18n support (was used for cfg.navibar)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
154 def split_navilink(self, text):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156 Split navibar links into pagename, link to page
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 Admin or user might want to use shorter navibar items by using
63
14832b8cc7ed navibar/split_navilink: remove i18n support (was used for cfg.navibar)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
159 the [[page|title]] or [[url|title]] syntax.
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 Supported syntax:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 * PageName
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 * WikiName:PageName
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 * wiki:WikiName:PageName
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 * url
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 * all targets as seen above with title: [[target|title]]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
168 :param text: the text used in config or user preferences
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
169 :rtype: tuple
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
170 :returns: pagename or url, link to page or url
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 title = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 wiki_local = '' # means local wiki
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 # Handle [[pagename|title]] or [[url|title]] formats
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 if text.startswith('[[') and text.endswith(']]'):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 text = text[2:-2]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 target, title = text.split('|', 1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 target = target.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181 title = title.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 except (ValueError, TypeError):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 # Just use the text as is.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 target = text.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 target = text
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 if wikiutil.is_URL(target):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 if not title:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 title = target
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 return target, title, wiki_local
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 # remove wiki: url prefix
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 if target.startswith("wiki:"):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 target = target[5:]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 wiki_name, item_name = split_interwiki(target)
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 313
diff changeset
198 if wiki_name == 'Self':
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 313
diff changeset
199 wiki_name = ''
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
200 href = url_for_item(item_name, wiki_name=wiki_name)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 if not title:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 title = item_name
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 313
diff changeset
203 return href, title, wiki_name
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
205 @timed()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 def navibar(self, item_name):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 Assemble the navibar
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
210 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
211 :returns: list of tuples (css_class, url, link_text, title)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 current = item_name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 # Process config navi_bar
150
d3deda1731fb configure navi_bar using tuples
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 146
diff changeset
215 items = [(cls, url_for(endpoint, **args), link_text, title)
d3deda1731fb configure navi_bar using tuples
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 146
diff changeset
216 for cls, endpoint, args, link_text, title in self.cfg.navi_bar]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 # Add user links to wiki links.
1278
2c58cbcfeabe quicklinks/subscribed_items: use attributes directly, simplify code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1227
diff changeset
219 for text in self.user.quicklinks:
63
14832b8cc7ed navibar/split_navilink: remove i18n support (was used for cfg.navibar)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
220 url, link_text, title = self.split_navilink(text)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 items.append(('userlink', url, link_text, title))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 # Add sister pages (see http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224 for sistername, sisterurl in self.cfg.sistersites:
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
225 if is_local_wiki(sistername):
1885
063c879ef79b sistersites: fix tuple member count
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
226 items.append(('sisterwiki current', sisterurl, sistername, ''))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227 else:
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 150
diff changeset
228 cid = cache_key(usage="SisterSites", sistername=sistername)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 sisteritems = app.cache.get(cid)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 if sisteritems is None:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
231 uo = urllib.URLopener()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232 uo.version = 'MoinMoin SisterItem list fetcher 1.0'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 sisteritems = {}
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235 f = uo.open(sisterurl)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236 for line in f:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 line = line.strip()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 item_url, item_name = line.split(' ', 1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 sisteritems[item_name.decode('utf-8')] = item_url
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 except:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 pass # ignore invalid lines
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 f.close()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244 app.cache.set(cid, sisteritems)
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
245 logging.info("Site: {0!r} Status: Updated. Pages: {1}".format(sistername, len(sisteritems)))
135
75312c9b94e3 use except...as syntax, use raise Exception(...) syntax, fix some imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 126
diff changeset
246 except IOError as err:
75312c9b94e3 use except...as syntax, use raise Exception(...) syntax, fix some imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 126
diff changeset
247 (title, code, msg, headers) = err.args # code e.g. 304
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
248 logging.warning("Site: {0!r} Status: Not updated.".format(sistername))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 logging.exception("exception was:")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 if current in sisteritems:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 url = sisteritems[current]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 items.append(('sisterwiki', url, sistername, ''))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 return items
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 def parent_item(self, item_name):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257 Return name of parent item for the current item
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
259 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
260 :returns: parent item name
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
261 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 parent_item_name = wikiutil.ParentItemName(item_name)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263 if item_name and parent_item_name:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264 return parent_item_name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
266 # TODO: reimplement on-wiki-page sidebar definition with MoinMoin.converter
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 # Properties ##############################################################
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
269
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
270 def login_url(self):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
272 Return URL usable for user login
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
274 :rtype: unicode (or None, if no login url is supported)
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
275 :returns: url for user login
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277 url = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278 if self.cfg.auth_login_inputs == ['special_no_input']:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279 url = url_for('frontend.login', login=1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
280 if self.cfg.auth_have_login:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 url = url or url_for('frontend.login')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
282 return url
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
283
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
284
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
285 def get_editor_info(meta, external=False):
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
286 addr = meta.get(ADDRESS)
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
287 hostname = meta.get(HOSTNAME)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 text = _('anonymous') # link text
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289 title = '' # link title
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 css = 'editor' # link/span css class
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
291 name = None # author name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
292 uri = None # author homepage uri
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 email = None # pure email address of author
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294 if app.cfg.show_hosts and addr:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
295 # only tell ip / hostname if show_hosts is True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 if hostname:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
297 text = hostname[:15] # 15 = len(ipaddr)
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
298 name = title = u'{0}[{1}]'.format(hostname, addr)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299 css = 'editor host'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301 name = text = addr
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
302 title = u'[{0}]'.format(addr)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 css = 'editor ip'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
305 userid = meta.get(USERID)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 if userid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307 u = user.User(userid)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 name = u.name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 text = name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
310 aliasname = u.aliasname
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
311 if not aliasname:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 aliasname = name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
313 if title:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
314 # we already have some address info
1414
614005b5edb3 fixed some .format() unicode issues, partially fixing bug #124
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1397
diff changeset
315 title = u"{0} @ {1}".format(aliasname, title)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
317 title = aliasname
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
318 if u.mailto_author and u.email:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
319 email = u.email
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
320 css = 'editor mail'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
321 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
322 homewiki = app.cfg.user_homewiki
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
323 if is_local_wiki(homewiki):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
324 css = 'editor homepage local'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
325 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
326 css = 'editor homepage interwiki'
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
327 uri = url_for_item(name, wiki_name=homewiki, _external=external)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
328
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
329 result = dict(name=name, text=text, css=css, title=title)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
330 if uri:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
331 result['uri'] = uri
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
332 if email:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
333 result['email'] = email
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
334 return result
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
335
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
336 def shorten_item_name(name, length=25):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
337 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
338 Shorten item names
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
339
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
340 Shorten very long item names that tend to break the user
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
341 interface. The short name is usually fine, unless really stupid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342 long names are used (WYGIWYD).
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
344 :param name: item name, unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
345 :param length: maximum length for shortened item names, int
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
346 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
347 :returns: shortened version.
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
348 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
349 # First use only the sub page name, that might be enough
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
350 if len(name) > length:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
351 name = name.split('/')[-1]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
352 # If it's not enough, replace the middle with '...'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
353 if len(name) > length:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
354 half, left = divmod(length - 3, 2)
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 861
diff changeset
355 name = u'{0}...{1}'.format(name[:half + left], name[-half:])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 return name
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
358 def shorten_id(name, length=7):
1109
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
359 """
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
360 Shorten IDs to specified length
1109
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
361
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
362 Shorten long IDs into just the first <length> characters. There's
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
363 no need to display the whole IDs everywhere.
1109
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
364
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
365 :param name: item name, unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
366 :param length: Maximum length of the resulting ID, int
1109
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
367 :rtype: unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
368 :returns: <name> truncated to <length> characters
1109
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
369 """
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
370
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
371 return name[:length]
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
373 MIMETYPE_TO_CLASS = {
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
374 'application/pdf': 'pdf',
476
a716e61ae9c7 contenttype texts are replaced by icons in global history page, all icons are GPL licensed (picked from tango icons library).
Akash Sinha <akash2607@gmail.com>
parents: 248
diff changeset
375 'application/zip': 'package',
a716e61ae9c7 contenttype texts are replaced by icons in global history page, all icons are GPL licensed (picked from tango icons library).
Akash Sinha <akash2607@gmail.com>
parents: 248
diff changeset
376 'application/x-tar': 'package',
526
035656874a40 icluding tgz also as archive package for icon display, similar to tar(missed this earlier)
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
377 'application/x-gtar': 'package',
476
a716e61ae9c7 contenttype texts are replaced by icons in global history page, all icons are GPL licensed (picked from tango icons library).
Akash Sinha <akash2607@gmail.com>
parents: 248
diff changeset
378 'application/x-twikidraw': 'drawing',
a716e61ae9c7 contenttype texts are replaced by icons in global history page, all icons are GPL licensed (picked from tango icons library).
Akash Sinha <akash2607@gmail.com>
parents: 248
diff changeset
379 'application/x-anywikidraw': 'drawing',
a716e61ae9c7 contenttype texts are replaced by icons in global history page, all icons are GPL licensed (picked from tango icons library).
Akash Sinha <akash2607@gmail.com>
parents: 248
diff changeset
380 'application/x-svgdraw': 'drawing',
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
381 }
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
382
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
383 def contenttype_to_class(contenttype):
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
384 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
385 Convert a contenttype string to a css class.
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
386 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
387 cls = MIMETYPE_TO_CLASS.get(contenttype)
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
388 if not cls:
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
389 # just use the major part of mimetype
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
390 cls = contenttype.split('/', 1)[0]
969
5bf6d7a2ffcf Convert all %r, %s, %x, %d, %i, %o to new Format String Syntax
Vedran Mileti? <rivanvx@gmail.com>
parents: 861
diff changeset
391 return 'moin-mime-{0}'.format(cls)
126
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
392
81f0ff7a5cae global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 125
diff changeset
393
770
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
394 def utctimestamp(dt):
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
395 """
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
396 convert a datetime object (UTC) to a UNIX timestamp (UTC)
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
397
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
398 Note: time library writers seem to have a distorted relationship to inverse
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
399 functions and also to UTC (see time.gmtime, see datetime.utcfromtimestamp).
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
400 """
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
401 from calendar import timegm
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
402 return timegm(dt.timetuple())
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
403
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
404
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 def setup_jinja_env():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 app.jinja_env.filters['shorten_item_name'] = shorten_item_name
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
407 app.jinja_env.filters['shorten_id'] = shorten_id
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
408 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
1145
5421be737643 Simplify string escaping filter.
Sam Toyer <samATqxcvDOTnet>
parents: 1144
diff changeset
409 app.jinja_env.filters['json_dumps'] = dumps
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
410 # please note that these filters are installed by flask-babel:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 # datetimeformat, dateformat, timeformat, timedeltaformat
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
412
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 app.jinja_env.globals.update({
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
414 # please note that flask-babel/jinja2.ext installs:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
415 # _, gettext, ngettext
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
416 'isinstance': isinstance,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
417 'list': list,
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
418 'Type': Type,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
419 # please note that flask-themes installs:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
420 # theme, theme_static
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 'theme_supp': ThemeSupport(app.cfg),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
422 'user': flaskg.user,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
423 'storage': flaskg.storage,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
424 'clock': flaskg.clock,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
425 'cfg': app.cfg,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
426 'item_name': 'handlers need to give it',
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 313
diff changeset
427 'url_for_item': url_for_item,
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
428 'get_editor_info': lambda meta: get_editor_info(meta),
770
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 526
diff changeset
429 'utctimestamp': lambda dt: utctimestamp(dt),
248
1a1dab306214 move the flatland form html generator to the global environment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 216
diff changeset
430 'gen': make_generator(),
1227
18cb4213fc4d Always show search box in layout.html
Sam Toyer <samATqxcvDOTnet>
parents: 1145
diff changeset
431 'search_form': SearchForm.from_defaults(),
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
432 })