annotate MoinMoin/apps/frontend/views.py @ 484:19b257c0e102

code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
author Akash Sinha <akash2607@gmail.com>
date Sat, 09 Jul 2011 00:11:02 +0530
parents 4307261bac75
children 3a3aea61aa1b
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
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
2 # Copyright: 2011 MoinMoin:AkashSinha
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
3 # Copyright: 2008 MoinMoin:FlorianKrupicka
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
4 # Copyright: 2010 MoinMoin:DiogenesAugusto
37
74a543f57ce7 docstrings: fix some typos, move some (c) infos to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
5 # Copyright: 2001 Richard Jones <richard@bizarsoftware.com.au>
74a543f57ce7 docstrings: fix some typos, move some (c) infos to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 26
diff changeset
6 # Copyright: 2001 Juergen Hermann <jh@web.de>
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
7 # 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
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 MoinMoin - frontend views
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 This shows the usual things users see when using the wiki.
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
13 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 import re
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 import difflib
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 import time
456
6177be92aa33 format_date now formatting the timestamp based on user's time zone when he is logged in otherwise showing the utc datetime
Akash Sinha <akash2607@gmail.com>
parents: 455
diff changeset
19 from flaskext.babel import format_date
454
b07dfe4ceb8d Grouping of global history done on the date basis.
Akash Sinha <akash2607@gmail.com>
parents: 233
diff changeset
20 from datetime import datetime
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 from itertools import chain
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
22 from collections import namedtuple, OrderedDict
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
24 from flask import request, url_for, flash, Response, redirect, session, abort, jsonify
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 from 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: 102
diff changeset
26 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
27 from flaskext.themes import get_themes_list
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 from flatland import Form, String, Integer, Boolean, Enum
469
82261b274b68 Option to configure result count per page for pagination of history results, added in usersettings.
Akash Sinha <akash2607@gmail.com>
parents: 468
diff changeset
30 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted, ValueAtLeast
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 from jinja2 import Markup
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 import pytz
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 from babel import Locale
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 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
38 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
39
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 from MoinMoin.i18n import _, L_, N_
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
41 from MoinMoin.themes import render_template, get_editor_info
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 from MoinMoin.apps.frontend import frontend
102
c084c1369078 move metadata name constant defs to MoinMoin.config
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 96
diff changeset
43 from MoinMoin.items import Item, NonExistent
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 from MoinMoin.items import ROWS_META, COLS, ROWS_DATA
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 from MoinMoin import config, user, wikiutil
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
46 from MoinMoin.config import ACTION, COMMENT, CONTENTTYPE, ITEMLINKS, ITEMTRANSCLUSIONS, 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
47 from MoinMoin.util.forms import make_generator
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 159
diff changeset
48 from MoinMoin.util import crypto
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 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 from MoinMoin.storage.error import NoSuchItemError, NoSuchRevisionError, AccessDeniedError
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 from MoinMoin.signalling import item_displayed, item_modified
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 @frontend.route('/+dispatch', methods=['GET', ])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 def dispatch():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 args = request.values.to_dict()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 endpoint = str(args.pop('endpoint'))
116
25723df2d237 dispatch: do not give unneeded args to endpoints not wanting them
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
58 # filter args given to url_for, so that no unneeded args end up in query string:
25723df2d237 dispatch: do not give unneeded args to endpoints not wanting them
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
59 args = dict([(k, args[k]) for k in args
25723df2d237 dispatch: do not give unneeded args to endpoints not wanting them
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 109
diff changeset
60 if app.url_map.is_endpoint_expecting(endpoint, k)])
0
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 redirect(url_for(endpoint, **args))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 @frontend.route('/')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 def show_root():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 item_name = app.cfg.item_root
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
67 location = url_for('.show_item', item_name=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
68 return redirect(location)
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 @frontend.route('/robots.txt')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 def robots():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 return Response("""\
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 User-agent: *
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 Crawl-delay: 20
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 Disallow: /+convert/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 Disallow: /+dom/
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
77 Disallow: /+download/
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 Disallow: /+modify/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 Disallow: /+copy/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 Disallow: /+delete/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 Disallow: /+destroy/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 Disallow: /+rename/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 Disallow: /+revert/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 Disallow: /+index/
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
85 Disallow: /+index2/
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
86 Disallow: /+jfu-server/
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 Disallow: /+sitemap/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 Disallow: /+similar_names/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 Disallow: /+quicklink/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 Disallow: /+subscribe/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 Disallow: /+backrefs/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 Disallow: /+wanteds/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 Disallow: /+orphans/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 Disallow: /+register
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 Disallow: /+recoverpass
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 Disallow: /+usersettings
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 Disallow: /+login
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 Disallow: /+logout
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 Disallow: /+bookmark
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 Disallow: /+diffsince/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 Disallow: /+diff/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 Disallow: /+diffraw/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 Disallow: /+dispatch/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 Disallow: /+admin/
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 Allow: /
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 """, mimetype='text/plain')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 @frontend.route('/favicon.ico')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 def favicon():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 # although we tell that favicon.ico is at /static/logos/favicon.ico,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 # some browsers still request it from /favicon.ico...
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 return app.send_static_file('logos/favicon.ico')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 @frontend.route('/<itemname:item_name>', defaults=dict(rev=-1))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 @frontend.route('/+show/<int:rev>/<itemname: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
118 def show_item(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 flaskg.user.addTrail(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
120 item_displayed.send(app._get_current_object(),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 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
122 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 item = Item.create(item_name, rev_no=rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 abort(403)
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
126 show_revision = show_navigation = rev >= 0
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
127 # Note: rev.revno of DummyRev is None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
128 first_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
129 last_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
130 if show_navigation:
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
131 rev_nos = item.rev.item.list_revisions()
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
132 if rev_nos:
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
133 first_rev = rev_nos[0]
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
134 last_rev = rev_nos[-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
135 if isinstance(item, NonExistent):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 status = 404
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 status = 200
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 content = render_template('show.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 item=item, 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
141 rev=item.rev,
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
142 contenttype=item.contenttype,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 first_rev_no=first_rev,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 last_rev_no=last_rev,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 data_rendered=Markup(item._render_data()),
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
146 show_revision=show_revision,
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
147 show_navigation=show_navigation,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149 return Response(content, status)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152 @frontend.route('/+show/<itemname: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
153 def redirect_show_item(item_name):
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
154 return redirect(url_for('.show_item', item_name=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
155
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 @frontend.route('/+dom/<int:rev>/<itemname: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
158 @frontend.route('/+dom/<itemname:item_name>', defaults=dict(rev=-1))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 def show_dom(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161 item = Item.create(item_name, rev_no=rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 if isinstance(item, NonExistent):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 status = 404
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 status = 200
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 content = render_template('dom.xml',
197
19e92e1ff286 fix the +dom view, details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 194
diff changeset
169 data_xml=Markup(item._render_data_xml()),
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171 return Response(content, status, mimetype='text/xml')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
174 @frontend.route('/+highlight/<int:rev>/<itemname:item_name>')
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
175 @frontend.route('/+highlight/<itemname:item_name>', defaults=dict(rev=-1))
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
176 def highlight_item(item_name, rev):
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
177 try:
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
178 item = Item.create(item_name, rev_no=rev)
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
179 except AccessDeniedError:
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
180 abort(403)
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
181 return render_template('highlight.html',
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
182 item=item, item_name=item.name,
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
183 data_text=Markup(item._render_data_highlight()),
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
184 )
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
185
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
186
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 @frontend.route('/+meta/<itemname:item_name>', defaults=dict(rev=-1))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 @frontend.route('/+meta/<int:rev>/<itemname: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
189 def show_item_meta(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 flaskg.user.addTrail(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
191 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 item = Item.create(item_name, rev_no=rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 abort(403)
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
195 show_revision = show_navigation = rev >= 0
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
196 # Note: rev.revno of DummyRev is None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
197 first_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
198 last_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
199 if show_navigation:
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
200 rev_nos = item.rev.item.list_revisions()
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
201 if rev_nos:
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
202 first_rev = rev_nos[0]
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
203 last_rev = rev_nos[-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
204 return render_template('meta.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205 item=item, 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
206 rev=item.rev,
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
207 contenttype=item.contenttype,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 first_rev_no=first_rev,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 last_rev_no=last_rev,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 meta_rendered=Markup(item._render_meta()),
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
211 show_revision=show_revision,
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
212 show_navigation=show_navigation,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 )
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
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 @frontend.route('/+get/<int:rev>/<itemname: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
217 @frontend.route('/+get/<itemname:item_name>', defaults=dict(rev=-1))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 def get_item(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 item = Item.create(item_name, rev_no=rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 return item.do_get()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224
255
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
225 @frontend.route('/+download/<int:rev>/<itemname:item_name>')
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
226 @frontend.route('/+download/<itemname:item_name>', defaults=dict(rev=-1))
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
227 def download_item(item_name, rev):
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
228 try:
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
229 item = Item.create(item_name, rev_no=rev)
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
230 except AccessDeniedError:
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
231 abort(403)
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
232 return item.do_get(force_attachment=True)
76a4e3cc8705 add +download view for just downloading a revision with forced content-disposition: attachment
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 250
diff changeset
233
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 @frontend.route('/+convert/<itemname: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
235 def convert_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
236 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 return a converted item.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 We create two items : the original one, and an empty
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 one with the expected mimetype for the converted item.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 To get the converted item, we just feed his converter,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 with the internal representation of the item.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
245 contenttype = request.values.get('contenttype')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 item = Item.create(item_name, rev_no=-1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 # We don't care about the name of the converted object
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 # It should just be a name which does not exist.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 # XXX Maybe use a random name to be sure it does not exist
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 item_name_converted = item_name + 'converted'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 try:
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
255 converted_item = Item.create(item_name_converted, contenttype=contenttype)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258 return converted_item._convert(item.internal_representation())
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 237
diff changeset
260
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
261 @frontend.route('/+modify/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 def modify_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
263 """Modify the wiki 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
264
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265 On GET, displays a form.
237
ec37a42f6fd2 item modify ui: remove cancel button (user can just click anywhere else than on SAVE)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 233
diff changeset
266 On POST, saves the new page (unless there's an error in input).
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267 After successful POST, redirects to the page.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
269 contenttype = request.values.get('contenttype')
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 template_name = request.values.get('template')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
271 try:
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
272 item = Item.create(item_name, contenttype=contenttype)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274 abort(403)
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 237
diff changeset
275 if not flaskg.user.may.write(item_name):
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 237
diff changeset
276 abort(403)
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 237
diff changeset
277 return item.do_modify(contenttype, template_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
278
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
280 class CommentForm(TextChaizedForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
281 comment = String.using(label=L_('Comment'), optional=True).with_properties(placeholder=L_("Comment about your change"))
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
282 submit = String.using(default=L_('OK'), optional=True)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
283
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
284 class TargetCommentForm(CommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
285 target = String.using(label=L_('Target')).with_properties(placeholder=L_("The name of the target item")).validated_by(Present())
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
286
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
287 class RevertItemForm(CommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
288 name = 'revert_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
289
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
290 class DeleteItemForm(CommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
291 name = 'delete_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
292
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
293 class DestroyItemForm(CommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
294 name = 'destroy_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
295
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
296 class CopyItemForm(TargetCommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
297 name = 'copy_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
298
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
299 class RenameItemForm(TargetCommentForm):
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
300 name = 'rename_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
301
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
302
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 @frontend.route('/+revert/<int:rev>/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 def revert_item(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
305 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 item = Item.create(item_name, rev_no=rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308 abort(403)
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 request.method == 'GET':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
310 form = RevertItemForm.from_defaults()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
311 TextCha(form).amend_form()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 elif request.method == 'POST':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
313 form = RevertItemForm.from_flat(request.form)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
314 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
315 if form.validate():
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 item.revert()
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
317 return redirect(url_for('.show_item', item_name=item_name))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
318 return render_template(item.revert_template,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
319 item=item, item_name=item_name,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
320 rev_no=rev,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
321 form=form,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
322 gen=make_generator(),
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
323 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
324
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
325
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
326 @frontend.route('/+copy/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
327 def copy_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
328 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
329 item = Item.create(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
330 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
331 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
332 if request.method == 'GET':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
333 form = CopyItemForm.from_defaults()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
334 TextCha(form).amend_form()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
335 form['target'] = item.name
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
336 elif request.method == 'POST':
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
337 form = CopyItemForm.from_flat(request.form)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
338 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
339 if form.validate():
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
340 target = form['target'].value
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
341 comment = form['comment'].value
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
342 item.copy(target, comment)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
343 return redirect(url_for('.show_item', item_name=target))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
344 return render_template(item.copy_template,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
345 item=item, item_name=item_name,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
346 form=form,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
347 gen=make_generator(),
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
348 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
349
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
350
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
351 @frontend.route('/+rename/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
352 def rename_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
353 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
354 item = Item.create(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
355 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357 if request.method == 'GET':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
358 form = RenameItemForm.from_defaults()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
359 TextCha(form).amend_form()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
360 form['target'] = item.name
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
361 elif request.method == 'POST':
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
362 form = RenameItemForm.from_flat(request.form)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
363 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
364 if form.validate():
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
365 target = form['target'].value
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
366 comment = form['comment'].value
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
367 item.rename(target, comment)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
368 return redirect(url_for('.show_item', item_name=target))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
369 return render_template(item.rename_template,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
370 item=item, item_name=item_name,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
371 form=form,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
372 gen=make_generator(),
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
373 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 @frontend.route('/+delete/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 def delete_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
378 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
379 item = Item.create(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
380 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 abort(403)
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 request.method == 'GET':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
383 form = DeleteItemForm.from_defaults()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
384 TextCha(form).amend_form()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385 elif request.method == 'POST':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
386 form = DeleteItemForm.from_flat(request.form)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
387 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
388 if form.validate():
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
389 comment = form['comment'].value
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
390 item.delete(comment)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
391 return redirect(url_for('.show_item', item_name=item_name))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
392 return render_template(item.delete_template,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
393 item=item, item_name=item_name,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
394 form=form,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
395 gen=make_generator(),
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
396 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
397
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
398
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
399 @frontend.route('/+destroy/<int:rev>/<itemname:item_name>', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
400 @frontend.route('/+destroy/<itemname:item_name>', methods=['GET', 'POST'], defaults=dict(rev=None))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
401 def destroy_item(item_name, rev):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402 if rev 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
403 # no revision given
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 _rev = -1 # for item creation
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 destroy_item = True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
407 _rev = rev
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
408 destroy_item = False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
409 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
410 item = Item.create(item_name, rev_no=_rev)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
412 abort(403)
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 request.method == 'GET':
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
414 form = DestroyItemForm.from_defaults()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
415 TextCha(form).amend_form()
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
416 elif request.method == 'POST':
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
417 form = DestroyItemForm.from_flat(request.form)
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
418 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
419 if form.validate():
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
420 comment = form['comment'].value
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 item.destroy(comment=comment, destroy_item=destroy_item)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
422 return redirect(url_for('.show_item', item_name=item_name))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
423 return render_template(item.destroy_template,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
424 item=item, item_name=item_name,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
425 rev_no=rev,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
426 form=form,
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
427 gen=make_generator(),
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
428 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
430
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
431 # XXX this has some functional redundancy with "index", solve that later
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
432 @frontend.route('/+index2/<itemname:item_name>', methods=['GET'])
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
433 def index2(item_name):
271
8a21b92d8985 use package XStatic-jQuery-File-Upload, require it in setup.py, remove it from quickinstall
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 270
diff changeset
434 # flat index using jquery-file-upload (see also jfu_server)
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
435 return render_template('index2.html',
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
436 item_name=item_name,
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
437 )
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
438
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
439 @frontend.route('/+jfu-server/<itemname:item_name>', methods=['GET', 'POST'])
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
440 def jfu_server(item_name):
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
441 """jquery-file-upload server component
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
442 """
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
443 if request.method == 'GET':
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
444 try:
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
445 item = Item.create(item_name)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
446 except AccessDeniedError:
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
447 abort(403)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
448 files = []
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
449 for full_name, rel_name, mimetype in item.flat_index():
270
2c12608c7c38 fix url generation for jquery-file-upload, use download instead of get for DL link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 266
diff changeset
450 url = url_for('.show_item', item_name=full_name)
2c12608c7c38 fix url generation for jquery-file-upload, use download instead of get for DL link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 266
diff changeset
451 url_download = url_for('.download_item', item_name=full_name)
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
452 files.append(dict(name=rel_name, url=url, url_download=url_download, size=0))
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
453 return jsonify(files=files)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
454 if request.method == 'POST':
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
455 data_file = request.files.get('data_file')
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
456 subitem_name = data_file.filename
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
457 item_name = item_name + u'/' + subitem_name
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
458 try:
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
459 item = Item.create(item_name)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
460 revno, size = item.modify()
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
461 item_modified.send(app._get_current_object(),
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
462 item_name=item_name)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
463 return jsonify(name=subitem_name,
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
464 size=size,
270
2c12608c7c38 fix url generation for jquery-file-upload, use download instead of get for DL link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 266
diff changeset
465 url=url_for('.show_item', item_name=item_name, rev=revno),
2c12608c7c38 fix url generation for jquery-file-upload, use download instead of get for DL link
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 266
diff changeset
466 url_download=url_for('.download_item', item_name=item_name, rev=revno),
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
467 )
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
468 except AccessDeniedError:
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
469 abort(403)
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
470
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
471
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
472
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473 @frontend.route('/+index/<itemname: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
474 def index(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
475 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 item = Item.create(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
477 except AccessDeniedError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
478 abort(403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
479 index = item.flat_index()
483
4307261bac75 item index view modified
Akash Sinha <akash2607@gmail.com>
parents: 479
diff changeset
480
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 483
diff changeset
481 detailed_index = item.get_detailed_index(index)
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 483
diff changeset
482 detailed_index.sort()
483
4307261bac75 item index view modified
Akash Sinha <akash2607@gmail.com>
parents: 479
diff changeset
483 split_char = u'/'
4307261bac75 item index view modified
Akash Sinha <akash2607@gmail.com>
parents: 479
diff changeset
484 item_names = item_name.split(split_char)
4307261bac75 item index view modified
Akash Sinha <akash2607@gmail.com>
parents: 479
diff changeset
485
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
486 return render_template(item.index_template,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487 item=item, item_name=item_name,
484
19b257c0e102 code to get the subitem index flag has been refactored and moved under items/__init__.py and also unitest is added for the same.
Akash Sinha <akash2607@gmail.com>
parents: 483
diff changeset
488 index=detailed_index,
483
4307261bac75 item index view modified
Akash Sinha <akash2607@gmail.com>
parents: 479
diff changeset
489 item_names=item_names
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
490 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
491
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493 @frontend.route('/+index')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494 def global_index():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495 item = Item.create('') # XXX hack: item_name='' gives toplevel index
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
496 startswith = request.values.get('startswith', None)
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
497 index = item.flat_index(startswith)
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
498 if startswith:
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
499 initials = item.name_initial(item.flat_index())
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
500 # if startswith was set, we would get the filtered index above
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
501 # so inorder to get initial of all elements we need all index, not filtered one
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
502 else:
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
503 initials = item.name_initial(index)
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
504 initials = [initial.upper() for initial in initials]
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
505 initials = list(set(initials))
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
506 initials.sort()
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
507 index_more_links = []
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
508 for fullname, relname, contenttype in index:
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
509 test_item = item.create(fullname)
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
510 item_index = test_item.flat_index()
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
511 hassubitem = False
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
512 if item_index:
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
513 hassubitem = True
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
514 index_more_links.append((fullname, relname, contenttype, hassubitem))
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
515 index_more_links.sort()
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
516
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
517 item_name = request.values.get('item_name', '') # actions menu puts it into qs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518 return render_template('global_index.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
519 item_name=item_name, # XXX no item
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
520 index=index_more_links,
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
521 initials=initials,
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
522 startswith=startswith,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
523 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
524
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
525
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
526 @frontend.route('/+backrefs/<itemname: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
527 def backrefs(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
528 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
529 Returns the list of all items that link or transclude 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
530
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
531 :param item_name: the name of the current item
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
532 :type item_name: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
533 :returns: a page with all the items which link or transclude 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
534 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
535 refs_here = _backrefs(flaskg.storage.iteritems(), 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
536 return render_template('item_link_list.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
537 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
538 headline=_(u'Refers Here'),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
539 item_names=refs_here
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
540 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
541
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
542
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
543 def _backrefs(items, 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
544 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
545 Returns a list with all names of items which ref 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
546
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
547 :param items: all the items
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
548 :type items: iteratable sequence
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
549 :param item_name: the name of the item transcluded or linked
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
550 :type item_name: unicode
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
551 :returns: the list of all items which ref 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
552 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
553 refs_here = []
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
554 for item in items:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
555 current_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
556 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
557 current_revision = item.get_revision(-1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
558 except NoSuchRevisionError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
559 continue
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
560 links = current_revision.get(ITEMLINKS, [])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
561 transclusions = current_revision.get(ITEMTRANSCLUSIONS, [])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
562
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
563 refs = set(links + transclusions)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
564 if item_name in refs:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
565 refs_here.append(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
566 return refs_here
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
567
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
568
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
569 @frontend.route('/+search')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
570 def search():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
571 return _search()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
572
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
573
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
574 def _search(**args):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
575 return "searching for %r not implemented yet" % args
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
576
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
577
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
578 @frontend.route('/+history/<itemname: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
579 def history(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
580 history = flaskg.storage.history(item_name=item_name)
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
581 selected_history = []
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
582
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
583 offset = request.values.get('offset', 0)
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
584 offset = max(int(offset), 0)
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
585
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
586 results_per_page = int(app.cfg.results_per_page)
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
587 if flaskg.user.valid:
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
588 results_per_page = flaskg.user.results_per_page
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
589
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
590 revcount = 0
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
591 maxcount = offset + results_per_page
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
592 nextPage = False
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
593 for rev in history:
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
594 if revcount < offset:
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
595 revcount += 1
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
596 elif results_per_page and revcount == maxcount:
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
597 nextPage = True
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
598 break
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
599 else:
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
600 selected_history.append(rev)
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
601 revcount += 1
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
602
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
603 if not nextPage:
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
604 revcount = 0
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
605
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
606 if results_per_page and offset:
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
607 previous_offset = max(offset - results_per_page, 0)
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
608 else:
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
609 previous_offset = -1
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
610
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
611 return render_template('history.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
612 item_name=item_name, # XXX no item here
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
613 history=selected_history,
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
614 offset=revcount,
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
615 previous_offset=previous_offset,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
616 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
617
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
618 @frontend.route('/+history')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
619 def global_history():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
620 history = flaskg.storage.history(item_name='')
471
17ee0418e93c function to get the count for results per page has been modified, and minor modification(based upon previous) in global_history function
Akash Sinha <akash2607@gmail.com>
parents: 469
diff changeset
621 results_per_page = int(app.cfg.results_per_page)
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
622 if flaskg.user.valid:
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
623 bookmark_time = flaskg.user.getBookmark()
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
624 results_per_page = flaskg.user.results_per_page # if it is 0, means no paging
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
625 else:
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
626 bookmark_time = None
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
627 item_groups = OrderedDict()
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
628 for rev in history:
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
629 current_item_name = rev.item.name
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
630 if bookmark_time and rev.timestamp <= bookmark_time:
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
631 break
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
632 elif current_item_name in item_groups:
467
71988ea0f53e minor edition in grouping of results, now changes done on the same day for a item is only shown in that item group
Akash Sinha <akash2607@gmail.com>
parents: 466
diff changeset
633 latest_rev = item_groups[current_item_name][0]
71988ea0f53e minor edition in grouping of results, now changes done on the same day for a item is only shown in that item group
Akash Sinha <akash2607@gmail.com>
parents: 466
diff changeset
634 tm_latest = datetime.utcfromtimestamp(latest_rev.timestamp)
71988ea0f53e minor edition in grouping of results, now changes done on the same day for a item is only shown in that item group
Akash Sinha <akash2607@gmail.com>
parents: 466
diff changeset
635 tm_current = datetime.utcfromtimestamp(rev.timestamp)
71988ea0f53e minor edition in grouping of results, now changes done on the same day for a item is only shown in that item group
Akash Sinha <akash2607@gmail.com>
parents: 466
diff changeset
636 if format_date(tm_latest) == format_date(tm_current): # this change took place on the same day
71988ea0f53e minor edition in grouping of results, now changes done on the same day for a item is only shown in that item group
Akash Sinha <akash2607@gmail.com>
parents: 466
diff changeset
637 item_groups[current_item_name].append(rev)
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
638 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
639 item_groups[current_item_name] = [rev]
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
640
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
641 # Got the item dict, now doing grouping inside them
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
642 editor_info = namedtuple('editor_info', ['editor', 'editor_revnos'])
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
643 for item_name, revs in item_groups.items():
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
644 item_info = {}
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
645 editors_info = OrderedDict()
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
646 editors = []
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
647 revnos = []
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
648 comments = []
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
649 current_rev = revs[0]
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
650 item_info["item_name"] = item_name
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
651 item_info["timestamp"] = current_rev.timestamp
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
652 item_info["contenttype"] = current_rev.get(CONTENTTYPE)
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
653 item_info["action"] = current_rev.get(ACTION)
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
654 item_info["name"] = current_rev.get(NAME)
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
655
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
656 # Aggregating comments, authors and revno
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
657 for rev in revs:
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
658 revnos.append(rev.revno)
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
659 comment = rev.get(COMMENT)
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
660 if comment:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
661 comment = "#%(revno)d %(comment)s" % {
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
662 'revno': rev.revno,
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
663 'comment': comment
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
664 }
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
665 comments.append(comment)
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
666 editor = get_editor_info(rev)
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
667 editor_name = editor["name"]
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
668 if editor_name in editors_info:
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
669 editors_info[editor_name].editor_revnos.append(rev.revno)
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
670 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
671 editors_info[editor_name] = editor_info(editor, [rev.revno])
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
672
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
673 if len(revnos) == 1:
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
674 # there is only one change for this item in the history considered
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
675 info, positions = editors_info[editor_name]
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
676 info_tuple = (info, "")
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
677 editors.append(info_tuple)
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
678 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
679 # grouping the revision numbers into a range, which belong to a particular editor(user) for the current item
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
680 for info, positions in editors_info.values():
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
681 positions.reverse()
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
682 position_range = str(positions[0])
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
683 pos_index = 1
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
684 for position in positions[1:]:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
685 if position == positions[pos_index-1] + 1:
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
686 if pos_index < len(positions) - 1 and position == positions[pos_index+1] - 1:
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
687 pos_index += 1
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
688 continue
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
689 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
690 position_range = "%(position_range)s-%(position)d" % {
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
691 'position_range': position_range,
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
692 'position': position
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
693 }
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
694 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
695 position_range = "%(position_range)s,%(position)d" % {
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
696 'position_range': position_range,
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
697 'position': position
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
698 }
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
699 pos_index += 1
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
700
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
701 position_range = "[%(position_range)s]" % {'position_range': position_range}
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
702 info_tuple = (info, position_range)
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
703 editors.append(info_tuple)
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
704
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
705 item_info["revnos"] = revnos
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
706 item_info["editors"] = editors
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
707 item_info["comments"] = comments
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
708 item_groups[item_name] = item_info
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
709
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
710 # Grouping on the date basis
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
711 offset = request.values.get('offset', 0)
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
712 offset = max(int(offset), 0)
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
713 day_count = OrderedDict()
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
714 revcount = 0
471
17ee0418e93c function to get the count for results per page has been modified, and minor modification(based upon previous) in global_history function
Akash Sinha <akash2607@gmail.com>
parents: 469
diff changeset
715 maxrev = results_per_page + offset
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
716 toappend = True
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
717 grouped_history = []
454
b07dfe4ceb8d Grouping of global history done on the date basis.
Akash Sinha <akash2607@gmail.com>
parents: 233
diff changeset
718 prev_date = '0000-00-00'
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
719 rev_tuple = namedtuple('rev_tuple', ['rev_date', 'item_revs'])
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
720 rev_tuples = rev_tuple(prev_date, [])
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
721 for item_group in item_groups.values():
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
722 tm = datetime.utcfromtimestamp(item_group["timestamp"])
454
b07dfe4ceb8d Grouping of global history done on the date basis.
Akash Sinha <akash2607@gmail.com>
parents: 233
diff changeset
723 rev_date = format_date(tm)
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
724 if revcount < offset:
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
725 revcount += len(item_group["revnos"])
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
726 if rev_date not in day_count:
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
727 day_count[rev_date] = 0
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
728 day_count[rev_date] += len(item_group["revnos"])
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
729 elif rev_date == prev_date:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
730 rev_tuples.item_revs.append(item_group)
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
731 revcount += len(item_group["revnos"])
454
b07dfe4ceb8d Grouping of global history done on the date basis.
Akash Sinha <akash2607@gmail.com>
parents: 233
diff changeset
732 else:
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
733 grouped_history.append(rev_tuples)
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
734 if results_per_page and revcount >= maxrev:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
735 toappend = False
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
736 break
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
737 else:
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
738 rev_tuples = rev_tuple(rev_date, [item_group])
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
739 prev_date = rev_date
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
740 revcount += len(item_group["revnos"])
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
741
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
742 if toappend:
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
743 grouped_history.append(rev_tuples)
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
744 revcount = 0 # this is the last page, no next page present
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
745 del grouped_history[0] # First tuple will be a null one
460
72dbe801338e Grouping of global history results on item name basis and after that on the date basis done. Also added features like diff links and editor grouping.
Akash Sinha <akash2607@gmail.com>
parents: 456
diff changeset
746
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
747 # calculate offset for previous page link
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
748 if results_per_page:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
749 previous_offset = 0
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
750 prev_rev_count = day_count.values()
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
751 prev_rev_count.reverse()
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
752 for numrev in prev_rev_count:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
753 if previous_offset < results_per_page:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
754 previous_offset += numrev
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
755 else:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
756 break
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
757
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
758 if offset - previous_offset >= results_per_page:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
759 previous_offset = offset - previous_offset
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
760 elif previous_offset:
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
761 previous_offset = 0
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
762 else:
474
b32034020a58 change in action in case of user's default value for results_per_page, now on '0' NO PAGINATION.
Akash Sinha <akash2607@gmail.com>
parents: 472
diff changeset
763 previous_offset = -1
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
764 else:
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
765 previous_offset = -1 # no previous page
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
766
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
767 item_name = request.values.get('item_name', '') # actions menu puts it into qs
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
768 current_timestamp = int(time.time())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
769 return render_template('global_history.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
770 item_name=item_name, # XXX no item
464
58a29a7fd016 grouping of the global history results on item name and date basis (code cleaned)
Akash Sinha <akash2607@gmail.com>
parents: 460
diff changeset
771 history=grouped_history,
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
772 current_timestamp=current_timestamp,
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
773 bookmark_time=bookmark_time,
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
774 offset=revcount,
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
775 previous_offset=previous_offset,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
776 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
777
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
778 @frontend.route('/+wanteds')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
779 def wanted_items():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
780 """ Returns a page with the list of non-existing items, which are wanted items and the
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
781 items they are linked or transcluded to helps show what items still need
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
782 to be written and shows whether there are any broken links. """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
783 wanteds = _wanteds(flaskg.storage.iteritems())
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
784 item_name = request.values.get('item_name', '') # actions menu puts it into qs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
785 return render_template('wanteds.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
786 headline=_(u'Wanted Items'),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
787 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
788 wanteds=wanteds)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
789
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
790
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
791 def _wanteds(items):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
792 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
793 Returns a dict with all the names of non-existing items which are refed by
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
794 other items and the items which are refed by
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
795
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
796 :param items: all the items
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
797 :type items: iteratable sequence
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
798 :returns: a dict with all the wanted items and the items which are beign refed by
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
799 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
800 all_items = set()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
801 wanteds = {}
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
802 for item in items:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
803 current_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
804 all_items.add(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
805 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
806 current_rev = item.get_revision(-1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
807 except NoSuchRevisionError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
808 continue
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
809 # converting to sets so we can get the union
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
810 outgoing_links = current_rev.get(ITEMLINKS, [])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
811 outgoing_transclusions = current_rev.get(ITEMTRANSCLUSIONS, [])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
812 outgoing_refs = set(outgoing_transclusions + outgoing_links)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
813 for refed_item in outgoing_refs:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
814 if refed_item not in all_items:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
815 if refed_item not in wanteds:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
816 wanteds[refed_item] = []
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
817 wanteds[refed_item].append(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
818 if current_item in wanteds:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
819 # if a previously wanted item has been found in the items storage, remove it
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
820 del wanteds[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
821
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
822 return wanteds
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
823
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
824
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
825 @frontend.route('/+orphans')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
826 def orphaned_items():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
827 """ Return a page with the list of items not being linked or transcluded
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
828 by any other items, that makes
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
829 them sometimes not discoverable. """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
830 orphan = _orphans(flaskg.storage.iteritems())
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
831 item_name = request.values.get('item_name', '') # actions menu puts it into qs
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
832 return render_template('item_link_list.html',
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
833 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
834 headline=_(u'Orphaned Items'),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
835 item_names=orphan)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
836
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
837
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
838 def _orphans(items):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
839 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
840 Returns a list with the names of all existing items not being refed by any other item
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
841
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
842 :param items: the list of all items
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
843 :type items: iteratable sequence
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
844 :returns: the list of all orphaned items
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
845 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
846 linked_items = set()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
847 transcluded_items = set()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
848 all_items = set()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
849 norev_items = set()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
850 for item in items:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
851 all_items.add(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
852 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
853 current_rev = item.get_revision(-1)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
854 except NoSuchRevisionError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
855 norev_items.add(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
856 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
857 linked_items.update(current_rev.get(ITEMLINKS, []))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
858 transcluded_items.update(current_rev.get(ITEMTRANSCLUSIONS, []))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
859 orphans = all_items - linked_items - transcluded_items - norev_items
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
860 logging.info("_orphans: Ignored %d item(s) that have no revisions" % len(norev_items))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
861 return list(orphans)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
862
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
863
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
864 @frontend.route('/+quicklink/<itemname: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
865 def quicklink_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
866 """ Add/Remove the current wiki page to/from the user quicklinks """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
867 u = 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
868 msg = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
869 if not u.valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
870 msg = _("You must login to use this action: %(action)s.", action="quicklink/quickunlink"), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
871 elif not flaskg.user.isQuickLinkedTo([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
872 if not u.addQuicklink(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
873 msg = _('A quicklink to this page could not be added for you.'), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
874 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
875 if not u.removeQuicklink(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
876 msg = _('Your quicklink to this page could not be removed.'), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
877 if msg:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
878 flash(*msg)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
879 return redirect(url_for('.show_item', item_name=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
880
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
881
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
882 @frontend.route('/+subscribe/<itemname: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
883 def subscribe_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
884 """ Add/Remove the current wiki item to/from the user's subscriptions """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
885 u = 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
886 cfg = app.cfg
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
887 msg = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
888 if not u.valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
889 msg = _("You must login to use this action: %(action)s.", action="subscribe/unsubscribe"), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
890 elif not u.may.read(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
891 msg = _("You are not allowed to subscribe to an item you may not read."), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
892 elif u.isSubscribedTo([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
893 # Try to unsubscribe
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
894 if not u.unsubscribe(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
895 msg = _("Can't remove regular expression subscription!") + u' ' + \
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
896 _("Edit the subscription regular expressions in your settings."), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
897 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
898 # Try to subscribe
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
899 if not u.subscribe(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
900 msg = _('You could not get subscribed to this item.'), "error"
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
901 if msg:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
902 flash(*msg)
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
903 return redirect(url_for('.show_item', item_name=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
904
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
905
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
906 class ValidRegistration(Validator):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
907 """Validator for a valid registration form
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
908 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
909 passwords_mismatch_msg = L_('The passwords do not match.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
910
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
911 def validate(self, element, state):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
912 if not (element['username'].valid and
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
913 element['password1'].valid and element['password2'].valid and
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
914 element['email'].valid and element['textcha'].valid):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
915 return False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
916 if element['password1'].value != element['password2'].value:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
917 return self.note_error(element, state, 'passwords_mismatch_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
918
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
919 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
920
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
921 class RegistrationForm(TextChaizedForm):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
922 """a simple user registration form"""
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
923 name = 'register'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
924
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
925 username = String.using(label=L_('Name')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
926 password1 = String.using(label=L_('Password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
927 password2 = String.using(label=L_('Password')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
928 email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
929 openid = String.using(label=L_('OpenID'), optional=True).with_properties(placeholder=L_("Your OpenID address")).validated_by(URLValidator())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
930 submit = String.using(default=L_('Register'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
931
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
932 validators = [ValidRegistration()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
933
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
934
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
935 class OpenIDForm(TextChaizedForm):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
936 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
937 OpenID registration form, inherited from the simple registration form.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
938 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
939 name = 'openid'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
940
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
941 username = String.using(label=L_('Name')).with_properties(placeholder=L_("The login name you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
942 password1 = String.using(label=L_('Password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
943 password2 = String.using(label=L_('Password')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
944
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
945 email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
946 openid = String.using(label=L_('OpenID')).with_properties(placeholder=L_("Your OpenID address")).validated_by(URLValidator())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
947 submit = String.using(optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
948
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
949 validators = [ValidRegistration()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
950
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
951 def _using_moin_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
952 """Check if MoinAuth is being used for authentication.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
953
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
954 Only then users can register with moin or change their password via moin.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
955 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
956 from MoinMoin.auth import MoinAuth
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
957 for auth in app.cfg.auth:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
958 if isinstance(auth, MoinAuth):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
959 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
960 return False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
961
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
962
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
963 def _using_openid_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
964 """Check if OpenIDAuth is being used for authentication.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
965
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
966 Only then users can register with openid or change their password via openid.
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
967 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
968 from MoinMoin.auth.openidrp import OpenIDAuth
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
969 for auth in app.cfg.auth:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
970 if isinstance(auth, OpenIDAuth):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
971 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
972 return False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
973
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
974
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
975 @frontend.route('/+register', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
976 def register():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
977 item_name = 'Register' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
978 # is openid_submit in the form?
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
979 isOpenID = 'openid_submit' in request.values
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
980
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
981 if isOpenID:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
982 # this is an openid continuation
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
983 if not _using_openid_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
984 return Response('No OpenIDAuth in auth list', 403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
985
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
986 template = 'openid_register.html'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
987 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
988 form = OpenIDForm.from_defaults()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
989 # we got an openid from the multistage redirect
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
990 oid = request.values.get('openid_openid')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
991 if oid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
992 form['openid'] = oid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
993 TextCha(form).amend_form()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
994
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
995 elif request.method == 'POST':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
996 form = OpenIDForm.from_flat(request.form)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
997 TextCha(form).amend_form()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
998
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
999 if form.validate():
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1000 msg = user.create_user(username=form['username'].value,
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1001 password=form['password1'].value,
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1002 email=form['email'].value,
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1003 openid=form['openid'].value,
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1004 )
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1005 if msg:
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1006 flash(msg, "error")
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1007 else:
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1008 flash(_('Account created, please log in now.'), "info")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1009 return redirect(url_for('.show_root'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1010
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1011 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1012 # not openid registration and no MoinAuth
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1013 if not _using_moin_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1014 return Response('No MoinAuth in auth list', 403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1015
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1016 template = 'register.html'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1017 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1018 form = RegistrationForm.from_defaults()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1019 TextCha(form).amend_form()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1020
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1021 elif request.method == 'POST':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1022 form = RegistrationForm.from_flat(request.form)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1023 TextCha(form).amend_form()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1024
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1025 if form.validate():
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1026 msg = user.create_user(username=form['username'].value,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1027 password=form['password1'].value,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1028 email=form['email'].value,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1029 openid=form['openid'].value,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1030 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1031 if msg:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1032 flash(msg, "error")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1033 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1034 flash(_('Account created, please log in now.'), "info")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1035 return redirect(url_for('.show_root'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1036
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1037 return render_template(template,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1038 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
1039 gen=make_generator(),
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1040 form=form,
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1041 )
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1042
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1043
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1044 class ValidLostPassword(Validator):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1045 """Validator for a valid lost password form
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1046 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1047 name_or_email_needed_msg = L_('Your user name or your email address is needed.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1048
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1049 def validate(self, element, state):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1050 if not(element['username'].valid and element['username'].value
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1051 or
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1052 element['email'].valid and element['email'].value):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1053 return self.note_error(element, state, 'name_or_email_needed_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1054
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1055 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1056
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1057
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1058 class PasswordLostForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1059 """a simple password lost form"""
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1060 name = 'lostpass'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1061
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1062 username = String.using(label=L_('Name'), optional=True).with_properties(placeholder=L_("Your login name"))
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1063 email = String.using(label=L_('E-Mail'), optional=True).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1064 submit = String.using(default=L_('Recover password'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1065
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1066 validators = [ValidLostPassword()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1067
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1068
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1069 @frontend.route('/+lostpass', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1070 def lostpass():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1071 # TODO use ?next=next_location check if target is in the wiki and not outside domain
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1072 item_name = 'LostPass' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1073
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1074 if not _using_moin_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1075 return Response('No MoinAuth in auth list', 403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1076
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1077 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1078 form = PasswordLostForm.from_defaults()
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1079 elif request.method == 'POST':
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1080 form = PasswordLostForm.from_flat(request.form)
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1081 if form.validate():
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1082 u = None
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1083 username = form['username'].value
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1084 if username:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1085 u = user.User(user.getUserId(username))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1086 email = form['email'].value
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1087 if form['email'].valid and email:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1088 u = user.get_by_email_address(email)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1089 if u and u.valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1090 is_ok, msg = u.mailAccountData()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1091 if not is_ok:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1092 flash(msg, "error")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1093 flash(_("If this account exists, you will be notified."), "info")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1094 return redirect(url_for('.show_root'))
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1095 return render_template('lostpass.html',
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1096 item_name=item_name,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1097 gen=make_generator(),
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1098 form=form,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1099 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1100
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1101 class ValidPasswordRecovery(Validator):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1102 """Validator for a valid password recovery form
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1103 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1104 passwords_mismatch_msg = L_('The passwords do not match.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1105 password_encoding_problem_msg = L_('New password is unacceptable, encoding trouble.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1106
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1107 def validate(self, element, state):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1108 if element['password1'].value != element['password2'].value:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1109 return self.note_error(element, state, 'passwords_mismatch_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1110
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1111 try:
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 159
diff changeset
1112 crypto.crypt_password(element['password1'].value)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1113 except UnicodeError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1114 return self.note_error(element, state, 'password_encoding_problem_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1115
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1116 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1117
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1118 class PasswordRecoveryForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1119 """a simple password recovery form"""
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1120 name = 'recoverpass'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1121
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1122 username = String.using(label=L_('Name')).with_properties(placeholder=L_("Your login name")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1123 token = String.using(label=L_('Recovery token')).with_properties(placeholder=L_("The recovery token that has been sent to you")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1124 password1 = String.using(label=L_('New password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1125 password2 = String.using(label=L_('New password (repeat)')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1126 submit = String.using(default=L_('Change password'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1127
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1128 validators = [ValidPasswordRecovery()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1129
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1130
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1131 @frontend.route('/+recoverpass', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1132 def recoverpass():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1133 # TODO use ?next=next_location check if target is in the wiki and not outside domain
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1134 item_name = 'RecoverPass' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1135
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1136 if not _using_moin_auth():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1137 return Response('No MoinAuth in auth list', 403)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1138
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1139 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1140 form = PasswordRecoveryForm.from_defaults()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1141 form.update(request.values)
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1142 elif request.method == 'POST':
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1143 form = PasswordRecoveryForm.from_flat(request.form)
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1144 if form.validate():
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1145 u = user.User(user.getUserId(form['username'].value))
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1146 if u and u.valid and u.apply_recovery_token(form['token'].value, form['password1'].value):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1147 flash(_("Your password has been changed, you can log in now."), "info")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1148 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1149 flash(_('Your token is invalid!'), "error")
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1150 return redirect(url_for('.show_root'))
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1151 return render_template('recoverpass.html',
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1152 item_name=item_name,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1153 gen=make_generator(),
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1154 form=form,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1155 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1156
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1157
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1158 class ValidLogin(Validator):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1159 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1160 Login validator
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1161 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1162 moin_fail_msg = L_('Either your username or password was invalid.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1163 openid_fail_msg = L_('Failed to authenticate with this OpenID.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1164
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1165 def validate(self, element, state):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1166 # get the result from the other validators
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1167 moin_valid = element['username'].valid and element['password'].valid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1168 openid_valid = element['openid'].valid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1169
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1170 # none of them was valid
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1171 if not (openid_valid or moin_valid):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1172 return False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1173 # got our user!
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1174 if flaskg.user.valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1175 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1176 # no valid user -> show appropriate message
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1177 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1178 if not openid_valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1179 return self.note_error(element, state, 'openid_fail_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1180 elif not moin_valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1181 return self.note_error(element, state, 'moin_fail_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1182
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1183
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1184 class LoginForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1185 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1186 Login form
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1187 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1188 name = 'login'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1189
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1190 username = String.using(label=L_('Name'), optional=False).with_properties(autofocus=True).validated_by(Present())
219
96b17384932a frontend.views: bug fix for login form, all input is required
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 216
diff changeset
1191 password = String.using(label=L_('Password'), optional=False).validated_by(Present())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1192 openid = String.using(label=L_('OpenID'), optional=True).validated_by(Present(), URLValidator())
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1193
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1194 # the submit hidden field
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1195 submit = String.using(optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1196
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1197 validators = [ValidLogin()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1198
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1199
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1200 @frontend.route('/+login', methods=['GET', 'POST'])
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1201 def login():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1202 # TODO use ?next=next_location check if target is in the wiki and not outside domain
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1203 item_name = 'Login' # XXX
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1204
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1205 # multistage return
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1206 if flaskg._login_multistage_name == 'openid':
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1207 return Response(flaskg._login_multistage, mimetype='text/html')
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1208
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1209 if request.method == 'GET':
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1210 form = LoginForm.from_defaults()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1211 for authmethod in app.cfg.auth:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1212 hint = authmethod.login_hint()
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1213 if hint:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1214 flash(hint, "info")
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1215 elif request.method == 'POST':
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1216 form = LoginForm.from_flat(request.form)
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
1217 if form.validate():
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1218 # we have a logged-in, valid user
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1219 return redirect(url_for('.show_root'))
231
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1220 # flash the error messages (if any)
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1221 for msg in flaskg._login_messages:
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1222 flash(msg, "error")
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1223 return render_template('login.html',
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1224 item_name=item_name,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1225 login_inputs=app.cfg.auth_login_inputs,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1226 gen=make_generator(),
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1227 form=form,
6f2dc5677639 frontend views: refactor form related code, reduce duplication
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 230
diff changeset
1228 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1229
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1230
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1231 @frontend.route('/+logout')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1232 def logout():
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1233 flash(_("You are now logged out."), "info")
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1234 for key in ['user.id', 'user.auth_method', 'user.auth_attribs', ]:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1235 if key in session:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1236 del session[key]
266
7a6b116afa20 upgrade to flask 0.7.1 (not compatible to older flasks)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 255
diff changeset
1237 return redirect(url_for('.show_root'))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1238
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1239
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1240 class ValidChangePass(Validator):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1241 """Validator for a valid password change
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1242 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1243 passwords_mismatch_msg = L_('The passwords do not match.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1244 current_password_wrong_msg = L_('The current password was wrong.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1245 password_encoding_problem_msg = L_('New password is unacceptable, encoding trouble.')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1246
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1247 def validate(self, element, state):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1248 if not (element['password_current'].valid and element['password1'].valid and element['password2'].valid):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1249 return False
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1250
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1251 if not user.User(name=flaskg.user.name, password=element['password_current'].value).valid:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1252 return self.note_error(element, state, 'current_password_wrong_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1253
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1254 if element['password1'].value != element['password2'].value:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1255 return self.note_error(element, state, 'passwords_mismatch_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1256
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1257 try:
174
e8f61cbd661b modularize crypto/random stuff, move it to MoinMoin.util.crypto, pw change bugfix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 159
diff changeset
1258 crypto.crypt_password(element['password1'].value)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1259 except UnicodeError:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1260 return self.note_error(element, state, 'password_encoding_problem_msg')
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1261 return True
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1262
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1263
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1264 class UserSettingsPasswordForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1265 name = 'usersettings_password'
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1266 password_current = String.using(label=L_('Current Password')).with_properties(placeholder=L_("Your current login password")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1267 password1 = String.using(label=L_('New password')).with_properties(placeholder=L_("The login password you want to use")).validated_by(Present())
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1268 password2 = String.using(label=L_('New password (repeat)')).with_properties(placeholder=L_("Repeat the same password")).validated_by(Present())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1269 submit = String.using(default=L_('Change password'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1270 validators = [ValidChangePass()]
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1271
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1272
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1273 class UserSettingsNotificationForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1274 name = 'usersettings_notification'
226
029cb888d253 use flatland filters for autofocus/placeholder html5 attrs, use html5 input field types email/url/search
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 219
diff changeset
1275 email = String.using(label=L_('E-Mail')).with_properties(placeholder=L_("Your E-Mail address")).validated_by(IsEmail())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1276 submit = String.using(default=L_('Save'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1277
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1278
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1279 class UserSettingsNavigationForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1280 name = 'usersettings_navigation'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1281 # TODO: find a good way to handle quicklinks here
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1282 submit = String.using(default=L_('Save'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1283
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1284
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1285 class UserSettingsOptionsForm(Form):
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1286 # TODO: if the checkbox in the form is checked, we get key: u'1' in the
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1287 # form data and all is fine. if it is not checked, the key is not present
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1288 # in the form data and flatland assigns None to the attribute (not False).
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1289 # If moin detects the None, it thinks this has not been set and uses its
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1290 # builtin defaults (for some True, for some others False). Makes
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1291 # edit_on_doubleclick malfunctioning (because its default 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
1292 name = 'usersettings_options'
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1293 mailto_author = Boolean.using(label=L_('Publish my email (not my wiki homepage) in author info'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1294 edit_on_doubleclick = Boolean.using(label=L_('Open editor on double click'), optional=True)
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Th