annotate MoinMoin/themes/__init__.py @ 2226:09a9bffa1581

Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
author Ashutosh Singla <ashu1461@gmail.com>
date Sat, 20 Jul 2013 02:40:21 +0530
parents 431815d4f4a6
children f2bd327932fb
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
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
14
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 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
16 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
17 from flask import url_for, request
1767
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1764
diff changeset
18 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
19
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 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
21 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
22
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 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
24 from MoinMoin import wikiutil, user
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
25 from MoinMoin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT
1227
18cb4213fc4d Always show search box in layout.html
Sam Toyer <samATqxcvDOTnet>
parents: 1145
diff changeset
26 from MoinMoin.search import SearchForm
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
27 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item, CompositeName, split_fqname
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
28 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
29 from MoinMoin.util.forms import make_generator
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
30 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
31 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
32
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 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
35 # 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
36 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
37 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
38 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
39 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 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
41 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
42 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
43 except KeyError:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
44 logging.warning("Theme {0!r} was not found; using default of {1!r} instead.".format(
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
45 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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 def render_template(template, **context):
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
51 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
52
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
53
0
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
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
76 self.ui_lang = 'en' # XXX
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
77 self.ui_dir = 'ltr' # XXX
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
78 self.content_lang = flaskg.content_lang # XXX
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
79 self.content_dir = 'ltr' # XXX
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
80 self.meta_items = [] # list of (name, content) for html head <meta>
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
82 def location_breadcrumbs(self, fqname):
0
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
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
87 :returns: location breadcrumbs items in tuple (segment_name, fq_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 = ''
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
91 if not isinstance(fqname, CompositeName):
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
92 fqname = split_fqname(fqname)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
93 if fqname.field != NAME_EXACT:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
94 return [(fqname, fqname, bool(self.storage.get_item(**fqname.query)))]
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
95 namespace = fqname.namespace
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
96 fq_current = CompositeName(u'', NAME_EXACT, namespace)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
97 fq_segment = CompositeName(u'', NAME_EXACT, namespace or '~')
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
98 breadcrumbs.append((CompositeName(fq_segment, fq_current, False)))
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
99 item_name = fqname.value
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
100 if not item_name:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
101 return breadcrumbs
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 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
103 current_item += segment
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
104 fq_current = CompositeName(namespace, NAME_EXACT, current_item)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
105 fq_segment = CompositeName(namespace, NAME_EXACT, segment)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
106 breadcrumbs.append((fq_segment, fq_current, bool(self.storage.get_item(**fq_current.query))))
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 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
108 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
109
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 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
111 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 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
113
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
114 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
115 :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
116 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 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
118 breadcrumbs = []
1281
0a70177ce4de user: changed method names for better PEP8 compliance
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1278
diff changeset
119 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
120 for interwiki_item_name in trail:
2217
431815d4f4a6 Fixed interwiki patch to deal with new composite name.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2117
diff changeset
121 wiki_name, namespace, field, item_name = split_interwiki(interwiki_item_name)
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
122 fqname = CompositeName(namespace, field, item_name)
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
123 err = not is_known_wiki(wiki_name)
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
124 href = url_for_item(wiki_name=wiki_name, **fqname.split)
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
125 if is_local_wiki(wiki_name):
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
126 exists = bool(self.storage.get_item(**fqname.query))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 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
128 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 exists = True # we can't detect existance of remote items
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
130 if item_name:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
131 breadcrumbs.append((wiki_name, fqname, href, 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
132 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
133
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
134 def subitem_index(self, item_name):
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
135 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
136 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
137
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
138 :rtype: list
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
139 :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
140 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
141 from MoinMoin.items import Item
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
142 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
143 return item.get_mixed_index()
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
144
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 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
146 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147 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
148
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
149 :rtype: tuple
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
150 :returns: arguments of user homepage link in tuple (wiki_href, display_name, 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
151 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 user = self.user
1286
d2704c2a8d39 meta NAME and User.name is always a list of unicode names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1283
diff changeset
153 name = user.name0
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
154 display_name = user.display_name or 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
155 wikiname, itemname = getInterwikiHome(name)
1832
ff503e7ea7a0 merged default into namespaces branch, some stuff XXX BROKEN
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1315 1801
diff changeset
156 title = u"{0} @ {1}".format(display_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
157 # 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
158 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
159 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
160 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 # 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
162 exists = True
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
163 wiki_href = url_for_item(itemname, wiki_name=wikiname)
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
164 return wiki_href, display_name, 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
165
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
166 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
167 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 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
169
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 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
171 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
172
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 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
174 * PageName
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 * 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
176 * 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
177 * url
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 * 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
179
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
180 :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
181 :rtype: tuple
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
182 :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
183 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 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
185 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
186
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 # 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
188 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
189 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
190 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 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
192 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
193 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
194 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
195 # 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
196 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
197 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 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
199
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 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
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 = target
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
203 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
204
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 # 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
206 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
207 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
208
2217
431815d4f4a6 Fixed interwiki patch to deal with new composite name.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2117
diff changeset
209 wiki_name, namespace, field, 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
210 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
211 wiki_name = ''
2217
431815d4f4a6 Fixed interwiki patch to deal with new composite name.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2117
diff changeset
212 href = url_for_item(item_name, namespace=namespace, wiki_name=wiki_name, field=field)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 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
214 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
215 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
216
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
217 @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
218 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
219 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 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
221
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
222 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
223 :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
224 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 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
226 # Process config navi_bar
2043
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
227 items = []
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
228 for cls, endpoint, args, link_text, title in self.cfg.navi_bar:
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
229 if endpoint == "frontend.show_root":
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
230 endpoint = "frontend.show_item"
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
231 args['item_name'] = app.cfg.item_root
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
232 items.append((cls, url_for(endpoint, **args), 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
233
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 # 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
235 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
236 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
237 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
238
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 # 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
240 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
241 if is_local_wiki(sistername):
1885
063c879ef79b sistersites: fix tuple member count
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 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 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
252 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
253 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
254 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 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
256 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
257 except:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
258 pass # ignore invalid lines
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259 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
260 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
261 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
262 except IOError as err:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
263 (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
264 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
265 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
266 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
267 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
268 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
269 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
270
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 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
272 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 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
274
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
275 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
276 :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
277 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278 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
279 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
280 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
281
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
282 # 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
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 # Properties ##############################################################
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
285
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 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
287 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 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
289
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
290 :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
291 :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
292 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 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
294 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
295 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
296 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
297 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
298 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
299
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
301 def get_editor_info(meta, external=False):
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
302 addr = meta.get(ADDRESS)
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 # 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
312 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
313 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
314 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
315 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
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 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
318 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
319 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
320
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
321 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
322 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
323 u = user.User(userid)
1286
d2704c2a8d39 meta NAME and User.name is always a list of unicode names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1283
diff changeset
324 name = u.name0
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
325 text = name
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
326 display_name = u.display_name or 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
327 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
328 # we already have some address info
1832
ff503e7ea7a0 merged default into namespaces branch, some stuff XXX BROKEN
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1315 1801
diff changeset
329 title = u"{0} @ {1}".format(display_name, 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
330 else:
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
331 title = display_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
332 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
333 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
334 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
335 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
336 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
337 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
338 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
339 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
340 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
341 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
342
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
343 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
344 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
345 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
346 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
347 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
348 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
349
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
350
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
351 def shorten_fqname(fqname, length=25):
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
352 """
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
353 Shorten fqname
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
354
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
355 Shorten a given long fqname so that it looks good depending upon whether
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
356 the field is a UUID or not.
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
357
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
358 :param fqname: fqname, namedtuple
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
359 :param length maximum length for shortened fqnames in case the field
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
360 is not a UUID.
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
361 :rtype: unicode
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
362 :returns: shortened fqname.
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
363 """
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
364 name = fqname.value
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
365 if len(name) > length:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
366 if fqname.field in [REVID, ITEMID]:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
367 name = shorten_id(name)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
368 else:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
369 name = shorten_item_name(name, length)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
370 return name
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
371
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
372
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
373 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
374 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375 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
376
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 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
378 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
379 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
380
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
381 :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
382 :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
383 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
384 :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
385 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
386 # 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
387 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
388 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
389 # 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
390 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
391 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
392 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
393 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
394
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
395
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
396 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
397 """
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
398 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
399
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
400 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
401 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
402
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
403 :param name: item name, unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
404 :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
405 :rtype: unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
406 :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
407 """
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
408
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
409 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
410
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
411 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
412 '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
413 '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
414 '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
415 '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
416 '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
417 '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
418 '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
419 }
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
420
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
421
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
422 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
423 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
424 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
425 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
426 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
427 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
428 # 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
429 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
430 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
431
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
432
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
433 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
434 """
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
435 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
436
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
437 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
438 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
439 """
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
440 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
441 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
442
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
443
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
444 def setup_jinja_env():
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2217
diff changeset
445 app.jinja_env.filters['shorten_fqname'] = shorten_fqname
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446 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
447 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
448 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
1145
5421be737643 Simplify string escaping filter.
Sam Toyer <samATqxcvDOTnet>
parents: 1144
diff changeset
449 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
450 # 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
451 # 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
452
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 app.jinja_env.globals.update({
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
454 # please note that flask-babel/jinja2.ext installs:
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
455 # _, gettext, ngettext
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
456 'isinstance': isinstance,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
457 'list': list,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
458 'Type': Type,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
459 # please note that flask-themes installs:
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
460 # theme, theme_static
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
461 'theme_supp': ThemeSupport(app.cfg),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
462 'user': flaskg.user,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
463 'storage': flaskg.storage,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
464 'clock': flaskg.clock,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
465 'cfg': app.cfg,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
466 'item_name': u'handlers need to give it',
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
467 'url_for_item': url_for_item,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
468 'get_editor_info': lambda meta: get_editor_info(meta),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
469 'utctimestamp': lambda dt: utctimestamp(dt),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
470 'gen': make_generator(),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
471 'search_form': SearchForm.from_defaults(),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
472 })