annotate MoinMoin/apps/frontend/views.py @ 2934:e2b5a79a1e06

Fixed issue #499 - Search for tickets assigned to a user
author Aabhas Majumdar <majumdaraabhas@gmail.com>
date Sun, 08 Mar 2015 20:57:53 +0530
parents 08007ac96dda
children 456c68761e96
rev   line source
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
1 # Copyright: 2012 MoinMoin:CheerXiao
1913
dbcadc76561a passlib support - strong crypto hashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1899
diff changeset
2 # Copyright: 2003-2013 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
3 # Copyright: 2011 MoinMoin:AkashSinha
755
d5daf53230ad frontend.views: show_content reintroduced. Same as show_item, but we only show the content.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 535
diff changeset
4 # Copyright: 2011 MoinMoin:ReimarBauer
26
4cd8edde9e94 automatically transform module docstrings, moving legal stuff to comments
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 24
diff changeset
5 # 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
6 # 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
7 # 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
8 # 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
9 # 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
10
0
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 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
13
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 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
15 """
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
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 re
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 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
20 import time
1427
466a277c72a3 implement i18n for .js by using jinja2 js templates
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1422
diff changeset
21 import mimetypes
1623
1e67974bee6e remove simplejson fallback, json is included since python 2.6 (which we require)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1457
diff changeset
22 import json
454
b07dfe4ceb8d Grouping of global history done on the date basis.
Akash Sinha <akash2607@gmail.com>
parents: 233
diff changeset
23 from datetime import datetime
933
fb45cc507f6a make sqlalchemy optional, remove unused OrderedDict monkeypatch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 926
diff changeset
24 from collections import namedtuple
1457
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
25 from functools import wraps, partial
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
26
1974
87272c032485 remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1973
diff changeset
27 from flask import request, url_for, flash, Response, make_response, redirect, 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
28 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
29 from flask import g as flaskg
1767
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1749
diff changeset
30 from flask.ext.babel import format_date
54be46b8a0b4 flask ext import change
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1749
diff changeset
31 from flask.ext.themes import get_themes_list
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
2019
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
33 from flatland import Form, List
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
34 from flatland.validation import Validator
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 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
37
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 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
39 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
40
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
41 from whoosh import sorting
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
42 from whoosh.query import Term, Prefix, And, Or, DateRange, Every
2532
74d2eafffa29 Adds ngram'ed search, highlights, shows to user about skipped terms in search query
sharky93 <rishabhr123@gmail.com>
parents: 2531
diff changeset
43 from whoosh.analysis import StandardAnalyzer
2635
d98612551045 Added option of sort by recently and least recently updated tickets in +tickets view
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2634
diff changeset
44 from whoosh import sorting
777
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
45
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 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
47 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
48
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.i18n import _, L_, N_
1974
87272c032485 remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1973
diff changeset
50 from MoinMoin.themes import render_template, contenttype_to_class
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 from MoinMoin.apps.frontend import frontend
2177
98af52a80d21 user subscriptions settings
Ana Balica <ana.balica@gmail.com>
parents: 2176
diff changeset
52 from MoinMoin.forms import (OptionalText, RequiredText, URL, YourOpenID, YourEmail,
98af52a80d21 user subscriptions settings
Ana Balica <ana.balica@gmail.com>
parents: 2176
diff changeset
53 RequiredPassword, Checkbox, InlineCheckbox, Select, Names,
2298
df86cc3aee33 merged with main repo, 1 test f failing still
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2296 2195
diff changeset
54 Tags, Natural, Hidden, MultiSelect, Enum, Subscriptions,
df86cc3aee33 merged with main repo, 1 test f failing still
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2296 2195
diff changeset
55 validate_name, NameNotValidError)
2713
c9baa61473a9 Now only tags specific to ticket items are shown in +tickets view and in ticket submit/modify view, added a function that returns itemtype specific tags
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2691
diff changeset
56 from MoinMoin.items import BaseChangeForm, Item, NonExistent, NameNotUniqueError, FieldNotUniqueError, get_itemtype_specific_tags
1801
f6afb9aeb861 Replace CONTENTTYPE_GROUPS with information collected in content_registry.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1800
diff changeset
57 from MoinMoin.items.content import content_registry
1973
286e315935ae refactor usage of constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1966
diff changeset
58 from MoinMoin import user, util
1274
8c275efc6e8c refactored and cleaned up user module code and tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1262
diff changeset
59 from MoinMoin.constants.keys import *
2257
a39955ac972f cleanup ..
Ashutosh Singla <ashu1461@gmail.com>
parents: 2256
diff changeset
60 from MoinMoin.constants.namespaces import *
2722
027184f05e7f Now user can check the issues assigned to a particular user
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2713
diff changeset
61 from MoinMoin.constants.itemtypes import ITEMTYPE_DEFAULT, ITEMTYPE_TICKET, ITEMTYPE_USERPROFILE
1973
286e315935ae refactor usage of constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1966
diff changeset
62 from MoinMoin.constants.chartypes import CHARS_UPPER, CHARS_LOWER
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
63 from MoinMoin.constants.contenttypes import *
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
64 from MoinMoin.util import crypto
2267
9c177f0ba6c3 Added fqname support to rename view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2266
diff changeset
65 from MoinMoin.util.interwiki import url_for_item, split_fqname, CompositeName
1974
87272c032485 remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1973
diff changeset
66 from MoinMoin.search import SearchForm
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
67 from MoinMoin.search.analyzers import item_name_analyzer
1974
87272c032485 remove unused imports
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1973
diff changeset
68 from MoinMoin.security.textcha import TextCha, TextChaizedForm
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 from MoinMoin.signalling import item_displayed, item_modified
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
70 from MoinMoin.storage.middleware.protecting import AccessDenied
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 @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
74 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
75 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
76 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
77 # 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
78 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
79 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
80 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
81
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 @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
84 def show_root():
2236
5f2fb2d7ed87 Replaced a single item_root to namespace-root mapping to add support for namespace specific redirecting.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2228
diff changeset
85 item_name = app.cfg.root_mapping.get(NAMESPACE_DEFAULT, app.cfg.default_root)
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 294
diff changeset
86 return redirect(url_for_item(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
87
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
88
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 @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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 Disallow: /+modify/
755
d5daf53230ad frontend.views: show_content reintroduced. Same as show_item, but we only show the content.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 535
diff changeset
98 Disallow: /+content/
0
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: /+delete/
535
da01d505e210 some more urls are disallowed now
Akash Sinha <akash2607@gmail.com>
parents: 534
diff changeset
100 Disallow: /+ajaxdelete/
da01d505e210 some more urls are disallowed now
Akash Sinha <akash2607@gmail.com>
parents: 534
diff changeset
101 Disallow: /+ajaxdestroy/
da01d505e210 some more urls are disallowed now
Akash Sinha <akash2607@gmail.com>
parents: 534
diff changeset
102 Disallow: /+ajaxmodify/
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 Disallow: /+subscribe/
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
112 Disallow: /+forwardrefs/
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 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
114 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
115 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 Disallow: /+diffraw/
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
124 Disallow: /+search
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 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
126 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
127 Allow: /
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 """, 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
129
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131 @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
132 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
133 # 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
134 # 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
135 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
136
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
138 @frontend.route('/all')
2288
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
139 def global_views():
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
140 """
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
141 Provides a link to all the global views.
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
142 """
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
143 return render_template('all.html',
2734
bac6217594a0 Removed full stops from user titles
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2722
diff changeset
144 title_name=_(u"Global Views"),
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
145 fqname=CompositeName(u'all', NAME_EXACT, u'')
2288
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
146 )
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
147
50ff4ba17f3e Added /+all view, Solving #22.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2285
diff changeset
148
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
149 class LookupForm(Form):
1749
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
150 name = OptionalText.using(label='name')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
151 name_exact = OptionalText.using(label='name_exact')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
152 itemid = OptionalText.using(label='itemid')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
153 revid = OptionalText.using(label='revid')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
154 userid = OptionalText.using(label='userid')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
155 language = OptionalText.using(label='language')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
156 itemlinks = OptionalText.using(label='itemlinks')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
157 itemtransclusions = OptionalText.using(label='itemtransclusions')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
158 refs = OptionalText.using(label='refs')
90c2680398bb +lookup view: do not translate field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1743
diff changeset
159 tags = Tags.using(optional=True).using(label='tags')
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
160 history = InlineCheckbox.using(label=L_('search also in non-current revisions'))
1988
490c13d072f2 remove Submit widget
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1986
diff changeset
161 submit_label = L_('Lookup')
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
162
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
163
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
164 def analyze(analyzer, text):
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
165 return [token.text for token in analyzer(text, mode='index')]
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
166
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
167
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
168 @frontend.route('/+lookup', methods=['GET', 'POST'])
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
169 def lookup():
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
170 """
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
171 lookup is like search, but it only deals with specific fields that identify
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
172 an item / revision. no query string parsing.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
173
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
174 for uuid fields, it performs a prefix search, so you can just give the
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
175 first few digits. same is done for name_exact field.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
176 if you give a complete uuid or you do a lookup via the name field, it
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
177 will use a simple search term.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
178 for one result, it directly redirects to the item/revision found.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
179 for none or multipe results, a result page is shown.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
180
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
181 usually this is used for links with a query string, like:
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
182 /+lookup?itemid=123cba (prefix match on itemid 123cba.......)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
183 /+lookup?revid=c0ddcda9a092499c92920cc4a9b11704 (full uuid simple term match)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
184 /+lookup?name_exact=FooBar/ (prefix match on name_exact FooBar/...)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
185
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
186 When giving history=1 it will use the all revisions index for lookup.
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
187 """
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
188 status = 200
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
189 title_name = _("Lookup")
1354
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
190 # TAGS might be there multiple times, thus we need multi:
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
191 lookup_form = LookupForm.from_flat(request.values.items(multi=True))
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
192 valid = lookup_form.validate()
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
193 if valid:
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
194 history = bool(request.values.get('history'))
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
195 idx_name = ALL_REVS if history else LATEST_REVS
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
196 terms = []
1354
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
197 for key in [NAME, NAME_EXACT, ITEMID, REVID, USERID,
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
198 LANGUAGE,
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
199 TAGS,
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
200 ITEMLINKS, ITEMTRANSCLUSIONS, 'refs', ]:
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
201 value = lookup_form[key].value
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
202 if value:
2625
aa093f88e018 remove redundant parentheses
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2617
diff changeset
203 if key in [ITEMID, REVID, USERID, ] and len(value) < crypto.UUID_LEN or key in [NAME_EXACT]:
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
204 term = Prefix(key, value)
1354
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
205 elif key == 'refs':
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
206 term = Or([Term(ITEMLINKS, value), Term(ITEMTRANSCLUSIONS, value)])
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
207 elif key == TAGS:
a9cd6f2bbc94 lookup view: add userid, language, itemlinks, itemtransclusions, refs, tags
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1347
diff changeset
208 term = And([Term(TAGS, v.value) for v in lookup_form[key]])
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
209 else:
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
210 term = Term(key, value)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
211 terms.append(term)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
212 if terms:
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
213 LookupEntry = namedtuple('LookupEntry', 'name revid wikiname')
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
214 name = lookup_form[NAME].value
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
215 name_exact = lookup_form[NAME_EXACT].value or u''
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
216 terms.append(Term(WIKINAME, app.cfg.interwikiname))
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
217 q = And(terms)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
218 with flaskg.storage.indexer.ix[idx_name].searcher() as searcher:
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
219 flaskg.clock.start('lookup')
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
220 results = searcher.search(q, limit=100)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
221 flaskg.clock.stop('lookup')
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
222 lookup_results = []
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
223 for result in results:
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
224 analyzer = item_name_analyzer()
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
225 lookup_results += [LookupEntry(n, result[REVID], result[WIKINAME])
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
226 for n in result[NAME]
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
227 if not name or name.lower() in analyze(analyzer, n)
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
228 if n.startswith(name_exact)]
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
229
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
230 if len(lookup_results) == 1:
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
231 result = lookup_results[0]
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
232 rev = result.revid if history else CURRENT
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
233 url = url_for('.show_item', item_name=result.name, rev=rev)
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
234 return redirect(url)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
235 else:
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
236 flaskg.clock.start('lookup render')
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
237 html = render_template('lookup.html',
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
238 title_name=title_name,
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
239 lookup_form=lookup_form,
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
240 results=lookup_results,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
241 )
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
242 flaskg.clock.stop('lookup render')
2101
d993f93428bc Lookup view modified to support multiple names
Ashutosh Singla <ashu1461@gmail.com>
parents: 2090
diff changeset
243 if not lookup_results:
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
244 status = 404
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
245 return Response(html, status)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
246 html = render_template('lookup.html',
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
247 title_name=title_name,
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
248 lookup_form=lookup_form,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
249 )
1347
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
250 return Response(html, status)
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
251
cd22cf9e8dd7 implement +lookup view for itemid/revid/... based lookup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1346
diff changeset
252
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
253 def _compute_item_transclusions(item_name):
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
254 """Compute which items are transcluded into item <item_name>.
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
255
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
256 :returns: a set of their item names.
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
257 """
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
258 with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher:
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
259 # The search process should be as fast as possible so use
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
260 # the indexer low-level documents instead of high-level Revisions.
1986
10e20c8a2c29 replace literal strings by constants from constants.keys
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1985
diff changeset
261 doc = searcher.document(**{NAME_EXACT: item_name})
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
262 if not doc:
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
263 return set()
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
264 transcluded_names = set(doc[ITEMTRANSCLUSIONS])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
265 for item_name in transcluded_names.copy():
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
266 transclusions = _compute_item_transclusions(item_name)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
267 transcluded_names.update(transclusions)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
268 return transcluded_names
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
269
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
270
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
271 def add_file_filters(_filter, filetypes):
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
272 """
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
273 Add various terms to the filter for the search query for the selected file types
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
274 in the search options.
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
275
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
276 :param _filter: the current filter
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
277 :param filetypes: list of selected filetypes
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
278 :returns: the required _filter for the search query
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
279 """
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
280 if filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
281 alltypes = "all" in filetypes
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
282 contenttypes = []
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
283 files_filter = []
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
284 if alltypes or "markup" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
285 contenttypes.append(CONTENTTYPE_MARKUP)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
286 if alltypes or "text" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
287 contenttypes.append(CONTENTTYPE_TEXT)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
288 if alltypes or "image" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
289 contenttypes.append(CONTENTTYPE_IMAGE)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
290 if alltypes or "audio" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
291 contenttypes.append(CONTENTTYPE_AUDIO)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
292 if alltypes or "video" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
293 contenttypes.append(CONTENTTYPE_VIDEO)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
294 if alltypes or "drawing" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
295 contenttypes.append(CONTENTTYPE_DRAWING)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
296 if alltypes or "other" in filetypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
297 contenttypes.append(CONTENTTYPE_OTHER)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
298 for ctype in contenttypes:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
299 for itemtype in ctype:
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
300 files_filter.append(Term("contenttype", itemtype))
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
301 files_filter = Or(files_filter)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
302 _filter.append(files_filter)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
303 _filter = And(_filter)
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
304 return _filter
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
305
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
306
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
307 def add_facets(facets, time_sorting):
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
308 """
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
309 Adds various facets for the search features.
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
310
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
311 :param facets: current facets
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
312 :param time_sorting: defines the sorting order and can have one of the following 3 values :
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
313 1. default - default search
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
314 2. old - sort old items first
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
315 3. new - sort new items first
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
316 :returns: required facets for the search query
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
317 """
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
318 if time_sorting == "new":
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
319 facets.append(sorting.FieldFacet("mtime", reverse=True))
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
320 elif time_sorting == "old":
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
321 facets.append(sorting.FieldFacet("mtime", reverse=False))
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
322 return facets
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
323
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
324
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
325 @frontend.route('/+search/<itemname:item_name>', methods=['GET', 'POST'])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
326 @frontend.route('/+search', defaults=dict(item_name=u''), methods=['GET', 'POST'])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
327 def search(item_name):
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
328 search_form = SearchForm.from_flat(request.values)
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
329 ajax = True if request.args.get('boolajax') else False
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
330 valid = search_form.validate()
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
331 time_sorting = False
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
332 filetypes = []
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
333 if ajax:
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
334 query = request.args.get('q')
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
335 history = request.args.get('history') == "true"
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
336 time_sorting = request.args.get('time_sorting')
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
337 filetypes = request.args.get('filetypes')
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
338 filetypes = filetypes.split(',')[:-1] # To remove the extra u'' at the end of the list
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
339 else:
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
340 query = search_form['q'].value
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
341 history = bool(request.values.get('history'))
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
342 if valid or ajax:
2589
ee404f81afe9 fix new pep8 errors generated after pep8 is upgraded to 1.5.1
RogerHaase <haaserd@gmail.com>
parents: 2559
diff changeset
343 # most fields in the schema use a StandardAnalyzer, it omits fairly frequently used words
ee404f81afe9 fix new pep8 errors generated after pep8 is upgraded to 1.5.1
RogerHaase <haaserd@gmail.com>
parents: 2559
diff changeset
344 # this finds such words and reports to the user
2532
74d2eafffa29 Adds ngram'ed search, highlights, shows to user about skipped terms in search query
sharky93 <rishabhr123@gmail.com>
parents: 2531
diff changeset
345 analyzer = StandardAnalyzer()
2545
6938dad629da merged sharky's other repo
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2298 2539
diff changeset
346 omitted_words = [token.text for token in analyzer(query, removestops=False) if token.stopped]
2532
74d2eafffa29 Adds ngram'ed search, highlights, shows to user about skipped terms in search query
sharky93 <rishabhr123@gmail.com>
parents: 2531
diff changeset
347
954
f79d471667b9 search/indexing: replace all_revs (boolean) by idx_name (index name str) - easier code, more flexible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 953
diff changeset
348 idx_name = ALL_REVS if history else LATEST_REVS
2532
74d2eafffa29 Adds ngram'ed search, highlights, shows to user about skipped terms in search query
sharky93 <rishabhr123@gmail.com>
parents: 2531
diff changeset
349 qp = flaskg.storage.query_parser([NAME_EXACT, NAME, SUMMARY, CONTENT, CONTENTNGRAM], idx_name=idx_name)
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
350 q = qp.parse(query)
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
351
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
352 _filter = []
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
353 _filter = add_file_filters(_filter, filetypes)
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
354 if item_name: # Only search this item and subitems
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
355 prefix_name = item_name + u'/'
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
356 terms = [Term(NAME_EXACT, item_name), Prefix(NAME_EXACT, prefix_name), ]
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
357
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
358 show_transclusions = True
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
359 if show_transclusions:
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
360 # XXX Search subitems and all transcluded items (even recursively),
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
361 # still looks like a hack. Imaging you have "foo" on main page and
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
362 # "bar" on transcluded one. Then you search for "foo AND bar".
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
363 # Such stuff would only work if we expand transcluded items
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
364 # at indexing time (and we currently don't).
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
365 with flaskg.storage.indexer.ix[LATEST_REVS].searcher() as searcher:
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
366 subq = Or([Term(NAME_EXACT, item_name), Prefix(NAME_EXACT, prefix_name), ])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
367 subq = And([subq, Every(ITEMTRANSCLUSIONS), ])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
368 flaskg.clock.start('search subitems with transclusions')
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
369 results = searcher.search(subq, limit=None)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
370 flaskg.clock.stop('search subitems with transclusions')
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
371 transcluded_names = set()
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
372 for hit in results:
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
373 name = hit[NAME]
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
374 transclusions = _compute_item_transclusions(name)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
375 transcluded_names.update(transclusions)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
376 # XXX Will whoosh cope with such a large filter query?
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
377 terms.extend([Term(NAME_EXACT, name) for name in transcluded_names])
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
378
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
379 _filter = Or(terms)
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
380
971
c396343c640a fix AttributeError exception that happened when searching
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 970
diff changeset
381 with flaskg.storage.indexer.ix[idx_name].searcher() as searcher:
2589
ee404f81afe9 fix new pep8 errors generated after pep8 is upgraded to 1.5.1
RogerHaase <haaserd@gmail.com>
parents: 2559
diff changeset
382 # terms is set to retrieve list of terms which matched, in the searchtemplate, for highlight.
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
383 facets = []
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
384 facets = add_facets(facets, time_sorting)
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
385 flaskg.clock.start('search')
2651
2003e3685733 Improved search GUI - Added information about contenttype and item size in the items metadata. Also added color coding for various stuff like green for metadata, yellow for search term suggestions, blue for item names. Also added search options to help in search - search all revisions or the latest ones, sort search results by time - newer first, older first or default, search items of particular contenttype(s). Also removed the second search bar in the upper right corner in search page.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2627
diff changeset
386 results = searcher.search(q, filter=_filter, limit=100, terms=True, sortedby=facets)
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
387 flaskg.clock.stop('search')
1985
7d8907699829 search: name and content suggestions are fast now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
388 flaskg.clock.start('search suggestions')
7d8907699829 search: name and content suggestions are fast now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
389 name_suggestions = [word for word, score in results.key_terms(NAME, docs=20, numterms=10)]
7d8907699829 search: name and content suggestions are fast now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
390 content_suggestions = [word for word, score in results.key_terms(CONTENT, docs=20, numterms=10)]
7d8907699829 search: name and content suggestions are fast now
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1983
diff changeset
391 flaskg.clock.stop('search suggestions')
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
392 flaskg.clock.start('search render')
2538
008e9d6e2040 PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2537
diff changeset
393
2531
7ec50a76110a Adds suggestions-as-you-type feature for the search function
sharky93 <rishabhr123@gmail.com>
parents: 2530
diff changeset
394 lastword = query.split(' ')[-1]
7ec50a76110a Adds suggestions-as-you-type feature for the search function
sharky93 <rishabhr123@gmail.com>
parents: 2530
diff changeset
395 word_suggestions = []
7ec50a76110a Adds suggestions-as-you-type feature for the search function
sharky93 <rishabhr123@gmail.com>
parents: 2530
diff changeset
396 if len(lastword) > 2:
7ec50a76110a Adds suggestions-as-you-type feature for the search function
sharky93 <rishabhr123@gmail.com>
parents: 2530
diff changeset
397 corrector = searcher.corrector(CONTENT)
7ec50a76110a Adds suggestions-as-you-type feature for the search function
sharky93 <rishabhr123@gmail.com>
parents: 2530
diff changeset
398 word_suggestions = corrector.suggest(lastword, limit=3)
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
399 if ajax:
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
400 html = render_template('ajaxsearch.html',
2539
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
401 results=results,
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
402 word_suggestions=u', '.join(word_suggestions),
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
403 name_suggestions=u', '.join(name_suggestions),
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
404 content_suggestions=u', '.join(content_suggestions),
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
405 omitted_words=u', '.join(omitted_words),
2545
6938dad629da merged sharky's other repo
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2298 2539
diff changeset
406 history=history,
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
407 )
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
408 else:
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
409 html = render_template('search.html',
2539
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
410 results=results,
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
411 name_suggestions=u', '.join(name_suggestions),
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
412 content_suggestions=u', '.join(content_suggestions),
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
413 query=query,
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
414 medium_search_form=search_form,
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
415 item_name=item_name,
1c873c0165f3 More PEP8 fixes
sharky93 <rishabhr123@gmail.com>
parents: 2538
diff changeset
416 omitted_words=u', '.join(omitted_words),
2545
6938dad629da merged sharky's other repo
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2298 2539
diff changeset
417 history=history,
2530
bfb653c10406 Adds AJAX search feature, for JS disabled, fallback mode and search still works
sharky93 <rishabhr123@gmail.com>
parents: 2102
diff changeset
418 )
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
419 flaskg.clock.stop('search render')
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
420 else:
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
421 html = render_template('search.html',
379
fb400cd3391f Add long search input field on search results page, remove highlighing search results due bugs, some fixes in css
Michael Mayorov <marchael@kb.csu.ru>
parents: 378
diff changeset
422 query=query,
401
215d7a8f5b3e Fixes #6.
Michael Mayorov <marchael@kb.csu.ru>
parents: 398
diff changeset
423 medium_search_form=search_form,
1636
72ec4f9a96fa Add search subitems capability through the +search/<item_name> view. Currently used on blog to search blog and blog entries.
Pavel Sviderski <pavel@psviderski.name>
parents: 1635
diff changeset
424 item_name=item_name,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
425 )
829
1cdd8d4eaed4 search: add timers for searching and result rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 827
diff changeset
426 return html
249
20c18292bd02 use flatland and some html5 features for search form, details see below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 248
diff changeset
427
802
919ae0e7ef1c add a separate +search view, remove incomplete search paging support, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 798
diff changeset
428
1457
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
429 def add_presenter(wrapped, view, add_trail=False, abort404=True):
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
430 """
1457
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
431 Add new "presenter" views.
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
432
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
433 Presenter views handle GET requests to locations like
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
434 +{view}/+<rev>/<item_name> and +{view}/<item_name>, and always try to
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
435 look up the item before processing.
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
436
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
437 :param view: name of view
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
438 :param add_trail: whether to call flaskg.user.add_trail
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
439 :param abort404: whether to abort(404) for nonexistent items
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
440 """
1457
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
441 @frontend.route('/+{view}/+<rev>/<itemname:item_name>'.format(view=view))
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
442 @frontend.route('/+{view}/<itemname:item_name>'.format(view=view), defaults=dict(rev=CURRENT))
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
443 @wraps(wrapped)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
444 def wrapper(item_name, rev):
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
445 if add_trail:
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
446 flaskg.user.add_trail(item_name)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
447 try:
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
448 item = Item.create(item_name, rev_id=rev)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
449 except AccessDenied:
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
450 abort(403)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
451 if abort404 and isinstance(item, NonExistent):
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
452 abort(404, item_name)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
453 return wrapped(item)
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
454 return wrapper
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
455
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
456
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
457 def presenter(view, add_trail=False, abort404=True):
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
458 """
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
459 Decorator factory to apply add_presenter().
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
460 """
49ab1a99df24 apps/frontend/views.py: Reduce one nesting level of @presenter
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1454
diff changeset
461 return partial(add_presenter, view=view, add_trail=add_trail, abort404=abort404)
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
462
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
463
1662
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1636
diff changeset
464 # The first form accepts POST to allow modifying behavior like modify_item.
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1636
diff changeset
465 # The second form only accpets GET since modifying a historical revision is not allowed (yet).
465b22852fae Let Item subclasses handle +show.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1636
diff changeset
466 @frontend.route('/<itemname:item_name>', defaults=dict(rev=CURRENT), methods=['GET', 'POST'])
956
9838477f0b68 disambiguate URLs by prefixing revid with +
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 955
diff changeset
467 @frontend.route('/+show/+<rev>/<itemname:item_name>', methods=['GET'])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
468 def show_item(item_name, rev):
2617
01d801e328de Added fqname support to notification module
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2589
diff changeset
469 fqname = split_fqname(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
470 item_displayed.send(app._get_current_object(),
2617
01d801e328de Added fqname support to notification module
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2589
diff changeset
471 fqname=fqname)
2251
22d1b58d785f Fix for issue 19. Redirects for deault roots are now done in the show function itself.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2250
diff changeset
472 if not fqname.value and fqname.field == NAME_EXACT:
22d1b58d785f Fix for issue 19. Redirects for deault roots are now done in the show function itself.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2250
diff changeset
473 fqname = fqname.get_root_fqname()
2257
a39955ac972f cleanup ..
Ashutosh Singla <ashu1461@gmail.com>
parents: 2256
diff changeset
474 return redirect(url_for_item(fqname))
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
476 item = Item.create(item_name, rev_id=rev)
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
477 flaskg.user.add_trail(item_name)
2090
10898faa48b8 Catch AccessDenied errors originating in item.do_show.
Andreas Kloeckner <inform@tiker.net>
parents: 2052
diff changeset
478 result = item.do_show(rev)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
479 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
480 abort(403)
2226
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
481 except FieldNotUniqueError:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
482 revs = flaskg.storage.documents(**fqname.query)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
483 fq_names = []
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
484 for rev in revs:
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
485 fq_names.extend(rev.fqnames)
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
486 return render_template("link_list_no_item_panel.html",
09a9bffa1581 Added Support for non-unique fields plus toggling b//w fqname and value on mouseover.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2220
diff changeset
487 headline=_("Items with %(field)s %(value)s", field=fqname.field, value=fqname.value),
2260
c800c819efc4 Updated fqname support to show view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2257
diff changeset
488 fqname=fqname,
c800c819efc4 Updated fqname support to show view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2257
diff changeset
489 fq_names=fq_names,
c800c819efc4 Updated fqname support to show view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2257
diff changeset
490 )
2090
10898faa48b8 Catch AccessDenied errors originating in item.do_show.
Andreas Kloeckner <inform@tiker.net>
parents: 2052
diff changeset
491 return result
0
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
1899
f38a893334b5 new ItemNameConverter that does not match trailing slashes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1870
diff changeset
494 @frontend.route('/<itemname:item_name>/') # note: unwanted trailing slash
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495 @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
496 def redirect_show_item(item_name):
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 294
diff changeset
497 return redirect(url_for_item(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
498
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
499
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
500 @presenter('dom', abort404=False)
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
501 def show_dom(item):
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
502 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
503 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
504 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505 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
506 content = render_template('dom.xml',
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
507 data_xml=Markup(item.content._render_data_xml()),
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
508 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
509 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
510
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
511
294
5158f027bb3f use converters to convert a rev to indexable content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 271
diff changeset
512 # XXX this is just a temporary view to test the indexing converter
956
9838477f0b68 disambiguate URLs by prefixing revid with +
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 955
diff changeset
513 @frontend.route('/+indexable/+<rev>/<itemname:item_name>')
859
95d1033b7808 fix show/meta view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 858
diff changeset
514 @frontend.route('/+indexable/<itemname:item_name>', defaults=dict(rev=CURRENT))
294
5158f027bb3f use converters to convert a rev to indexable content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 271
diff changeset
515 def indexable(item_name, rev):
894
93ae039cb363 fixed indexable and diff views, use revids not revnos for diffs and urls
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 889
diff changeset
516 from MoinMoin.storage.middleware.indexing import convert_to_indexable
1103
ed265a8018bf fix indexable/sitemap views for non-existing items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1101
diff changeset
517 try:
ed265a8018bf fix indexable/sitemap views for non-existing items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1101
diff changeset
518 item = flaskg.storage[item_name]
ed265a8018bf fix indexable/sitemap views for non-existing items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1101
diff changeset
519 rev = item[rev]
ed265a8018bf fix indexable/sitemap views for non-existing items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1101
diff changeset
520 except KeyError:
1262
65d36909177b fix 404 behaviour, the error handler wants the item name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1241
diff changeset
521 abort(404, item_name)
1039
b521a6667a54 access to Item's name through name property instead of meta directly.
Luis Henrique Fagundes <lhfagundes@gmail.com>
parents: 1032
diff changeset
522 content = convert_to_indexable(rev.meta, rev.data, item_name)
294
5158f027bb3f use converters to convert a rev to indexable content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 271
diff changeset
523 return Response(content, 200, mimetype='text/plain')
5158f027bb3f use converters to convert a rev to indexable content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 271
diff changeset
524
5158f027bb3f use converters to convert a rev to indexable content
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 271
diff changeset
525
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
526 @presenter('highlight')
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
527 def highlight_item(item):
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
528 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
529 item=item, item_name=item.name,
2266
dea5f965ae8b Updated fqname support to highlight view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2265
diff changeset
530 fqname=item.fqname,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
531 data_text=Markup(item.content._render_data_highlight()),
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
532 )
202
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
533
9ffa82e550ba highlight view: move dom conversion code to Item method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 197
diff changeset
534
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
535 @presenter('meta', add_trail=True)
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
536 def show_item_meta(item):
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
537 show_revision = request.view_args['rev'] != CURRENT
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
538 show_navigation = False # TODO
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
539 first_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
540 last_rev = None
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
541 if show_navigation:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
542 rev_ids = list(item.rev.item.iter_revs())
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
543 if rev_ids:
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
544 first_rev = rev_ids[0]
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
545 last_rev = rev_ids[-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
546 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
547 item=item, item_name=item.name,
2264
8e97ca0b5e83 Updated fqname support to meta view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2262
diff changeset
548 fqname=item.fqname,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
549 rev=item.rev,
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
550 contenttype=item.contenttype,
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
551 first_rev_id=first_rev,
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
552 last_rev_id=last_rev,
2669
7798855349f6 Improved Metadata view
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2655
diff changeset
553 meta=item._meta_info(),
74
079c61438b3f only compute revisions list if navigation is shown
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 38
diff changeset
554 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
555 show_navigation=show_navigation,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
556 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
557
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
558
956
9838477f0b68 disambiguate URLs by prefixing revid with +
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 955
diff changeset
559 @frontend.route('/+content/+<rev>/<itemname:item_name>')
859
95d1033b7808 fix show/meta view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 858
diff changeset
560 @frontend.route('/+content/<itemname:item_name>', defaults=dict(rev=CURRENT))
756
ab4083ea79ed frontend.views: renamed show_content to content_item
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 755
diff changeset
561 def content_item(item_name, rev):
755
d5daf53230ad frontend.views: show_content reintroduced. Same as show_item, but we only show the content.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 535
diff changeset
562 """ same as show_item, but we only show the content """
2617
01d801e328de Added fqname support to notification module
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2589
diff changeset
563 fqname = split_fqname(item_name)
01d801e328de Added fqname support to notification module
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2589
diff changeset
564 item_displayed.send(app, fqname=fqname)
755
d5daf53230ad frontend.views: show_content reintroduced. Same as show_item, but we only show the content.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 535
diff changeset
565 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
566 item = Item.create(item_name, rev_id=rev)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
567 except AccessDenied:
755
d5daf53230ad frontend.views: show_content reintroduced. Same as show_item, but we only show the content.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 535
diff changeset
568 abort(403)
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
569 if isinstance(item, NonExistent):
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
570 abort(404, item_name)
757
c9381c5ce219 frontend.views.content_item: simplified
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 756
diff changeset
571 return render_template('content.html',
c9381c5ce219 frontend.views.content_item: simplified
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 756
diff changeset
572 item_name=item.name,
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
573 data_rendered=Markup(item.content._render_data()),
757
c9381c5ce219 frontend.views.content_item: simplified
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 756
diff changeset
574 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
575
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
576
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
577 @presenter('get')
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
578 def get_item(item):
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
579 return item.content.do_get()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
580
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
581
1391
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
582 @presenter('download')
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
583 def download_item(item):
339668f8ad06 refactor of apps/frontend/views.py and items/__init__.py modules
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1379
diff changeset
584 mimetype = request.values.get("mimetype")
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
585 return item.content.do_get(force_attachment=True, mimetype=mimetype)
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
586
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
587
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
588 @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
589 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
590 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
591 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
592
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
593 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
594 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
595
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
596 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
597 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
598 """
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
599 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
600 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
601 item = Item.create(item_name, rev_id=CURRENT)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
602 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
603 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
604 # 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
605 # 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
606 # 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
607 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
608 try:
1453
accea307e94e Fix some comments in the itemtype changeset.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1451
diff changeset
609 # TODO implement Content.create and use it here
1991
38e79cd2b320 use more constants: ITEMTYPE_DEFAULT
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1988
diff changeset
610 converted_item = Item.create(item_name_converted, itemtype=ITEMTYPE_DEFAULT, contenttype=contenttype)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
611 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
612 abort(403)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
613 return converted_item.content._convert(item.content.internal_representation())
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
614
242
e93157b8b0bd refactor modify views to use flatland, see details below
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 237
diff changeset
615
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 @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
617 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
618 """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
619
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
620 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
621 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
622 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
623 """
1772
47914f18089c drawing applets don't send itemtype
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 1767
diff changeset
624 # XXX drawing applets don't send itemtype
1991
38e79cd2b320 use more constants: ITEMTYPE_DEFAULT
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1988
diff changeset
625 itemtype = request.values.get('itemtype', ITEMTYPE_DEFAULT)
216
661a57c747bd replace mimetype by contenttype, use more constants
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 202
diff changeset
626 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
627 try:
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
628 item = Item.create(item_name, itemtype=itemtype, contenttype=contenttype)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
629 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
630 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
631 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
632 abort(403)
1451
c32ff2e07e7a Introduce itemtype.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1449
diff changeset
633 return item.do_modify()
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
634
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
635
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
636 class TargetChangeForm(BaseChangeForm):
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
637 target = RequiredText.using(label=L_('Target')).with_properties(placeholder=L_("The name of the target item"))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
638
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
639
2220
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
640 class ValidRevert(Validator):
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
641 """
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
642 Validator for a valid revert form.
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
643 """
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
644 invalid_name_msg = ''
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
645
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
646 def validate(self, element, state):
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
647 """
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
648 Check whether the names present in the previous meta are not taken by some other item.
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
649 """
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
650 try:
2294
e615e3bbe48d Fixed broken links.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2291
diff changeset
651 validate_name(state['meta'], state['meta'].get(ITEMID))
2220
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
652 return True
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
653 except NameNotValidError as e:
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
654 self.invalid_name_msg = _(e)
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
655 return self.note_error(element, state, 'invalid_name_msg')
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
656
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
657
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
658 class RevertItemForm(BaseChangeForm):
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
659 name = 'revert_item'
2220
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
660 validators = [ValidRevert()]
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
661
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
662
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
663 class DeleteItemForm(BaseChangeForm):
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
664 name = 'delete_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
665
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
666
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
667 class DestroyItemForm(BaseChangeForm):
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
668 name = 'destroy_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
669
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
670
1420
100197cb69ab Convert Flatland forms to contain rendering hints.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1407
diff changeset
671 class RenameItemForm(TargetChangeForm):
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
672 name = 'rename_item'
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
673
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
674
956
9838477f0b68 disambiguate URLs by prefixing revid with +
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 955
diff changeset
675 @frontend.route('/+revert/+<rev>/<itemname:item_name>', methods=['GET', '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
676 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
677 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
678 item = Item.create(item_name, rev_id=rev)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
679 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
680 abort(403)
1031
64e6be47c4f6 fixes #44. Check for permission in frontend view. Hide link to actions that user is not allowed to do in the history and in the rev_navigation
Bruno Martin <bruno@hacklab.com.br>
parents: 1005
diff changeset
681 if not flaskg.user.may.write(item_name):
64e6be47c4f6 fixes #44. Check for permission in frontend view. Hide link to actions that user is not allowed to do in the history and in the rev_navigation
Bruno Martin <bruno@hacklab.com.br>
parents: 1005
diff changeset
682 abort(403)
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
683 if isinstance(item, NonExistent):
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
684 abort(404, item_name)
1963
f05af7eb6f50 fix handling of HEAD requests
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1913
diff changeset
685 if request.method in ['GET', 'HEAD']:
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
686 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
687 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
688 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
689 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
690 TextCha(form).amend_form()
2220
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
691 state = dict(fqname=item.fqname, meta=dict(item.meta))
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
692 if form.validate(state):
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
693 item.revert(form['comment'])
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 294
diff changeset
694 return redirect(url_for_item(item_name))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
695 return render_template(item.revert_template,
2220
81652de0216c Added support for multiple names in revert view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2214
diff changeset
696 item=item, fqname=item.fqname,
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
697 rev_id=rev,
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
698 form=form,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
699 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
700
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
701
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
702 @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
703 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
704 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
705 item = Item.create(item_name)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
706 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
707 abort(403)
2267
9c177f0ba6c3 Added fqname support to rename view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2266
diff changeset
708 if not flaskg.user.may.write(item.fqname):
1031
64e6be47c4f6 fixes #44. Check for permission in frontend view. Hide link to actions that user is not allowed to do in the history and in the rev_navigation
Bruno Martin <bruno@hacklab.com.br>
parents: 1005
diff changeset
709 abort(403)
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
710 if isinstance(item, NonExistent):
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
711 abort(404, item_name)
1963
f05af7eb6f50 fix handling of HEAD requests
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1913
diff changeset
712 if request.method in ['GET', 'HEAD']:
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
713 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
714 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
715 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
716 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
717 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
718 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
719 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
720 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
721 comment = form['comment'].value
2052
f1d7f77b71a9 Fixes 346 (Item Rename allows new name to reuse existing name)
Ashutosh Singla <ashu1461@gmail.com>
parents: 2019
diff changeset
722 try:
2267
9c177f0ba6c3 Added fqname support to rename view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2266
diff changeset
723 fqname = CompositeName(item.fqname.namespace, item.fqname.field, target)
2052
f1d7f77b71a9 Fixes 346 (Item Rename allows new name to reuse existing name)
Ashutosh Singla <ashu1461@gmail.com>
parents: 2019
diff changeset
724 item.rename(target, comment)
2267
9c177f0ba6c3 Added fqname support to rename view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2266
diff changeset
725 return redirect(url_for_item(fqname))
2052
f1d7f77b71a9 Fixes 346 (Item Rename allows new name to reuse existing name)
Ashutosh Singla <ashu1461@gmail.com>
parents: 2019
diff changeset
726 except NameNotUniqueError as e:
f1d7f77b71a9 Fixes 346 (Item Rename allows new name to reuse existing name)
Ashutosh Singla <ashu1461@gmail.com>
parents: 2019
diff changeset
727 flash(str(e), "error")
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
728 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
729 item=item, item_name=item_name,
2267
9c177f0ba6c3 Added fqname support to rename view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2266
diff changeset
730 fqname=item.fqname,
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
731 form=form,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
732 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
733
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
734
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
735 @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
736 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
737 try:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
738 item = Item.create(item_name)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
739 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
740 abort(403)
2268
9ad7a108b511 Added fqname support to delete view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2267
diff changeset
741 if not flaskg.user.may.write(item.fqname):
1031
64e6be47c4f6 fixes #44. Check for permission in frontend view. Hide link to actions that user is not allowed to do in the history and in the rev_navigation
Bruno Martin <bruno@hacklab.com.br>
parents: 1005
diff changeset
742 abort(403)
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
743 if isinstance(item, NonExistent):
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
744 abort(404, item_name)
1963
f05af7eb6f50 fix handling of HEAD requests
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1913
diff changeset
745 if request.method in ['GET', 'HEAD']:
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
746 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
747 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
748 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
749 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
750 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
751 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
752 comment = form['comment'].value
1186
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
753 try:
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
754 item.delete(comment)
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
755 except AccessDenied:
1187
82a7411e0653 Fix PEP8 issue, remove spacing between abort and parentheses
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1186
diff changeset
756 abort(403)
316
4ee796d759bf use url_for_item where appropriate (in py code, no template changes yet)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 294
diff changeset
757 return redirect(url_for_item(item_name))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
758 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
759 item=item, item_name=item_name,
2268
9ad7a108b511 Added fqname support to delete view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2267
diff changeset
760 fqname=split_fqname(item_name),
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
761 form=form,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
762 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
763
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
764
511
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
765 @frontend.route('/+ajaxdelete/<itemname:item_name>', methods=['POST'])
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
766 @frontend.route('/+ajaxdelete', defaults=dict(item_name=''), methods=['POST'])
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
767 def ajaxdelete(item_name):
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
768 if request.method == 'POST':
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
769 args = request.values.to_dict()
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
770 comment = args.get("comment")
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
771 itemnames = args.get("itemnames")
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
772 itemnames = json.loads(itemnames)
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
773 if item_name:
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
774 subitem_prefix = item_name + u'/'
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
775 else:
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
776 subitem_prefix = u''
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
777 response = {"itemnames": [], "status": []}
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
778 for itemname in itemnames:
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
779 response["itemnames"].append(itemname)
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
780 itemname = subitem_prefix + itemname
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
781 try:
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
782 item = Item.create(itemname)
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
783 item.delete(comment)
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
784 response["status"].append(True)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
785 except AccessDenied:
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
786 response["status"].append(False)
511
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
787
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
788 return jsonify(response)
5c86980e7d06 Ajax delete feature for the items, has been added on index page.
Akash Sinha <akash2607@gmail.com>
parents: 510
diff changeset
789
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
790
512
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
791 @frontend.route('/+ajaxdestroy/<itemname:item_name>', methods=['POST'])
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
792 @frontend.route('/+ajaxdestroy', defaults=dict(item_name=''), methods=['POST'])
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
793 def ajaxdestroy(item_name):
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
794 if request.method == 'POST':
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
795 args = request.values.to_dict()
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
796 comment = args.get("comment")
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
797 itemnames = args.get("itemnames")
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
798 itemnames = json.loads(itemnames)
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
799 if item_name:
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
800 subitem_prefix = item_name + u'/'
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
801 else:
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
802 subitem_prefix = u''
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
803 response = {"itemnames": [], "status": []}
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
804 for itemname in itemnames:
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
805 response["itemnames"].append(itemname)
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
806 itemname = subitem_prefix + itemname
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
807 try:
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
808 item = Item.create(itemname)
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
809 item.destroy(comment=comment, destroy_item=True)
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
810 response["status"].append(True)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
811 except AccessDenied:
520
6332dda59cb6 some pep8 fixes
Akash Sinha <akash2607@gmail.com>
parents: 518
diff changeset
812 response["status"].append(False)
512
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
813
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
814 return jsonify(response)
92314b3890a8 Ajax destroy feature added on index page (similar to the delete feature).
Akash Sinha <akash2607@gmail.com>
parents: 511
diff changeset
815
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
816
515
e665d70b0278 index page view modified (elements re-arranged on the page)
Akash Sinha <akash2607@gmail.com>
parents: 513
diff changeset
817 @frontend.route('/+ajaxmodify/<itemname:item_name>', methods=['POST'])
e665d70b0278 index page view modified (elements re-arranged on the page)
Akash Sinha <akash2607@gmail.com>
parents: 513
diff changeset
818 @frontend.route('/+ajaxmodify', methods=['POST'], defaults=dict(item_name=''))
513
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
819 def ajaxmodify(item_name):
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
820 newitem = request.values.get("newitem")
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
821 if not newitem:
1262
65d36909177b fix 404 behaviour, the error handler wants the item name
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1241
diff changeset
822 abort(404, item_name)
513
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
823 if item_name:
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
824 newitem = item_name + u'/' + newitem
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
825
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
826 return redirect(url_for('.modify_item', item_name=newitem))
050c5d125762 New item tab added on index page, and Upload file button also moved under that new item box (but drag-drop area kept to whole screen as it was earlier)
Akash Sinha <akash2607@gmail.com>
parents: 512
diff changeset
827
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
828
956
9838477f0b68 disambiguate URLs by prefixing revid with +
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 955
diff changeset
829 @frontend.route('/+destroy/+<rev>/<itemname:item_name>', methods=['GET', '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
830 @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
831 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
832 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
833 # no revision given
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
834 _rev = CURRENT # for item creation
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
835 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
836 else:
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
837 _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
838 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
839 try:
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
840 item = Item.create(item_name, rev_id=_rev)
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
841 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
842 abort(403)
2238
913c1b908070 Destroy view is now fqname friendly.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2236
diff changeset
843 fqname = item.fqname
913c1b908070 Destroy view is now fqname friendly.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2236
diff changeset
844 if not flaskg.user.may.destroy(fqname):
1031
64e6be47c4f6 fixes #44. Check for permission in frontend view. Hide link to actions that user is not allowed to do in the history and in the rev_navigation
Bruno Martin <bruno@hacklab.com.br>
parents: 1005
diff changeset
845 abort(403)
1003
8621c3e273a1 fixes #72. Implements the page to handle 404 error, and calls abort(404) in some view, when apropriate.
Bruno Martin <bruno@hacklab.com.br>
parents: 971
diff changeset
846 if isinstance(item, NonExistent):
2238
913c1b908070 Destroy view is now fqname friendly.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2236
diff changeset
847 abort(404, fqname.fullname)
1963
f05af7eb6f50 fix handling of HEAD requests
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1913
diff changeset
848 if request.method in ['GET', 'HEAD']:
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
849 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
850 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
851 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
852 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
853 TextCha(form).amend_form()
246
727e03c59dbf simplify form validation check, fix indentation
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 242
diff changeset
854 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
855 comment = form['comment'].value
1186
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
856 try:
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
857 item.destroy(comment=comment, destroy_item=destroy_item)
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
858 except AccessDenied:
ca53b9687f94 Catch AccessDenied exceptions while delete()ing or destroy()ing, and show an HTTP 403 error page instead of a traceback
Bilal Akhtar <bilalakhtar@ubuntu.com>
parents: 1140
diff changeset
859 abort(403)
2238
913c1b908070 Destroy view is now fqname friendly.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2236
diff changeset
860 return redirect(url_for_item(fqname.fullname))
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
861 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
862 item=item, item_name=item_name,
2238
913c1b908070 Destroy view is now fqname friendly.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2236
diff changeset
863 fqname=fqname,
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
864 rev_id=rev,
230
29b3586181cb simple item actions now use flatland based forms
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 226
diff changeset
865 form=form,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
866 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
867
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
868
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
869 @frontend.route('/+jfu-server/<itemname:item_name>', methods=['POST'])
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
870 @frontend.route('/+jfu-server', defaults=dict(item_name=''), methods=['POST'])
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
871 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
872 """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
873 """
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
874 data_file = request.files.get('data_file')
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
875 subitem_name = data_file.filename
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
876 contenttype = data_file.content_type # guess by browser, based on file name
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
877 data = data_file.stream
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
878 if item_name:
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
879 subitem_prefix = item_name + u'/'
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
880 else:
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
881 subitem_prefix = u''
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
882 item_name = subitem_prefix + subitem_name
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
883 try:
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
884 item = Item.create(item_name)
1407
8bbdf554e812 Cleanups and fixes for the items module.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1397
diff changeset
885 revid, size = item.modify({}, data, contenttype_guessed=contenttype)
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
886 item_modified.send(app._get_current_object(),
2617
01d801e328de Added fqname support to notification module
Saurabh Kathpalia <saurabh.kathpalia95@gmail.com>
parents: 2589
diff changeset
887 fqname=item.fqname, action=ACTION_SAVE)
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
888 return jsonify(name=subitem_name,
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
889 size=size,
905
51475954290f rename all revno usages to revid (no numbers any more), remove update_item param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 900
diff changeset
890 url=url_for('.show_item', item_name=item_name, rev=revid),
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
891 contenttype=contenttype_to_class(contenttype),
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
892 )
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
893 except AccessDenied:
493
17132086b9d6 File upload functionality moved from index2 to index, index2 has been removed, as well as its link from itemviews bar also.
Akash Sinha <akash2607@gmail.com>
parents: 491
diff changeset
894 abort(403)
194
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
895
389cd14f0888 integrate jquery.file-upload as /+index2 view, adapt quickinstall script
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 174
diff changeset
896
2019
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
897 def contenttype_selects_gen():
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
898 for g in content_registry.group_names:
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
899 description = u', '.join([e.display_name for e in content_registry.groups[g]])
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
900 yield g, None, description
2653
011a118feecf Improved the Index GUI using bootstrap classes in the basic theme. Used navbar to show actions instead of the previous list. Fixed the popup for new files, which was earlier always present on the index page itself. Also added smileys for the basic theme which were missing earlier.
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2651
diff changeset
901 yield u'Unknown Items', None, u'Items of contenttype unknown to MoinMoin'
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
902
2019
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
903 ContenttypeGroup = MultiSelect.of(Enum.out_of(contenttype_selects_gen())).using(optional=True)
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
904
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
905
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
906 class IndexForm(Form):
1742
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
907 contenttype = ContenttypeGroup
1988
490c13d072f2 remove Submit widget
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1986
diff changeset
908 submit_label = L_('Filter')
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
909
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
910
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
911 @frontend.route('/+index/', defaults=dict(item_name=''), methods=['GET', 'POST'])
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
912 @frontend.route('/+index/<itemname:item_name>', methods=['GET', '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
913 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
914 try:
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
915 item = Item.create(item_name) # when item_name='', it gives toplevel index
1005
c36f61f85e97 AccessDeniedError replaced by AccessDenied, from the new storage api.
Bruno Martin <bruno@hacklab.com.br>
parents: 1003
diff changeset
916 except AccessDenied:
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
917 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
918
1742
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
919 # request.args is a MultiDict instance, which degenerates into a normal
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
920 # single-valued dict on most occasions (making the first value the *only*
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
921 # value for a specific key) unless explicitly told to expose multiple
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
922 # values, eg. calling items with multi=True. See Werkzeug documentation for
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
923 # more.
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
924 form = IndexForm.from_flat(request.args.items(multi=True))
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
925 if not form['contenttype']:
2019
ecd902b614bd factor out common code for building Select and MultiSelect widgets
Cheer Xiao <xiaqqaix@gmail.com>
parents: 2011
diff changeset
926 form['contenttype'].set(ContenttypeGroup.member_schema.valid_values)
1741
bf840fab4737 On +index view, Use GET for filtering.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1732
diff changeset
927
1742
8f18745faf4a In +index view, use a multivalue instead of multiple booleans for contentype
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1741
diff changeset
928 selected_groups = form['contenttype'].value
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
929 startswith = request.values.get("startswith")
486
b6149c732926 contenttype filtering added to global index page
Akash Sinha <akash2607@gmail.com>
parents: 485
diff changeset
930
1938
b8cfcf3bb9aa fix initials computation for NAME being a list, move sort/upper/lower code to method
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1934
diff changeset
931 initials = item.name_initial(item.get_subitem_revs(), uppercase=True)
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
932
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1781
diff changeset
933 dirs, files = item.get_index(startswith, selected_groups)
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1781
diff changeset
934 # index = sorted(index, key=lambda e: e.relname.lower())
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
935 fqname = item.fqname
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
936 if fqname.value == NAMESPACE_ALL:
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
937 fqname = CompositeName(NAMESPACE_ALL, NAME_EXACT, u'')
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
938 item_names = item_name.split(u'/')
2559
b9133a780db8 Fixed location line to show separate location for Global Index and Subitem Index as per issue #410
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2545
diff changeset
939 if not item_name:
b9133a780db8 Fixed location line to show separate location for Global Index and Subitem Index as per issue #410
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2545
diff changeset
940 title_name = _(u'Global Index')
b9133a780db8 Fixed location line to show separate location for Global Index and Subitem Index as per issue #410
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2545
diff changeset
941 else:
b9133a780db8 Fixed location line to show separate location for Global Index and Subitem Index as per issue #410
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2545
diff changeset
942 title_name = _(u'Subitem Index')
497
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
943 return render_template(item.index_template,
d20568493a93 unified global_index and item index, thus we are now left with only 1 type of index
Akash Sinha <akash2607@gmail.com>
parents: 495
diff changeset
944 item_names=item_names,
1726
d697fd14e772 Various cleanup for item index code (+index view and related methods of Item).
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1675
diff changeset
945 item_name=item_name,
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
946 fqname=fqname,
1800
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1781
diff changeset
947 files=files,
54062fc0ca97 Separate "directory" and "file" items in the index view.
Cheer Xiao <xiaqqaix@gmail.com>
parents: 1781
diff changeset
948 dirs=dirs,
477
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
949 initials=initials,
72899d48db41 alphabetic listing of global index, with link to item index
Akash Sinha <akash2607@gmail.com>
parents: 475
diff changeset
950 startswith=startswith,
490
a7207331864a contenttype filter form is replaced by flatland form in global_index page
Akash Sinha <akash2607@gmail.com>
parents: 488
diff changeset
951 form=form,
2559
b9133a780db8 Fixed location line to show separate location for Global Index and Subitem Index as per issue #410
Ajitesh Gupta <ajgupta93@gmail.com>
parents: 2545
diff changeset
952 title_name=title_name,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
953 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
954
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
955
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
956 @frontend.route('/+mychanges')
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
957 def mychanges():
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
958 """
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
959 Returns the list of all items the current user has contributed to.
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
960
2139
e383d2b70de1 fix docstring of +mychanges view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2137
diff changeset
961 :returns: a page with all the items the current user has contributed to
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
962 """
2771
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
963 offset = request.values.get('offset', 0)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
964 offset = max(int(offset), 0)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
965 if flaskg.user.valid:
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
966 results_per_page = flaskg.user.results_per_page
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
967 else:
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
968 results_per_page = app.cfg.results_per_page
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
969 my_changes = _mychanges(flaskg.user.itemid)
2771
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
970 my_changes_page = util.getPageContent(my_changes, offset, results_per_page)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
971 return render_template('mychanges.html',
1006
b65a998fab8e fixes #61 using title_name instead of item_name for pages without an item
Bruno Gola <brunogola@gmail.com>
parents: 971
diff changeset
972 title_name=_(u'My Changes'),
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
973 headline=_(u'My Changes'),
2771
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
974 my_changes=my_changes,
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
975 my_changes_page=my_changes_page,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
976 )
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
977
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
978
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
979 def _mychanges(userid):
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
980 """
2247
3f532c2cac83 Multiple names support for /+mychanges.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2246
diff changeset
981 Returns a list with all fqnames of items which user userid has contributed to.
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
982
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
983 :param userid: user itemid
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
984 :type userid: unicode
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
985 :returns: the list of all items with user userid's contributions
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
986 """
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
987 q = And([Term(WIKINAME, app.cfg.interwikiname),
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
988 Term(USERID, userid)])
2771
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
989 revs = flaskg.storage.search(q, idx_name=ALL_REVS, sortedby=[MTIME], reverse=True, limit=None)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
990 # get rid of the content value to save potentially big amounts of memory:
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
991 history = []
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
992 for rev in revs:
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
993 entry = dict(rev.meta)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
994 entry[FQNAME] = rev.fqname
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
995 history.append(entry)
5762664a2887 make /+mychanges work similar to local history, needs more work...
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
996 return history
938
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
997
046320bc0f82 implement +mychanges view - list all items the current user has contributed to
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 933
diff changeset
998
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
999 @frontend.route('/+forwardrefs/<itemname:item_name>')
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1000 def forwardrefs(item_name):
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1001 """
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1002 Returns the list of all links or transclusions of item item_name
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1003
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1004 :param item_name: the name of the current item
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1005 :type item_name: unicode
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1006 :returns: a page with all the items linked from this item
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1007 """
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1008 refs = _forwardrefs(item_name)
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1009 return render_template('link_list_item_panel.html',
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1010 item_name=item_name,
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1011 fqname=split_fqname(item_name),
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1012 headline=_(u"Items that are referred by '%(item_name)s'", item_name=item_name),
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1013 fq_names=split_fqname_list(refs),
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1014 )
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1015
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1016
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1017 def _forwardrefs(item_name):
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1018 """
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1019 Returns a list with all names of items that get referenced from item_name
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1020
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1021 :param item_name: the name of the current item
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1022 :type item_name: unicode
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1023 :returns: the list of all items which are referenced from this item
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1024 """
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1025 fqname = split_fqname(item_name)
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1026 q = fqname.query
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1027 q[WIKINAME] = app.cfg.interwikiname
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1028 rev = flaskg.storage.document(**q)
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1029 if rev is None:
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1030 refs = []
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1031 else:
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1032 refs = rev.meta.get(ITEMLINKS, []) + rev.meta.get(ITEMTRANSCLUSIONS, [])
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1033 return set(refs)
2136
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1034
9d4dad921261 add +forwardrefs view to complement +backrefs view
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2131
diff changeset
1035
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 @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
1037 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
1038 """
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1039 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
1040
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
1041 :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
1042 :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
1043 :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
1044 """
2162
a704bbeb189c pass item object as argument to render template
Ana Balica <ana.balica@gmail.com>
parents: 2161
diff changeset
1045 try:
a704bbeb189c pass item object as argument to render template
Ana Balica <ana.balica@gmail.com>
parents: 2161
diff changeset
1046 item = Item.create(item_name)
a704bbeb189c pass item object as argument to render template
Ana Balica <ana.balica@gmail.com>
parents: 2161
diff changeset
1047 except AccessDenied:
a704bbeb189c pass item object as argument to render template
Ana Balica <ana.balica@gmail.com>
parents: 2161
diff changeset
1048 abort(403)
797
31aff629ed47 backrefs: remove some unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 796
diff changeset
1049 refs_here = _backrefs(item_name)
1870
e03714644b0f fix for 289 orphans, mychanges, wanteds, tags/tagname incorrectly show item views panel/bar
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1853
diff changeset
1050 return render_template('link_list_item_panel.html',
2162
a704bbeb189c pass item object as argument to render template
Ana Balica <ana.balica@gmail.com>
parents: 2161
diff changeset
1051 item=item,
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1052 item_name=item_name,
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1053 fqname=split_fqname(item_name),
1241
95abf895be4f Refactor title code, fixes #147
Sam Toyer <samATqxcvDOTnet>
parents: 1227
diff changeset
1054 headline=_(u"Items which refer to '%(item_name)s'", item_name=item_name),
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1055 fq_names=refs_here,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
1056 )
0
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
797
31aff629ed47 backrefs: remove some unused code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 796
diff changeset
1059 def _backrefs(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
1060 """
2269
494166b34798 Added fqname support to backrefs view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2268
diff changeset
1061 Returns a list with all names of items which ref fq_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
1062
38
1d8e9b1153d6 docstrings: convert epydoc fields to rst/sphinx fields
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 37
diff changeset
1063 :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
1064 :type item_name: unicode
2269
494166b34798 Added fqname support to backrefs view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2268
diff changeset
1065 :returns: the list of all items which ref fq_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
1066 """
827
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 824
diff changeset
1067 q = And([Term(WIKINAME, app.cfg.interwikiname),
94e388cd4e28 use 'constants' for metadata keys / whoosh field names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 824
diff changeset
1068 Or([Term(ITEMTRANSCLUSIONS, item_name), Term(ITEMLINKS, item_name)])])
953
326f7a365007 search/indexing: remove all_revs=False params (it is the default)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 938
diff changeset
1069 revs = flaskg.storage.search(q)
2270
ff7194d0a709 Added fqname support to forwardrefs view + updated +backrefs.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2269
diff changeset
1070 return set([fqname for rev in revs for fqname in rev.fqnames])
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1071
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1072
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1073 @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
1074 def history(item_name):
2256
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1075 fqname = split_fqname(item_name)
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
1076 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
1077 offset = max(int(offset), 0)
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1078 bookmark_time = int(request.values.get('bookmark', 0))
472
c04d1ca903c7 paging for item history results added
Akash Sinha <akash2607@gmail.com>
parents: 471
diff changeset
1079 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
1080 results_per_page = flaskg.user.results_per_page
777
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
1081 else:
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
1082 results_per_page = app.cfg.results_per_page
2256
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1083 terms = [Term(WIKINAME, app.cfg.interwikiname), ]
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1084 terms.extend(Term(term, value) for term, value in fqname.query.iteritems())
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1085 if bookmark_time:
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1086 terms.append(DateRange(MTIME, start=datetime.utcfromtimestamp(bookmark_time), end=None))
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1087 query = And(terms)
777
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
1088 # TODO: due to how getPageContent and the template works, we need to use limit=None -
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
1089 # it would be better to use search_page (and an appropriate limit, if needed)
954
f79d471667b9 search/indexing: replace all_revs (boolean) by idx_name (index name str) - easier code, more flexible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 953
diff changeset
1090 revs = flaskg.storage.search(query, idx_name=ALL_REVS, sortedby=[MTIME], reverse=True, limit=None)
782
5c60754f8d1a save memory by not including content in history list. Fixes #42
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 777
diff changeset
1091 # get rid of the content value to save potentially big amounts of memory:
2256
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1092 history = []
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1093 for rev in revs:
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1094 entry = dict(rev.meta)
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1095 entry[FQNAME] = rev.fqname
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1096 history.append(entry)
495
b9f0ba2ba779 paging code at item history moved under util, such that this function could be called from anywhere else.
Akash Sinha <akash2607@gmail.com>
parents: 494
diff changeset
1097 history_page = util.getPageContent(history, offset, results_per_page)
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1098 return render_template('history.html',
2256
e66f66689305 UI for switching between itemid-name based history. Also fixes #15.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2255
diff changeset
1099 fqname=fqname,
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
1100 item_name=item_name, # XXX no item here
495
b9f0ba2ba779 paging code at item history moved under util, such that this function could be called from anywhere else.
Akash Sinha <akash2607@gmail.com>
parents: 494
diff changeset
1101 history_page=history_page,
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1102 bookmark_time=bookmark_time,
2783
d75032c39f11 fix #459 Reverting a deleted item fails on Basic theme, fix Name/Item ID column display bug
RogerHaase <haaserd@gmail.com>
parents: 2771
diff changeset
1103 NAME_EXACT=NAME_EXACT,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
1104 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1105
770
a4ec2c6f0bb7 history: do not yield Revision objects, but directly result documents from whoosh
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 768
diff changeset
1106
2255
98be82eb3db8 Namespace and fqname support for global history view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2254
diff changeset
1107 @frontend.route('/<namespace>/+history')
98be82eb3db8 Namespace and fqname support for global history view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2254
diff changeset
1108 @frontend.route('/+history', defaults=dict(namespace=NAMESPACE_DEFAULT), methods=['GET'])
98be82eb3db8 Namespace and fqname support for global history view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2254
diff changeset
1109 def global_history(namespace):
920
6d9cfa2981d3 global history view: add a all=true url arg (default: false) to choose the index to be used
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 918
diff changeset
1110 all_revs = bool(request.values.get('all'))
954
f79d471667b9 search/indexing: replace all_revs (boolean) by idx_name (index name str) - easier code, more flexible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 953
diff changeset
1111 idx_name = ALL_REVS if all_revs else LATEST_REVS
2290
5beaf17c6a1a Updated Namespace all support for history views.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2288
diff changeset
1112 terms = [Term(WIKINAME, app.cfg.interwikiname)]
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
1113 fqname = CompositeName(NAMESPACE_ALL, NAME_EXACT, u'')
2255
98be82eb3db8 Namespace and fqname support for global history view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2254
diff changeset
1114 if namespace != NAMESPACE_ALL:
2290
5beaf17c6a1a Updated Namespace all support for history views.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2288
diff changeset
1115 terms.append(Term(NAMESPACE, namespace))
2291
b02bac100074 Added more support for 'all' identifier, Also fixed #24.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2290
diff changeset
1116 fqname = split_fqname(namespace)
1280
30634c59829b user bookmarks: simplify code, make .bookmark property
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1277
diff changeset
1117 bookmark_time = flaskg.user.bookmark
777
21a6765b793d killed backend.history(), replace it by .search() and appropriate query/reverse/sortedby/limit params
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 770
diff changeset
1118 if bookmark_time is not None:
2290
5beaf17c6a1a Updated Namespace all support for history views.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2288
diff changeset
1119 terms.append(DateRange(MTIME, start=datetime.utcfromtimestamp(bookmark_time), end=None))
2257
a39955ac972f cleanup ..
Ashutosh Singla <ashu1461@gmail.com>
parents: 2256
diff changeset
1120 query = And(terms)
954
f79d471667b9 search/indexing: replace all_revs (boolean) by idx_name (index name str) - easier code, more flexible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 953
diff changeset
1121 revs = flaskg.storage.search(query, idx_name=idx_name, sortedby=[MTIME], reverse=True, limit=1000)
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1122 # Group by date
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1123 history = []
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1124 day_history = namedtuple('day_history', ['day', 'entries'])
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1125 prev_date = '0000-00-00'
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1126 dh = day_history(prev_date, []) # dummy
915
3b9bef437212 global history: remove superfluous bookmark comparison, extract from rev what we need only
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 914
diff changeset
1127 for rev in revs:
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1128 rev_date = format_date(datetime.utcfromtimestamp(rev.meta[MTIME]))
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1129 if rev_date == prev_date:
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1130 dh.entries.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
1131 else:
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1132 history.append(dh)
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1133 dh = day_history(rev_date, [rev])
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1134 prev_date = rev_date
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
1135 else:
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1136 history.append(dh)
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1137 del history[0] # kill the dummy
468
511a2a2e9950 paging of history results, currently without the option of setting count per page
Akash Sinha <akash2607@gmail.com>
parents: 467
diff changeset
1138
1013
57f6267eb050 title display: add some more, make it more consistent
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1007
diff changeset
1139 title_name = _(u'Global History')
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
1140 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
1141 return render_template('global_history.html',
1013
57f6267eb050 title display: add some more, make it more consistent
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1007
diff changeset
1142 title_name=title_name,
918
764f209d1eae simplify global history (and make it faster), bookmark changes for diff and history
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 915
diff changeset
1143 history=history,
465
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
1144 current_timestamp=current_timestamp,
3076415fdaba Bookmark functionality added for the global history results
Akash Sinha <akash2607@gmail.com>
parents: 464
diff changeset
1145 bookmark_time=bookmark_time,
2290
5beaf17c6a1a Updated Namespace all support for history views.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2288
diff changeset
1146 fqname=fqname,
2011
791bdedb0c20 fix lots of pep8 issues, mainly E12x
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1991
diff changeset
1147 )
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1148
1975
384555088cab lots of pep8 fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1974
diff changeset
1149
793
328d83e165a4 whooshify _compute_item_sets (used for wanteds/orphans view)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 792
diff changeset
1150 def _compute_item_sets():
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1151 """
2272
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1152 compute sets of existing, linked, transcluded and no-revision item fqnames
0
5568cf133caf create moin/2.0 repo, drop all history (see notes below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1153 """
792
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1154 linked = set()
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1155 transcluded = set()
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1156 existing = set()
953
326f7a365007 search/indexing: remove all_revs=False params (it is the default)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 938
diff changeset
1157 revs = flaskg.storage.documents(wikiname=app.cfg.interwikiname)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 839
diff changeset
1158 for rev in revs:
2272
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1159 existing |= set(rev.fqnames)
852
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 839
diff changeset
1160 linked.update(rev.meta.get(ITEMLINKS, []))
5ad4ae0b1e09 lots of fixes / adaptions for storage-ng code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 839
diff changeset
1161 transcluded.update(rev.meta.get(ITEMTRANSCLUSIONS, []))
2272
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1162 return existing, set(split_fqname_list(linked)), set(split_fqname_list(transcluded))
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1163
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1164
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1165 def split_fqname_list(names):
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1166 """
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1167 Converts a list of names to a list of fqnames.
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1168 """
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1169 return [split_fqname(name) for name in 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
1170
792
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1171
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1172 @frontend.route('/+wanteds')
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1173 def wanted_items():
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1174 """
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1175 Returns a list view of non-existing items that are linked to or
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1176 transcluded by other items. If you want to know by which items they are
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1177 referred to, use the backrefs functionality of the item in question.
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1178 """
793
328d83e165a4 whooshify _compute_item_sets (used for wanteds/orphans view)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 792
diff changeset
1179 existing, linked, transcluded = _compute_item_sets()
792
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1180 referred = linked | transcluded
793
328d83e165a4 whooshify _compute_item_sets (used for wanteds/orphans view)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 792
diff changeset
1181 wanteds = referred - existing
1013
57f6267eb050 title display: add some more, make it more consistent
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1007
diff changeset
1182 title_name = _(u'Wanted Items')
1870
e03714644b0f fix for 289 orphans, mychanges, wanteds, tags/tagname incorrectly show item views panel/bar
Roger Haase <crosseyedpenguin@yahoo.com>
parents: 1853
diff changeset
1183 return render_template('link_list_no_item_panel.html',
792
911ccaa08db6 refactor wanteds/orphans - do same stuff much simpler
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 791
diff changeset
1184 headline=_(u'Wanted Items'),
1013
57f6267eb050 title display: add some more, make it more consistent
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1007
diff changeset
1185 title_name=title_name,
2272
b1c0a532235d Added fqname support to wanteds and orphans view.
Ashutosh Singla <ashu1461@gmail.com>
parents: 2271
diff changeset
1186 fq_names=wanteds)
0
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: