forked from AFPy/afpy.org
Ajout d'une interface d'administration
This commit is contained in:
parent
2fe3e841a0
commit
87a2fcd980
36
afpy.py
36
afpy.py
|
@ -93,7 +93,7 @@ def rest(name):
|
|||
|
||||
|
||||
@app.route('/post/edit/<name>')
|
||||
@app.route('/post/edit/<name>/<timestamp>')
|
||||
@app.route('/admin/post/edit/<name>/<timestamp>')
|
||||
def edit_post(name, timestamp=None):
|
||||
if name not in POSTS:
|
||||
abort(404)
|
||||
|
@ -115,7 +115,7 @@ def edit_post(name, timestamp=None):
|
|||
|
||||
|
||||
@app.route('/post/edit/<name>', methods=['post'])
|
||||
@app.route('/post/edit/<name>/<timestamp>', methods=['post'])
|
||||
@app.route('/admin/post/edit/<name>/<timestamp>', methods=['post'])
|
||||
def save_post(name, timestamp=None):
|
||||
original_timestamp = timestamp
|
||||
if name not in POSTS:
|
||||
|
@ -141,14 +141,15 @@ def save_post(name, timestamp=None):
|
|||
element.text = email.utils.formatdate(
|
||||
int(timestamp) if timestamp else time.time())
|
||||
ElementTree.ElementTree(tree).write(post)
|
||||
if 'publish' in request.form and status == 'waiting':
|
||||
(root / name / 'waiting' / timestamp).rename(
|
||||
root / name / 'published' / timestamp)
|
||||
elif 'unpublish' in request.form and status == 'published':
|
||||
(root / name / 'published' / timestamp).rename(
|
||||
root / name / 'waiting' / timestamp)
|
||||
return redirect(
|
||||
'/' if original_timestamp else url_for('rest', name='confirmation'))
|
||||
if original_timestamp:
|
||||
if 'publish' in request.form and status == 'waiting':
|
||||
(root / name / 'waiting' / timestamp).rename(
|
||||
root / name / 'published' / timestamp)
|
||||
elif 'unpublish' in request.form and status == 'published':
|
||||
(root / name / 'published' / timestamp).rename(
|
||||
root / name / 'waiting' / timestamp)
|
||||
return redirect(url_for('admin'))
|
||||
return redirect(url_for('rest', name='confirmation'))
|
||||
|
||||
|
||||
@app.route('/posts/<name>')
|
||||
|
@ -165,6 +166,21 @@ def posts(name):
|
|||
'posts.html', body_id=name, posts=posts, title=POSTS[name], name=name)
|
||||
|
||||
|
||||
@app.route('/admin/posts')
|
||||
def admin():
|
||||
posts = {}
|
||||
for name, label in POSTS.items():
|
||||
posts[(name, label)] = name_posts = {}
|
||||
for state in ('waiting', 'published'):
|
||||
name_posts[state] = state_posts = {}
|
||||
timestamps = sorted((root / name / state).iterdir(), reverse=True)
|
||||
for timestamp in timestamps:
|
||||
tree = ElementTree.parse(timestamp / 'post.xml')
|
||||
state_posts[timestamp.name] = {
|
||||
item.tag: item.text for item in tree.iter()}
|
||||
return render_template('admin.html', body_id='admin', posts=posts)
|
||||
|
||||
|
||||
@app.route('/posts/<name>/<timestamp>')
|
||||
def post(name, timestamp):
|
||||
if name not in POSTS:
|
||||
|
|
|
@ -63,11 +63,21 @@ code
|
|||
display: block
|
||||
padding: 2em
|
||||
|
||||
table
|
||||
border-collapse: collapse
|
||||
margin: 1em 0
|
||||
|
||||
thead, tr:nth-child(even)
|
||||
background: $header
|
||||
|
||||
td, th
|
||||
padding: 0.3em 1em
|
||||
|
||||
iframe
|
||||
background: $text
|
||||
border: 0
|
||||
height: 55em
|
||||
width: 100%
|
||||
background: $text
|
||||
border: 0
|
||||
height: 55em
|
||||
width: 100%
|
||||
|
||||
body
|
||||
background: $bkg
|
||||
|
@ -128,6 +138,9 @@ main
|
|||
padding: 0 1em
|
||||
width: 100%
|
||||
|
||||
aside
|
||||
width: 100%
|
||||
|
||||
footer
|
||||
background: $header
|
||||
box-sizing: border-box
|
||||
|
|
|
@ -53,6 +53,14 @@ code {
|
|||
display: block;
|
||||
padding: 2em; }
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 1em 0; }
|
||||
table thead, table tr:nth-child(even) {
|
||||
background: #1d1e23; }
|
||||
table td, table th {
|
||||
padding: 0.3em 1em; }
|
||||
|
||||
iframe {
|
||||
background: #eaeaea;
|
||||
border: 0;
|
||||
|
@ -112,6 +120,9 @@ main {
|
|||
padding: 0 1em;
|
||||
width: 100%; }
|
||||
|
||||
aside {
|
||||
width: 100%; }
|
||||
|
||||
footer {
|
||||
background: #1d1e23;
|
||||
box-sizing: border-box;
|
||||
|
|
|
@ -53,6 +53,9 @@
|
|||
<li>
|
||||
<a href="{{ url_for('rest', name='rss') }}">Flux RSS</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{{ url_for('admin') }}">Administration</a>
|
||||
</li>
|
||||
</ul>
|
||||
</footer>
|
||||
</body>
|
||||
|
|
39
templates/admin.html
Normal file
39
templates/admin.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{% extends '_layout.jinja2' %}
|
||||
|
||||
{% block header %}
|
||||
<h1>Administration</h1>
|
||||
{% endblock header %}
|
||||
|
||||
{% block main %}
|
||||
{% for (name, label), states in posts.items() %}
|
||||
<article>
|
||||
<h2>{{ label }}</h2>
|
||||
{% for state, timestamps in states.items() %}
|
||||
{% set state_label = 'En attente' if state == 'waiting' else 'Publiés' %}
|
||||
<h3>{{ state_label }}</h3>
|
||||
{% if timestamps %}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for timestamp, post in timestamps.items() %}
|
||||
<tr>
|
||||
<td>{{ post.title }}</td>
|
||||
<td>{{ post.pubDate | parse_rfc822_datetime | datetime('%x') }}</td>
|
||||
<td><a href="{{ url_for('edit_post', name=name, timestamp=timestamp) }}">Éditer</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>Aucun article dans la catégorie « {{ label }} / {{ state_label }} »</p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</article>
|
||||
{% endfor %}
|
||||
{% endblock main %}
|
Loading…
Reference in New Issue
Block a user