Commit f89f33fd authored by Serge S. Koval's avatar Serge S. Koval

File admin, use POST to delete models/files.

parent 18b3c956
- Core
- Right-side menu items (auth?)
- Pregenerate URLs for menu
- Conditional js include for forms or pages
- Flask app in constructor
- Calendar - add validation for time without seconds (automatically add seconds)
- Model Admin
- Ability to sort by fields that are not visible?
- SQLA Model Admin
......@@ -12,5 +12,6 @@
- Many2Many support
- WYSIWYG editor support
- File admin
- Documentation
- Header title
- Mass-delete functionality
- Unit tests
import os
import os.path as op
from flask import Flask
from flask.ext import adminex
from flask.ext.adminex.ext import fileadmin
# Create flask app
app = Flask(__name__, template_folder='templates', static_folder='files')
# Create dummy secrey key so we can use flash
app.config['SECRET_KEY'] = '123456790'
# Flask views
@app.route('/')
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
if __name__ == '__main__':
# Create directory
path = op.join(op.dirname(__file__), 'files')
try:
os.mkdir(path)
except OSError:
pass
# Create admin interface
admin = adminex.Admin()
admin.add_view(fileadmin.FileAdmin(path, '/files/', name='Files'))
admin.setup_app(app)
# Start app
app.debug = True
app.run()
......@@ -23,7 +23,6 @@ class AnotherAdminView(adminex.BaseView):
# Create flask app
app = Flask(__name__, template_folder='templates')
# Flask views
@app.route('/')
def index():
......
This diff is collapsed.
......@@ -34,8 +34,6 @@ class AdminModelConverter(ModelConverter):
'default': None
}
print prop, kwargs, local_column
if field_args:
kwargs.update(field_args)
......
......@@ -494,10 +494,10 @@ class BaseModelView(BaseView):
form=form,
return_url=return_url or url_for('.index_view'))
@expose('/delete/<int:id>/')
@expose('/delete/<int:id>/', methods=('POST',))
def delete_view(self, id):
"""
Delete model view
Delete model view. Only POST method is allowed.
"""
return_url = request.args.get('return')
......
......@@ -3,3 +3,19 @@ body
{
padding-top: 50px;
}
form.icon {
display: inline;
}
form.icon button {
border: none;
background: transparent;
text-decoration: none;
padding: 0;
line-height: normal;
}
a.icon {
text-decoration: none;
}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib %}
{% block body %}
{{ lib.render_form(form, dir_url) }}
{% endblock %}
\ No newline at end of file
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib %}
{% block body %}
<ul class="breadcrumb">
<li>
<a href="{{ get_dir_url('.index', path=None) }}">Root</a>
</li>
{% for name, path in breadcrumbs[:-1] %}
<li>
<span class="divider">/</span><a href="{{ get_dir_url('.index', path=path) }}">{{ name }}</a>
</li>
{% endfor %}
{% if breadcrumbs %}
<li>
<span class="divider">/</span><a href="{{ get_dir_url('.index', path=breadcrumbs[-1][1]) }}">{{ breadcrumbs[-1][0] }}</a>
</li>
{% endif %}
</ul>
<table class="table table-striped table-bordered model-list">
<thead>
<tr>
<th class="span1">&nbsp;</th>
<th>Name</th>
<th>Size</th>
</tr>
</thead>
{% for name, path, is_dir, size in items %}
<tr>
<td>
{% if admin_view.can_rename and path and name != '..' %}
<a class="icon" href="{{ url_for('.rename', path=path) }}">
<i class="icon-pencil"></i>
</a>
{% endif %}
{%- if admin_view.can_delete and path -%}
{% if is_dir %}
{% if name != '..' %}
<form class="icon" method="POST" action="{{ url_for('.delete') }}">
<input type="hidden" name="path" value="{{ path }}"></input>
<button onclick="return confirm('Are you sure you want to delete \'{{ name }}\' recursively?')">
<i class="icon-remove"></i>
</button>
</form>
{% endif %}
{% else %}
<form class="icon" method="POST" action="{{ url_for('.delete') }}">
<input type="hidden" name="path" value="{{ path }}"></input>
<button onclick="return confirm('Are you sure you want to delete \'{{ name }}\'?')">
<i class="icon-remove"></i>
</button>
</form>
{% endif %}
{%- endif -%}
</td>
{% if is_dir %}
<td colspan="2">
<a href="{{ get_dir_url('.index', path)|safe }}">
<i class="icon-folder-close"></i> <span>{{ name }}</span>
</a>
</td>
{% else %}
<td>
<a href="{{ get_file_url(path)|safe }}">{{ name }}</a>
</td>
<td>
{{ size }}
</td>
{% endif %}
</tr>
{% endfor %}
</table>
{% if admin_view.can_upload %}
<a class="btn btn-primary btn-large" href="{{ get_dir_url('.upload', path=dir_path) }}">Upload File</a>
{% endif %}
{% if admin_view.can_mkdir %}
<a class="btn btn-primary btn-large" href="{{ get_dir_url('.mkdir', path=dir_path) }}">Create Directory</a>
{% endif %}
{% endblock %}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib %}
{% block body %}
<h3>Please provide new name for <i>{{ name }}</i></h3>
{{ lib.render_form(form, dir_url) }}
{% endblock %}
\ No newline at end of file
......@@ -72,3 +72,42 @@
</div>
{% endif %}
{%- endmacro %}
{% macro render_form(form, cancel_url) -%}
<form action="" method="POST" class="form-horizontal"{% if form.has_file_field %} enctype="multipart/form-data"{% endif %}>
<fieldset>
{{ form.csrf }}
{% for f in form if f.label.text != 'Csrf' %}
<div class="control-group{% if f.errors %} error{% endif %}">
{{ f.label(class='control-label') }}
<div class="controls">
<div>
{% if not focus_set %}
{{ f(autofocus='autofocus') }}
{% set focus_set = True %}
{% else %}
{{ f() }}
{% endif %}
</div>
{% if f.errors %}
<ul>
{% for e in f.errors %}
<li>{{ e }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endfor %}
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-primary btn-large" />
{% if cancel_url %}
<a href="{{ cancel_url }}" class="btn btn-large">Cancel</a>
{% endif %}
</div>
</div>
</fieldset>
</form>
{% endmacro %}
{% extends 'admin/master.html' %}
{% import 'admin/lib.html' as lib %}
{% block head %}
<link href="{{ url_for('admin.static', filename='chosen/chosen.css') }}" rel="stylesheet">
......@@ -6,35 +7,7 @@
{% endblock %}
{% block body %}
<form action="" method="POST" class="form-horizontal"{% if form.has_file_field %} enctype="multipart/form-data"{% endif %}>
<fieldset>
{{ form.csrf }}
{% for f in form if f.label.text != 'Csrf' %}
<div class="control-group{% if f.errors %} error{% endif %}">
{{ f.label(class='control-label') }}
<div class="controls">
<div>
{{ f }}
</div>
{% if f.errors %}
<ul>
{% for e in f.errors %}
<li>{{ e }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endfor %}
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-primary btn-large" />
<a href="{{ return_url }}" class="btn btn-large">Cancel</a>
</div>
</div>
</fieldset>
</form>
{{ lib.render_form(form, return_url) }}
{% endblock %}
{% block tail %}
......
......@@ -34,14 +34,16 @@
<tr>
<td>
{%- if admin_view.can_edit -%}
<a href="{{ url_for('.edit_view', id=row.id, return=return_url) }}">
<a class="icon" href="{{ url_for('.edit_view', id=row.id, return=return_url) }}">
<i class="icon-pencil"></i>
</a>
{%- endif -%}
{%- if admin_view.can_delete -%}
<a href="{{ url_for('.delete_view', id=row.id, return=return_url) }}" onclick="return confirm('You sure you want to delete this item?')">
<form class="icon" method="POST" action="{{ url_for('.delete_view', id=row.id, return=return_url) }}">
<button onclick="return confirm('You sure you want to delete this item?')">
<i class="icon-remove"></i>
</a>
</button>
</form>
{%- endif -%}
</td>
{% for c, name in list_columns %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment