forked from AFPy/afpy.org
Merge branch 'master' of https://github.com/AFPy/site
This commit is contained in:
commit
6351c467ac
51
afpy.py
51
afpy.py
|
@ -2,7 +2,6 @@ import email
|
|||
import locale
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import docutils.core
|
||||
import docutils.writers.html5_polyglot
|
||||
|
@ -59,12 +58,11 @@ def index():
|
|||
for post in data.get_posts(data.POST_ACTUALITIES, end=4):
|
||||
timestamp = post[data.TIMESTAMP]
|
||||
posts[timestamp] = post
|
||||
if (post[data.DIR] / 'post.jpg').is_file():
|
||||
posts[timestamp]['image'] = '/'.join(
|
||||
(data.POST_ACTUALITIES, data.STATE_PUBLISHED, timestamp)
|
||||
)
|
||||
return render_template(
|
||||
'index.html', body_id='index', name=data.POST_ACTUALITIES, posts=posts
|
||||
'index.html',
|
||||
body_id='index',
|
||||
name=data.POST_ACTUALITIES,
|
||||
posts=posts
|
||||
)
|
||||
|
||||
|
||||
|
@ -90,7 +88,10 @@ def rest(name):
|
|||
except FileNotFoundError:
|
||||
abort(404)
|
||||
return render_template(
|
||||
'rst.html', body_id=name, html=parts['body'], title=parts['title']
|
||||
'rst.html',
|
||||
body_id=name,
|
||||
html=parts['body'],
|
||||
title=parts['title']
|
||||
)
|
||||
|
||||
|
||||
|
@ -128,7 +129,11 @@ def edit_post_admin(name, timestamp):
|
|||
if not post:
|
||||
abort(404)
|
||||
return render_template(
|
||||
'edit_post.html', body_id='edit-post', post=post, name=name, admin=True
|
||||
'edit_post.html',
|
||||
body_id='edit-post',
|
||||
post=post,
|
||||
name=name,
|
||||
admin=True
|
||||
)
|
||||
|
||||
|
||||
|
@ -153,7 +158,10 @@ def save_post(name, token=None):
|
|||
edit_post_url = url_for(
|
||||
'edit_post', name=name, token=signer.dumps(post['_timestamp'])
|
||||
)
|
||||
return render_template('confirmation.html', edit_post_url=edit_post_url)
|
||||
return render_template(
|
||||
'confirmation.html',
|
||||
edit_post_url=edit_post_url
|
||||
)
|
||||
|
||||
|
||||
@app.route('/admin/post/edit/<name>/<timestamp>', methods=['post'])
|
||||
|
@ -185,10 +193,6 @@ def posts(name, page=1):
|
|||
):
|
||||
timestamp = post[data.TIMESTAMP]
|
||||
posts[timestamp] = post
|
||||
if (Path(str(timestamp)) / 'post.jpg').is_file():
|
||||
posts[timestamp]['image'] = '/'.join(
|
||||
(name, data.STATE_PUBLISHED, timestamp)
|
||||
)
|
||||
return render_template(
|
||||
'posts.html',
|
||||
body_id=name,
|
||||
|
@ -226,21 +230,24 @@ def post(name, timestamp):
|
|||
post = data.get_post(name, timestamp, data.STATE_PUBLISHED)
|
||||
if not post:
|
||||
abort(404)
|
||||
if (post[data.DIR] / 'post.jpg').is_file():
|
||||
post['image'] = '/'.join((name, data.STATE_PUBLISHED, timestamp))
|
||||
return render_template('post.html', body_id='post', post=post, name=name)
|
||||
return render_template(
|
||||
'post.html',
|
||||
body_id='post',
|
||||
post=post,
|
||||
name=name
|
||||
)
|
||||
|
||||
|
||||
@app.route('/post_image/<path:path>/post.jpg')
|
||||
@app.route('/post_image/<path:path>')
|
||||
def post_image(path):
|
||||
if path.count('/') != 2:
|
||||
if path.count('/') != 3:
|
||||
abort(404)
|
||||
name, status, timestamp = path.split('/')
|
||||
if name not in data.POSTS:
|
||||
category, state, timestamp, name = path.split('/')
|
||||
if category not in data.POSTS:
|
||||
abort(404)
|
||||
if status not in data.STATES:
|
||||
if state not in data.STATES:
|
||||
abort(404)
|
||||
return send_from_directory(data.root / path, 'post.jpg')
|
||||
return send_from_directory(data.root, path)
|
||||
|
||||
|
||||
@app.route('/feed/<name>/rss.xml')
|
||||
|
|
|
@ -28,6 +28,7 @@ ACTIONS = {
|
|||
ACTION_TRASH: "Supprimer",
|
||||
}
|
||||
|
||||
IMAGE = '_image'
|
||||
TIMESTAMP = '_timestamp'
|
||||
STATE = '_state'
|
||||
PATH = '_path'
|
||||
|
@ -35,6 +36,7 @@ DIR = '_dir'
|
|||
|
||||
BASE_DIR = 'posts'
|
||||
BASE_FILE = 'post.xml'
|
||||
BASE_IMAGE = 'post.jpg'
|
||||
|
||||
|
||||
class DataException(Exception):
|
||||
|
@ -87,7 +89,12 @@ def get_post(category, timestamp, states=None):
|
|||
return None
|
||||
tree = ElementTree.parse(path)
|
||||
post = {item.tag: (item.text or '').strip() for item in tree.iter()}
|
||||
post[TIMESTAMP] = int(timestamp)
|
||||
|
||||
# Calculated fields
|
||||
image = post.get('image') or BASE_IMAGE
|
||||
if (dir / image).is_file():
|
||||
post[IMAGE] = '/'.join((category, state, timestamp, image))
|
||||
post[TIMESTAMP] = timestamp
|
||||
post[STATE] = state
|
||||
post[DIR] = dir
|
||||
post[PATH] = path
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
(url_for('index'), 'index', 'Accueil'),
|
||||
(url_for('rest', name='a-propos'), 'a-propos', 'Qui sommes-nous ?'),
|
||||
(url_for('posts', name='actualites'), 'actualites', 'Actualités'),
|
||||
(url_for('posts', name='emplois'), 'emplois', 'Offres \'emplois'),
|
||||
(url_for('posts', name='emplois'), 'emplois', 'Offres d\'emplois'),
|
||||
(url_for('pages', name='communaute'), 'communaute', 'Communauté'),
|
||||
(url_for('pages', name='discussion'), 'discussion', 'Discussion'),
|
||||
(url_for('pages', name='adhesions'), 'adhesions', 'Adhésions')
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
<time pubdate datetime="{{ post.published }}">
|
||||
{{ post.published | parse_iso_datetime('%x') }}
|
||||
</time>
|
||||
{% if post.image %}
|
||||
<img src="{{ url_for('post_image', path=post.image) }}" alt="{{ post.title }}" />
|
||||
{% if post._image %}
|
||||
<img src="{{ url_for('post_image', path=post._image) }}" alt="{{ post.title }}" />
|
||||
{% endif %}
|
||||
{{ post.summary | safe }}
|
||||
<p><a href="{{ url_for('post', name=name, timestamp=timestamp) }}">Lire la suite…</a></p>
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
{{ post.summary | safe if post.summary }}
|
||||
</em>
|
||||
</p>
|
||||
{% if post.image %}
|
||||
<img src="{{ url_for('post_image', path=post.image) }}" alt="{{ post.title }}" />
|
||||
{% if post._image %}
|
||||
<img src="{{ url_for('post_image', path=post._image) }}" alt="{{ post.title }}" />
|
||||
{% endif %}
|
||||
{{ post.content | safe }}
|
||||
</article>
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
<time pubdate datetime="{{ post.published }}">
|
||||
{{ post.published | parse_iso_datetime('%x') }}
|
||||
</time>
|
||||
{% if post.image %}
|
||||
<img src="{{ url_for('post_image', path=post.image) }}" alt="{{ post.title }}" />
|
||||
{% if post._image %}
|
||||
<img src="{{ url_for('post_image', path=post._image) }}" alt="{{ post.title }}" />
|
||||
{% endif %}
|
||||
{{ post.summary | safe if post.summary }}
|
||||
<p><a href="{{ url_for('post', name=name, timestamp=timestamp) }}">Lire la suite…</a></p>
|
||||
|
|
Loading…
Reference in New Issue
Block a user