prompt
large_stringlengths 72
9.34k
| completion
large_stringlengths 0
7.61k
|
---|---|
<|file_name|>feed_parse_extractLittlebambooHomeBlog.py<|end_file_name|><|fim▁begin|>def extractLittlebambooHomeBlog(item):
'''
Parser for 'littlebamboo.home.blog'
'''
vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title'])
if not (chp or vol) or "preview" in item['title'].lower():
<|fim_middle|>
tagmap = [
('FW', 'Fortunate Wife', 'translated'),
('PRC', 'PRC', 'translated'),
('Loiterous', 'Loiterous', 'oel'),
]
for tagname, name, tl_type in tagmap:
if tagname in item['tags']:
return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type)
return False<|fim▁end|> | return None |
<|file_name|>feed_parse_extractLittlebambooHomeBlog.py<|end_file_name|><|fim▁begin|>def extractLittlebambooHomeBlog(item):
'''
Parser for 'littlebamboo.home.blog'
'''
vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title'])
if not (chp or vol) or "preview" in item['title'].lower():
return None
tagmap = [
('FW', 'Fortunate Wife', 'translated'),
('PRC', 'PRC', 'translated'),
('Loiterous', 'Loiterous', 'oel'),
]
for tagname, name, tl_type in tagmap:
if tagname in item['tags']:
<|fim_middle|>
return False<|fim▁end|> | return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type) |
<|file_name|>feed_parse_extractLittlebambooHomeBlog.py<|end_file_name|><|fim▁begin|>def <|fim_middle|>(item):
'''
Parser for 'littlebamboo.home.blog'
'''
vol, chp, frag, postfix = extractVolChapterFragmentPostfix(item['title'])
if not (chp or vol) or "preview" in item['title'].lower():
return None
tagmap = [
('FW', 'Fortunate Wife', 'translated'),
('PRC', 'PRC', 'translated'),
('Loiterous', 'Loiterous', 'oel'),
]
for tagname, name, tl_type in tagmap:
if tagname in item['tags']:
return buildReleaseMessageWithType(item, name, vol, chp, frag=frag, postfix=postfix, tl_type=tl_type)
return False<|fim▁end|> | extractLittlebambooHomeBlog |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")<|fim▁hole|>
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))<|fim▁end|> |
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
<|fim_middle|>
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
<|fim_middle|>
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
<|fim_middle|>
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
<|fim_middle|>
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
<|fim_middle|>
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials')) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
<|fim_middle|>
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={}) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
<|fim_middle|>
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2] |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
<|fim_middle|>
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
<|fim_middle|>
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
<|fim_middle|>
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
<|fim_middle|>
<|fim▁end|> | if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname)) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
<|fim_middle|>
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return current_app.login_manager.unauthorized() |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
<|fim_middle|>
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | abort(404) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
<|fim_middle|>
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return current_app.login_manager.unauthorized() |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
<|fim_middle|>
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Anonymous posting not allowed"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
<|fim_middle|>
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Page is locked"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
<|fim_middle|>
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | flash("Page reverted") |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
<|fim_middle|>
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return current_app.login_manager.unauthorized() |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
<|fim_middle|>
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return redirect(url_for('wiki.create', name=cname)) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
<|fim_middle|>
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return redirect(url_for('wiki.edit', name=cname)) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
<|fim_middle|>
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return parts[-2] |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
<|fim_middle|>
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | for item in items:
yield dict(item, dir=False) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
<|fim_middle|>
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
<|fim_middle|>
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return current_app.login_manager.unauthorized() |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
<|fim_middle|>
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | path = to_canonical(path) + "/" |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
<|fim_middle|>
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Invalid name") |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
<|fim_middle|>
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Anonymous posting not allowed"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
<|fim_middle|>
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
<|fim_middle|>
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Page is locked"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
<|fim_middle|>
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
<|fim_middle|>
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Page is locked"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
<|fim_middle|>
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | g.current_wiki.rename_page(cname, edit_cname) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
<|fim_middle|>
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
<|fim_middle|>
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return dict(error=True, message="Page is locked"), 403 |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
<|fim_middle|>
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return current_app.login_manager.unauthorized() |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
<|fim_middle|>
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return redirect(url_for('wiki.page', name=cname)) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
<|fim_middle|>
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials')) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
<|fim_middle|>
<|fim▁end|> | return redirect(url_for('wiki.create', name=cname)) |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def <|fim_middle|>(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | commit |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def <|fim_middle|>(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | compare |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def <|fim_middle|>():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | revert |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def <|fim_middle|>(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | history |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def <|fim_middle|>(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | edit |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def <|fim_middle|>(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | create |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def <|fim_middle|>(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | _get_subdir |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def <|fim_middle|>(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | _tree_index |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def <|fim_middle|>(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | index |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def <|fim_middle|>(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | page_write |
<|file_name|>views.py<|end_file_name|><|fim▁begin|>import itertools
import sys
from flask import abort, g, render_template, request, redirect, Blueprint, flash, url_for, current_app
from flask.ext.login import login_required, current_user
from realms.lib.util import to_canonical, remove_ext, gravatar_url
from .models import PageNotFound
blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<path:name>")
def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha)
if not data:
abort(404)
return render_template('wiki/page.html', name=name, page=data, commit=sha)
@blueprint.route(r"/_compare/<path:name>/<regex('\w+'):fsha><regex('\.{2,3}'):dots><regex('\w+'):lsha>")
def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha)
@blueprint.route("/_revert", methods=['POST'])
@login_required
def revert():
cname = to_canonical(request.form.get('name'))
commit = request.form.get('commit')
message = request.form.get('message', "Reverting %s" % cname)
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
try:
sha = g.current_wiki.revert_page(cname,
commit,
message=message,
username=current_user.username,
email=current_user.email)
except PageNotFound as e:
return dict(error=True, message=e.message), 404
if sha:
flash("Page reverted")
return dict(sha=sha)
@blueprint.route("/_history/<path:name>")
def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
hist = g.current_wiki.get_history(name)
for item in hist:
item['gravatar'] = gravatar_url(item['author_email'])
return render_template('wiki/history.html', name=name, history=hist)
@blueprint.route("/_edit/<path:name>")
@login_required
def edit(name):
cname = to_canonical(name)
page = g.current_wiki.get_page(name)
if not page:
# Page doesn't exist
return redirect(url_for('wiki.create', name=cname))
name = remove_ext(page['path'])
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=name,
content=page.get('data'),
info=page.get('info'),
sha=page.get('sha'),
partials=page.get('partials'))
@blueprint.route("/_create/", defaults={'name': None})
@blueprint.route("/_create/<path:name>")
@login_required
def create(name):
cname = to_canonical(name) if name else ""
if cname and g.current_wiki.get_page(cname):
# Page exists, edit instead
return redirect(url_for('wiki.edit', name=cname))
g.assets['js'].append('editor.js')
return render_template('wiki/edit.html',
name=cname,
content="",
info={})
def _get_subdir(path, depth):
parts = path.split('/', depth)
if len(parts) > depth:
return parts[-2]
def _tree_index(items, path=""):
depth = len(path.split("/"))
items = filter(lambda x: x['name'].startswith(path), items)
items = sorted(items, key=lambda x: x['name'])
for subdir, items in itertools.groupby(items, key=lambda x: _get_subdir(x['name'], depth)):
if not subdir:
for item in items:
yield dict(item, dir=False)
else:
size = 0
ctime = sys.maxint
mtime = 0
for item in items:
size += item['size']
ctime = min(item['ctime'], ctime)
mtime = max(item['mtime'], mtime)
yield dict(name=path + subdir + "/",
mtime=mtime,
ctime=ctime,
size=size,
dir=True)
@blueprint.route("/_index", defaults={"path": ""})
@blueprint.route("/_index/<path:path>")
def index(path):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
items = g.current_wiki.get_index()
if path:
path = to_canonical(path) + "/"
return render_template('wiki/index.html', index=_tree_index(items, path=path), path=path)
@blueprint.route("/<path:name>", methods=['POST', 'PUT', 'DELETE'])
@login_required
def page_write(name):
cname = to_canonical(name)
if not cname:
return dict(error=True, message="Invalid name")
if not current_app.config.get('ALLOW_ANON') and current_user.is_anonymous():
return dict(error=True, message="Anonymous posting not allowed"), 403
if request.method == 'POST':
# Create
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.write_page(cname,
request.form['content'],
message=request.form['message'],
create=True,
username=current_user.username,
email=current_user.email)
elif request.method == 'PUT':
edit_cname = to_canonical(request.form['name'])
if edit_cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
if edit_cname != cname:
g.current_wiki.rename_page(cname, edit_cname)
sha = g.current_wiki.write_page(edit_cname,
request.form['content'],
message=request.form['message'],
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
elif request.method == 'DELETE':
# DELETE
if cname in current_app.config.get('WIKI_LOCKED_PAGES'):
return dict(error=True, message="Page is locked"), 403
sha = g.current_wiki.delete_page(cname,
username=current_user.username,
email=current_user.email)
return dict(sha=sha)
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<path:name>")
def <|fim_middle|>(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name)
if cname != name:
return redirect(url_for('wiki.page', name=cname))
data = g.current_wiki.get_page(cname)
if data:
return render_template('wiki/page.html', name=cname, page=data, partials=data.get('partials'))
else:
return redirect(url_for('wiki.create', name=cname))
<|fim▁end|> | page |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')<|fim▁hole|> def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))<|fim▁end|> |
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
|
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
<|fim_middle|>
<|fim▁end|> | def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a')) |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
<|fim_middle|>
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | self.assertEqual(string_color('Jack'), '79CAE5') |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
<|fim_middle|>
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | self.assertEqual(string_color('Joshua'), '6A10D6') |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
<|fim_middle|>
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | self.assertEqual(string_color('Joshua Smith'), '8F00FB') |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
<|fim_middle|>
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | self.assertEqual(string_color('Hayden Smith'), '7E00EE') |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
<|fim_middle|>
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | self.assertEqual(string_color('Mathew Smith'), '8B00F1') |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
<|fim_middle|>
<|fim▁end|> | self.assertIsNone(string_color('a')) |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def <|fim_middle|>(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_equal_1 |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def <|fim_middle|>(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_equal_2 |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def <|fim_middle|>(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_equal_3 |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def <|fim_middle|>(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_equal_4 |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def <|fim_middle|>(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def test_is_none_1(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_equal_5 |
<|file_name|>test_what_color_is_your_name.py<|end_file_name|><|fim▁begin|>import unittest
from katas.beta.what_color_is_your_name import string_color
class StringColorTestCase(unittest.TestCase):
def test_equal_1(self):
self.assertEqual(string_color('Jack'), '79CAE5')
def test_equal_2(self):
self.assertEqual(string_color('Joshua'), '6A10D6')
def test_equal_3(self):
self.assertEqual(string_color('Joshua Smith'), '8F00FB')
def test_equal_4(self):
self.assertEqual(string_color('Hayden Smith'), '7E00EE')
def test_equal_5(self):
self.assertEqual(string_color('Mathew Smith'), '8B00F1')
def <|fim_middle|>(self):
self.assertIsNone(string_color('a'))
<|fim▁end|> | test_is_none_1 |
<|file_name|>__init__.py<|end_file_name|><|fim▁begin|><|fim▁hole|>from ga_starters import *<|fim▁end|> | |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200<|fim▁hole|> sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json()
if __name__ == "__main__":
main()<|fim▁end|> | url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
<|fim_middle|>
if __name__ == "__main__":
main()
<|fim▁end|> | argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json() |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
<|fim_middle|>
elif state == 'absent':
aci.delete_config()
aci.exit_json()
if __name__ == "__main__":
main()
<|fim▁end|> | aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config() |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config()
elif state == 'absent':
<|fim_middle|>
aci.exit_json()
if __name__ == "__main__":
main()
<|fim▁end|> | aci.delete_config() |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def main():
argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json()
if __name__ == "__main__":
<|fim_middle|>
<|fim▁end|> | main() |
<|file_name|>aci_tenant_span_dst_group.py<|end_file_name|><|fim▁begin|>#!/usr/bin/python
# -*- coding: utf-8 -*-
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = r'''
---
module: aci_tenant_span_dst_group
short_description: Manage SPAN destination groups (span:DestGrp)
description:
- Manage SPAN destination groups on Cisco ACI fabrics.
notes:
- The C(tenant) used must exist before using this module in your playbook.
The M(aci_tenant) module can be used for this.
- More information about the internal APIC class B(span:DestGrp) from
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
author:
- Dag Wieers (@dagwieers)
version_added: '2.4'
options:
dst_group:
description:
- The name of the SPAN destination group.
required: yes
aliases: [ name ]
description:
description:
- The description of the SPAN destination group.
aliases: [ descr ]
tenant:
description:
- The name of the tenant.
required: yes
aliases: [ tenant_name ]
state:
description:
- Use C(present) or C(absent) for adding or removing.
- Use C(query) for listing an object or multiple objects.
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: aci
'''
# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_tenant_span_dst_group:
host: apic
username: admin
password: SomeSecretPassword
dst_group: '{{ dst_group }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
'''
RETURN = r'''
current:
description: The existing configuration from the APIC after the module has finished
returned: success
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
error:
description: The error information as returned from the APIC
returned: failure
type: dict
sample:
{
"code": "122",
"text": "unknown managed object class foo"
}
raw:
description: The raw output returned by the APIC REST API (xml or json)
returned: parse error
type: string
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
sent:
description: The actual/minimal configuration pushed to the APIC
returned: info
type: list
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment"
}
}
}
previous:
description: The original configuration from the APIC before the module has started
returned: info
type: list
sample:
[
{
"fvTenant": {
"attributes": {
"descr": "Production",
"dn": "uni/tn-production",
"name": "production",
"nameAlias": "",
"ownerKey": "",
"ownerTag": ""
}
}
}
]
proposed:
description: The assembled configuration from the user-provided parameters
returned: info
type: dict
sample:
{
"fvTenant": {
"attributes": {
"descr": "Production environment",
"name": "production"
}
}
}
filter_string:
description: The filter string used for the request
returned: failure or debug
type: string
sample: ?rsp-prop-include=config-only
method:
description: The HTTP method used for the request to the APIC
returned: failure or debug
type: string
sample: POST
response:
description: The HTTP response from the APIC
returned: failure or debug
type: string
sample: OK (30 bytes)
status:
description: The HTTP status from the APIC
returned: failure or debug
type: int
sample: 200
url:
description: The HTTP url used for the request to the APIC
returned: failure or debug
type: string
sample: https://10.11.12.13/api/mo/uni/tn-production.json
'''
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
from ansible.module_utils.basic import AnsibleModule
def <|fim_middle|>():
argument_spec = aci_argument_spec()
argument_spec.update(
dst_group=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['dst_group', 'tenant']],
['state', 'present', ['dst_group', 'tenant']],
],
)
dst_group = module.params['dst_group']
description = module.params['description']
state = module.params['state']
tenant = module.params['tenant']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fvTenant',
aci_rn='tn-{0}'.format(tenant),
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
module_object=tenant,
),
subclass_1=dict(
aci_class='spanDestGrp',
aci_rn='destgrp-{0}'.format(dst_group),
filter_target='eq(spanDestGrp.name, "{0}")'.format(dst_group),
module_object=dst_group,
),
)
aci.get_existing()
if state == 'present':
aci.payload(
aci_class='spanDestGrp',
class_config=dict(
name=dst_group,
descr=description,
),
)
aci.get_diff(aci_class='spanDestGrp')
aci.post_config()
elif state == 'absent':
aci.delete_config()
aci.exit_json()
if __name__ == "__main__":
main()
<|fim▁end|> | main |
<|file_name|>aiplatform_v1_generated_vizier_service_delete_study_sync.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated code. DO NOT EDIT!
#
# Snippet for DeleteStudy
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.
# To install the latest published package dependency, execute the following:
# python3 -m pip install google-cloud-aiplatform
# [START aiplatform_v1_generated_VizierService_DeleteStudy_sync]
from google.cloud import aiplatform_v1
def sample_delete_study():<|fim▁hole|> # Initialize request argument(s)
request = aiplatform_v1.DeleteStudyRequest(
name="name_value",
)
# Make the request
client.delete_study(request=request)
# [END aiplatform_v1_generated_VizierService_DeleteStudy_sync]<|fim▁end|> | # Create a client
client = aiplatform_v1.VizierServiceClient()
|
<|file_name|>aiplatform_v1_generated_vizier_service_delete_study_sync.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated code. DO NOT EDIT!
#
# Snippet for DeleteStudy
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.
# To install the latest published package dependency, execute the following:
# python3 -m pip install google-cloud-aiplatform
# [START aiplatform_v1_generated_VizierService_DeleteStudy_sync]
from google.cloud import aiplatform_v1
def sample_delete_study():
# Create a client
<|fim_middle|>
# [END aiplatform_v1_generated_VizierService_DeleteStudy_sync]
<|fim▁end|> | client = aiplatform_v1.VizierServiceClient()
# Initialize request argument(s)
request = aiplatform_v1.DeleteStudyRequest(
name="name_value",
)
# Make the request
client.delete_study(request=request) |
<|file_name|>aiplatform_v1_generated_vizier_service_delete_study_sync.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated code. DO NOT EDIT!
#
# Snippet for DeleteStudy
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.
# To install the latest published package dependency, execute the following:
# python3 -m pip install google-cloud-aiplatform
# [START aiplatform_v1_generated_VizierService_DeleteStudy_sync]
from google.cloud import aiplatform_v1
def <|fim_middle|>():
# Create a client
client = aiplatform_v1.VizierServiceClient()
# Initialize request argument(s)
request = aiplatform_v1.DeleteStudyRequest(
name="name_value",
)
# Make the request
client.delete_study(request=request)
# [END aiplatform_v1_generated_VizierService_DeleteStudy_sync]
<|fim▁end|> | sample_delete_study |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'App.created_at'
db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Deleting field 'App.created_at'
db.delete_column('mobile_apps_app', 'created_at')
<|fim▁hole|> 'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps']<|fim▁end|> | models = {
'core.level': { |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
<|fim_middle|>
<|fim▁end|> | def forwards(self, orm):
# Adding field 'App.created_at'
db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Deleting field 'App.created_at'
db.delete_column('mobile_apps_app', 'created_at')
models = {
'core.level': {
'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps'] |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'App.created_at'
<|fim_middle|>
def backwards(self, orm):
# Deleting field 'App.created_at'
db.delete_column('mobile_apps_app', 'created_at')
models = {
'core.level': {
'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps']
<|fim▁end|> | db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False) |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'App.created_at'
db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Deleting field 'App.created_at'
<|fim_middle|>
models = {
'core.level': {
'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps']
<|fim▁end|> | db.delete_column('mobile_apps_app', 'created_at') |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def <|fim_middle|>(self, orm):
# Adding field 'App.created_at'
db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
def backwards(self, orm):
# Deleting field 'App.created_at'
db.delete_column('mobile_apps_app', 'created_at')
models = {
'core.level': {
'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps']
<|fim▁end|> | forwards |
<|file_name|>0002_auto__add_field_app_created_at.py<|end_file_name|><|fim▁begin|># encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'App.created_at'
db.add_column('mobile_apps_app', 'created_at', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
def <|fim_middle|>(self, orm):
# Deleting field 'App.created_at'
db.delete_column('mobile_apps_app', 'created_at')
models = {
'core.level': {
'Meta': {'ordering': "['order']", 'object_name': 'Level'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.CharField', [], {'max_length': '45'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '25'}),
'order': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
},
'mobile_apps.app': {
'Meta': {'object_name': 'App'},
'content_areas': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_areas'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'cost': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '2', 'blank': 'True'}),
'created_at': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'levels': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'levels'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['core.Level']"}),
'link': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
'type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mobile_apps.Type']"})
},
'mobile_apps.type': {
'Meta': {'object_name': 'Type'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
}
}
complete_apps = ['mobile_apps']
<|fim▁end|> | backwards |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')<|fim▁hole|> op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###<|fim▁end|> | op.drop_column('file_type', 'created_at') |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
<|fim_middle|>
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | globals()["upgrade_%s" % engine_name]() |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
<|fim_middle|>
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | globals()["downgrade_%s" % engine_name]() |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
<|fim_middle|>
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ### |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
<|fim_middle|>
<|fim▁end|> | op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ### |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def <|fim_middle|>(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | upgrade |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def <|fim_middle|>(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | downgrade |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def <|fim_middle|>():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def downgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | upgrade_validation |
<|file_name|>c0a714ade734_adding_timestamps_to_all_tables.py<|end_file_name|><|fim▁begin|>"""adding timestamps to all tables
Revision ID: c0a714ade734
Revises: 1a886e694fca
Create Date: 2016-04-20 14:46:06.407765
"""
# revision identifiers, used by Alembic.
revision = 'c0a714ade734'
down_revision = '1a886e694fca'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_validation():
### commands auto generated by Alembic - please adjust! ###
op.add_column('field_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('field_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_columns', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('file_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('multi_field_rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_timing', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('rule_type', sa.Column('updated_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('created_at', sa.DateTime(), nullable=True))
op.add_column('tas_lookup', sa.Column('updated_at', sa.DateTime(), nullable=True))
### end Alembic commands ###
def <|fim_middle|>():
### commands auto generated by Alembic - please adjust! ###
op.drop_column('tas_lookup', 'updated_at')
op.drop_column('tas_lookup', 'created_at')
op.drop_column('rule_type', 'updated_at')
op.drop_column('rule_type', 'created_at')
op.drop_column('rule_timing', 'updated_at')
op.drop_column('rule_timing', 'created_at')
op.drop_column('rule', 'updated_at')
op.drop_column('rule', 'created_at')
op.drop_column('multi_field_rule_type', 'updated_at')
op.drop_column('multi_field_rule_type', 'created_at')
op.drop_column('multi_field_rule', 'updated_at')
op.drop_column('multi_field_rule', 'created_at')
op.drop_column('file_type', 'updated_at')
op.drop_column('file_type', 'created_at')
op.drop_column('file_columns', 'updated_at')
op.drop_column('file_columns', 'created_at')
op.drop_column('field_type', 'updated_at')
op.drop_column('field_type', 'created_at')
### end Alembic commands ###
<|fim▁end|> | downgrade_validation |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
pass
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),<|fim▁hole|> c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def register():
return Prof1()<|fim▁end|> | dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo() |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
<|fim_middle|>
def register():
return Prof1()
<|fim▁end|> | def __init__(self):
pass
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
) |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
<|fim_middle|>
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def register():
return Prof1()
<|fim▁end|> | pass |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
pass
def get_profile(self, **kwargs):
# ip generator
<|fim_middle|>
def register():
return Prof1()
<|fim▁end|> | ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
) |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
pass
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def register():
<|fim_middle|>
<|fim▁end|> | return Prof1() |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def <|fim_middle|>(self):
pass
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def register():
return Prof1()
<|fim▁end|> | __init__ |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
pass
def <|fim_middle|>(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def register():
return Prof1()
<|fim▁end|> | get_profile |
<|file_name|>param_tcp_rxbufsize_8k.py<|end_file_name|><|fim▁begin|>from trex_astf_lib.api import *
# IPV6 tunable example
#
# ipv6.src_msb
# ipv6.dst_msb
# ipv6.enable
#
class Prof1():
def __init__(self):
pass
def get_profile(self, **kwargs):
# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)
c_glob_info = ASTFGlobalInfo()
c_glob_info.tcp.rxbufsize = 8*1024
c_glob_info.tcp.txbufsize = 8*1024
s_glob_info = ASTFGlobalInfo()
s_glob_info.tcp.rxbufsize = 8*1024
s_glob_info.tcp.txbufsize = 8*1024
return ASTFProfile(default_ip_gen=ip_gen,
# Defaults affects all files
default_c_glob_info=c_glob_info,
default_s_glob_info=s_glob_info,
cap_list=[
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap", cps=1)
]
)
def <|fim_middle|>():
return Prof1()
<|fim▁end|> | register |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.