annotate MoinMoin/themes/__init__.py @ 2446:10666a449e7b

updated icon for highlight
author sharky93 <rishabhr123@gmail.com>
date Sun, 08 Sep 2013 14:54:47 +0530
parents 357e884dc642
children 7fb6bff63aa0
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
1973
286e315935ae refactor usage of constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1932
diff changeset
25 from MoinMoin.constants.keys import USERID, ADDRESS, HOSTNAME
1227
18cb4213fc4d Always show search box in layout.html
Sam Toyer <samATqxcvDOTnet>
parents: 1145
diff changeset
26 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
27 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
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
2395
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
82 def get_action_tabs(self, item_name, current_endpoint):
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
83 navtabs_endpoints = ['frontend.show_item', 'frontend.history',
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
84 'frontend.show_item_meta', 'frontend.highlight_item', 'frontend.backrefs',
2424
8bf6121e6366 Fixes #38, adds bootstrap checkboxes for transclusions and comments
sharky93 <rishabhr123@gmail.com>
parents: 2412
diff changeset
85 ]
2380
7df17df524e7 adds helper function to render action tabs
sharky93 <rishabhr123@gmail.com>
parents: 2328
diff changeset
86 if self.user.may.write(item_name):
2395
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
87 navtabs_endpoints.append('frontend.modify_item')
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
88
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
89 icon = self.get_endpoint_iconmap()
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
90 exists = flaskg.storage.has_item(item_name)
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
91 navtabs = []
2396
35b64d97bd9c Fixes #39, by making the history tab active for diff views
sharky93 <rishabhr123@gmail.com>
parents: 2395
diff changeset
92 spl_active = [('frontend.history', 'frontend.diff'),]
2395
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
93
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
94 for endpoint, label, title, check_exists in app.cfg.item_views:
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
95 if endpoint not in app.cfg.endpoints_excluded:
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
96 if not check_exists or exists:
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
97 if endpoint in navtabs_endpoints:
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
98
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
99 iconcls = icon[endpoint]
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
100
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
101 if endpoint == 'special.comments':
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
102 maincls = "moin-toggle-comments-button"
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
103 href = "#"
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
104 elif endpoint == 'special.transclusions':
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
105 maincls = "moin-transclusions-button"
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
106 href = "#"
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
107 else:
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
108 maincls = None
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
109 href = url_for(endpoint, item_name=item_name)
2396
35b64d97bd9c Fixes #39, by making the history tab active for diff views
sharky93 <rishabhr123@gmail.com>
parents: 2395
diff changeset
110 if endpoint == current_endpoint or (endpoint, current_endpoint) in spl_active:
2395
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
111 maincls = "active"
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
112
e0a4950b9658 Refactored tab views code, major part on python side
sharky93 <rishabhr123@gmail.com>
parents: 2394
diff changeset
113 navtabs.append((endpoint, href, maincls, iconcls, title, label))
2380
7df17df524e7 adds helper function to render action tabs
sharky93 <rishabhr123@gmail.com>
parents: 2328
diff changeset
114 return navtabs
7df17df524e7 adds helper function to render action tabs
sharky93 <rishabhr123@gmail.com>
parents: 2328
diff changeset
115
2381
aa19b1b69b5c adds helper function to render the local panel
sharky93 <rishabhr123@gmail.com>
parents: 2380
diff changeset
116 def get_local_panel(self, item_name):
2393
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
117 user_actions_endpoints = ['frontend.quicklink_item', 'frontend.subscribe_item', ]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
118 item_navigation_endpoints = ['frontend.index', 'frontend.sitemap', ]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
119 item_actions_endpoints = ['frontend.rename_item', 'frontend.delete_item', 'frontend.destroy_item',
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
120 'frontend.similar_names', 'frontend.download_item',
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
121 'frontend.copy_item', 'special.supplementation'] if self.user.may.write(item_name) else []
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
122
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
123 user_actions = []
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
124 item_navigation = []
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
125 item_actions = []
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
126
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
127 icon = self.get_endpoint_iconmap()
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
128 exists = flaskg.storage.has_item(item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
129
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
130 for endpoint, label, title, check_exists in app.cfg.item_views:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
131 if endpoint not in app.cfg.endpoints_excluded:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
132 if not check_exists or exists:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
133 if endpoint in user_actions_endpoints:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
134 if flaskg.user.valid:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
135 href = url_for(endpoint, item_name=item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
136 iconcls = icon[endpoint]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
137 #endpoint = iconcls = label = None
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
138
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
139 if endpoint == 'frontend.quicklink_item':
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
140 if not flaskg.user.is_quicklinked_to([item_name]):
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
141 label = _('Add Link')
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
142 user_actions.append((endpoint, href, iconcls, label, title))
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
143 elif endpoint == 'frontend.subscribe_item':
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
144 if flaskg.user.is_subscribed_to([item_name]):
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
145 label = _('Unsubscribe')
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
146 else:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
147 label = _('Subscribe')
2435
2188b5fe3b89 fixes broken user_actions panel (unsubscribe)
sharky93 <rishabhr123@gmail.com>
parents: 2424
diff changeset
148 user_actions.append((endpoint, href, iconcls, label, title))
2393
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
149
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
150 elif endpoint in item_actions_endpoints:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
151
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
152 iconcls = icon[endpoint]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
153
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
154 if endpoint == 'special.supplementation':
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
155 for sub_item_name in app.cfg.supplementation_item_names:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
156 current_sub = item_name.rsplit('/', 1)[-1]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
157 if current_sub not in app.cfg.supplementation_item_names:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
158 supp_name = '%s/%s' % (item_name, sub_item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
159 if flaskg.storage.has_item(supp_name) or flaskg.user.may.write(supp_name):
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
160 href = url_for('frontend.show_item', item_name=supp_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
161 label = _(sub_item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
162 title = None
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
163
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
164 item_actions.append((endpoint, href, iconcls, label, title))
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
165 else:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
166 href = url_for(endpoint, item_name=item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
167 item_actions.append((endpoint, href, iconcls, label, title))
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
168
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
169 elif endpoint in item_navigation_endpoints:
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
170
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
171 iconcls = icon[endpoint]
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
172 href = url_for(endpoint, item_name=item_name)
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
173
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
174 item_navigation.append((endpoint, href, iconcls, label, title))
0cb9f75fb9ba Refactored local_panel rendering code, almost everything processed on python side
sharky93 <rishabhr123@gmail.com>
parents: 2387
diff changeset
175
2381
aa19b1b69b5c adds helper function to render the local panel
sharky93 <rishabhr123@gmail.com>
parents: 2380
diff changeset
176 return user_actions, item_navigation, item_actions
aa19b1b69b5c adds helper function to render the local panel
sharky93 <rishabhr123@gmail.com>
parents: 2380
diff changeset
177
2387
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
178 def get_endpoint_iconmap(self):
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
179 icon = {'frontend.quicklink_item' : "icon-star-empty",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
180 'frontend.subscribe_item' : "icon-envelope",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
181 'frontend.index' : "icon-list-alt",
2445
357e884dc642 updated icon for sitemap
sharky93 <rishabhr123@gmail.com>
parents: 2444
diff changeset
182 'frontend.sitemap' : "icon-sitemap",
2387
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
183 'frontend.rename_item' : "icon-tag",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
184 'frontend.delete_item' : "icon-trash",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
185 'frontend.destroy_item' : "icon-fire",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
186 'frontend.similar_names' : "icon-search",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
187 'frontend.download_item' : "icon-download-alt",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
188 'frontend.copy_item' : "icon-comment",
2444
64ad5138ec68 updated icon for Discussion
sharky93 <rishabhr123@gmail.com>
parents: 2435
diff changeset
189 'special.supplementation' : "icon-comments",
2387
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
190 'frontend.show_item' : "icon-eye-open",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
191 'frontend.modify_item' : "icon-pencil",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
192 'frontend.history' : "icon-time",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
193 'frontend.show_item_meta' : "icon-wrench",
2446
10666a449e7b updated icon for highlight
sharky93 <rishabhr123@gmail.com>
parents: 2445
diff changeset
194 'frontend.highlight_item' : "icon-code",
2387
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
195 'frontend.backrefs' : "icon-share",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
196 'special.comments' : "icon-comment",
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
197 'special.transclusions' : "icon-edit",};
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
198 return icon
9bf41329f031 icon dict to map endpoints with icon retrieved from helper functions
sharky93 <rishabhr123@gmail.com>
parents: 2381
diff changeset
199
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 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
201 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 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
203
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
204 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
205 :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
206 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 breadcrumbs = []
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 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
209 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
210 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
211 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
212 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
213 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
214
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 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
216 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 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
218
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
219 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
220 :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
221 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 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
223 breadcrumbs = []
1281
0a70177ce4de user: changed method names for better PEP8 compliance
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1278
diff changeset
224 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
225 for interwiki_item_name in trail:
1315
005e12de8b6a interwiki and namespaces related url generation and split adapted to namespaces. Proper documentation still missing.
Bruno Martin <bruno.martin@hacklab.com.br>
parents: 1286
diff changeset
226 wiki_name, namespace, 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
227 err = not is_known_wiki(wiki_name)
1315
005e12de8b6a interwiki and namespaces related url generation and split adapted to namespaces. Proper documentation still missing.
Bruno Martin <bruno.martin@hacklab.com.br>
parents: 1286
diff changeset
228 href = url_for_item(item_name, namespace=namespace, wiki_name=wiki_name)
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
229 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
230 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
231 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
232 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233 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
234 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
235 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
236
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
237 def subitem_index(self, item_name):
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
238 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
239 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
240
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
241 :rtype: list
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
242 :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
243 """
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
244 from MoinMoin.items import Item
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
245 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
246 return item.get_mixed_index()
1123
ebc4f8213e74 Add a flat subitem index for show item view.
Sam Toyer <samATqxcvDOTnet>
parents: 1110
diff changeset
247
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 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
249 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 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
251
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
252 :rtype: tuple
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
253 :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
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 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
256 name = user.name0
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
257 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
258 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
259 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
260 # 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
261 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
262 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
263 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264 # 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
265 exists = True
313
8fa4a76d71ff cleanup interwiki code, new easier/more powerful functions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
266 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
267 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
268
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
269 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
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 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
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 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
274 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
275
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 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
277 * PageName
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278 * 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
279 * 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
280 * url
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 * 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
282
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
283 :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
284 :rtype: tuple
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
285 :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
286 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
287 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
288 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
289
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 # 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
291 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
292 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
293 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294 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
295 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
296 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
297 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
298 # 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
299 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
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 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
302
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 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
304 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
305 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
306 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
307
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 # 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
309 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
310 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
311
1315
005e12de8b6a interwiki and namespaces related url generation and split adapted to namespaces. Proper documentation still missing.
Bruno Martin <bruno.martin@hacklab.com.br>
parents: 1286
diff changeset
312 wiki_name, namespace, 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
313 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
314 wiki_name = ''
1315
005e12de8b6a interwiki and namespaces related url generation and split adapted to namespaces. Proper documentation still missing.
Bruno Martin <bruno.martin@hacklab.com.br>
parents: 1286
diff changeset
315 href = url_for_item(item_name, namespace=namespace, 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
316 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
317 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
318 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
319
1764
19b19d4d9291 Add a @timed decorator.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1726
diff changeset
320 @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
321 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
322 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
323 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
324
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
325 :rtype: list
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
326 :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
327 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
328 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
329 # 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
330 items = []
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
331 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
332 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
333 endpoint = "frontend.show_item"
423d8d791cc9 Fix for Issue#291, home link now coloured as should be
sharky93 <rishabhr123@gmail.com>
parents: 2011
diff changeset
334 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
335 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
336
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
337 # 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
338 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
339 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
340 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
341
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342 # 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
343 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
344 if is_local_wiki(sistername):
1885
063c879ef79b sistersites: fix tuple member count
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
353 sisteritems = {}
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
354 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
355 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
356 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
357 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358 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
359 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
360 except:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
361 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
362 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
363 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
364 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
365 except IOError as err:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
366 (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
367 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
368 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
369 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
370 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
371 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
372 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
373
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374 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
375 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 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
377
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
378 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
379 :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
380 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 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
382 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
383 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
384
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385 # 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
386
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
387 # Properties ##############################################################
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
388
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
389 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
390 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
391 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
392
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
393 :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
394 :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
395 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
396 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
397 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
398 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
399 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
400 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
401 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
402
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
404 def get_editor_info(meta, external=False):
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
405 addr = meta.get(ADDRESS)
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
406 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
407 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
408 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
409 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
410 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
411 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
412 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
413 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
414 # 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
415 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
416 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
417 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
418 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
419 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
420 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
421 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
422 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
423
861
9a7889c04a25 fixed history view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 859
diff changeset
424 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
425 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
426 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
427 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
428 text = name
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
429 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
430 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
431 # 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
432 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
433 else:
1063
ee71ed6e97c6 change user.aliasname to user.display_name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 969
diff changeset
434 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
435 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
436 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
437 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
438 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
439 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
440 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
441 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
442 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
443 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
444 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
445
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446 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
447 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
448 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
449 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
450 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
451 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
452
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
453
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454 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
455 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
456 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
457
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
458 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
459 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
460 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
461
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
462 :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
463 :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
464 :rtype: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
465 :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
466 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467 # 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
468 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
469 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
470 # 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
471 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
472 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
473 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
474 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
475
2409
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
476 CONTENTTYPE_SHORTEN = {
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
477 'text/x.moin.wiki': 'MoinWiki',
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
478 }
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
479
2410
89ce7644a01d Adds todo for more content-types
sharky93 <rishabhr123@gmail.com>
parents: 2409
diff changeset
480 # TODO: Update dictionary with more content-types
2409
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
481 def shorten_content_type(contenttype):
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
482 """
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
483 Shorten content-types
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
484
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
485 Shortens the content-type to terms that normal users understand.
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
486
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
487 :param name: contenttype, unicode
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
488 :rtype: unicode
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
489 :returns: shortened version of contenttype
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
490 """
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
491 ctype = contenttype.split(';')[0]
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
492 if ctype in CONTENTTYPE_SHORTEN:
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
493 return CONTENTTYPE_SHORTEN[ctype]
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
494 else:
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
495 return "Unknown"
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
496
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
497 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
498 """
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
499 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
500
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
501 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
502 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
503
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
504 :param name: item name, unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
505 :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
506 :rtype: unicode
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
507 :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
508 """
b703c5e590a3 Create new template filter "shorten_revid" which shortens the specified text to 7 chars
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 969
diff changeset
509
1110
5479a3b62b9f Change shorten_revid to shorten_id everywhere.
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1109
diff changeset
510 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
511
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
512 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
513 '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
514 '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
515 '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
516 '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
517 '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
518 '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
519 '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
520 }
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
521
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
522
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
523 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
524 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
525 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
526 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
527 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
528 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
529 # 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
530 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
531 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
532
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
533
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
534 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
535 """
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
536 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
537
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
538 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
539 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
540 """
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
541 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
542 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
543
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
544
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
545 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
546 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
547 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
548 app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
1145
5421be737643 Simplify string escaping filter.
Sam Toyer <samATqxcvDOTnet>
parents: 1144
diff changeset
549 app.jinja_env.filters['json_dumps'] = dumps
2409
51b90beddc7c Shortens contenttype display in the history view
sharky93 <rishabhr123@gmail.com>
parents: 2396
diff changeset
550 app.jinja_env.filters['shorten_ctype'] = shorten_content_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
551 # 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
552 # 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
553
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
554 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
555 # 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
556 # _, gettext, ngettext
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
557 'isinstance': isinstance,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
558 'list': list,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
559 'Type': Type,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
560 # 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
561 # theme, theme_static
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
562 '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
563 'user': flaskg.user,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
564 'storage': flaskg.storage,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
565 'clock': flaskg.clock,
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
566 'cfg': app.cfg,
2328
5d61b26cad7c Fixes highlight of current item without JS
sharky93 <rishabhr123@gmail.com>
parents: 2117
diff changeset
567 'item_name': u'@NONAMEGIVEN',
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
568 '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
569 '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
570 '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
571 'gen': make_generator(),
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1975
diff changeset
572 '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
573 })