Merging with master

This commit is contained in:
Jérémie 2018-10-05 17:22:59 +02:00
commit 038b578e07
7 changed files with 54 additions and 13 deletions

View File

@ -151,7 +151,8 @@ def save_post(name, token=None):
timestamp = None
try:
post = data.save_post(
name, timestamp=timestamp, admin=False, form=request.form
name, timestamp=timestamp, admin=False,
form=request.form, files=request.files
)
except data.DataException as e:
abort(e.http_code)
@ -173,10 +174,13 @@ def save_post_admin(name, timestamp):
abort(404)
try:
data.save_post(
name, timestamp=timestamp, admin=True, form=request.form
name, timestamp=timestamp, admin=True,
form=request.form, files=request.files
)
except data.DataException as e:
abort(e.http_code)
if 'delete_image' in request.form:
return redirect(request.url)
return redirect(url_for('admin', name=name))

View File

@ -2,6 +2,7 @@ import email
import time
from pathlib import Path
from xml.etree import ElementTree
from werkzeug.utils import secure_filename
POST_ACTUALITIES = 'actualites'
@ -22,12 +23,14 @@ ACTION_UNPUBLISH = 'unpublish'
ACTION_REPUBLISH = 'republish'
ACTION_TRASH = 'trash'
ACTION_EDIT = 'edit'
ACTION_DELETE_IMAGE = 'delete_image'
ACTIONS = {
ACTION_PUBLISH: "Publier",
ACTION_UNPUBLISH: "Dépublier",
ACTION_REPUBLISH: "Republier",
ACTION_TRASH: "Supprimer",
ACTION_EDIT: 'Editer',
ACTION_DELETE_IMAGE: "Supprimer l'image"
}
IMAGE = '_image'
@ -103,7 +106,7 @@ def get_post(category, timestamp, states=None):
return post
def save_post(category, timestamp, admin, form):
def save_post(category, timestamp, admin, form, files):
if timestamp is None:
status = STATE_WAITING
timestamp = str(int(time.time()))
@ -120,11 +123,28 @@ def save_post(category, timestamp, admin, form):
post = get_path(category, status, timestamp, BASE_FILE, create_dir=True)
tree = ElementTree.Element('entry')
for key, value in form.items():
if key.startswith('_'):
continue
element = ElementTree.SubElement(tree, key)
element.text = value
if '_image_path' in form:
image_path = root / form['_image_path']
if ACTION_DELETE_IMAGE in form and image_path.exists:
image_path.unlink()
else:
element = ElementTree.SubElement(tree, 'image')
element.text = image_path.name
if 'image' in files:
post_image = files['image']
filename = secure_filename(post_image.filename)
post_image.save(str(post.parent / filename))
element = ElementTree.SubElement(tree, 'image')
element.text = filename
element = ElementTree.SubElement(tree, STATE_PUBLISHED)
element.text = email.utils.formatdate(
int(timestamp) if timestamp else time.time()

View File

@ -37,7 +37,7 @@ label
textarea
height: 5em
input[type="submit"]
.button
background: $action
border: 0
color: $text
@ -234,6 +234,10 @@ dd
time
display: block
article
img
max-width: 100%
#actualites main, #emplois main, #index-news
box-sizing: border-box
display: flex
@ -247,9 +251,6 @@ time
padding: 2em
word-wrap: break-word
img
max-width: 100%
a
color: $action-secondary
font-size: .8em

View File

@ -28,7 +28,7 @@ label {
textarea {
height: 5em; }
input[type="submit"] {
.button {
background: #2e5cfd;
border: 0;
color: #eaeaea;
@ -39,7 +39,7 @@ input[type="submit"] {
text-transform: uppercase;
transition: background 250ms;
width: auto; }
input[type="submit"]:hover {
.button:hover {
background: #4770fd; }
.nicEdit-panelContain, .nicEdit-pane {
@ -208,6 +208,9 @@ dd {
time {
display: block; }
article img {
max-width: 100%; }
#actualites main, #emplois main, #index-news {
box-sizing: border-box;
display: flex;
@ -219,8 +222,6 @@ time {
flex: 1 50%;
padding: 2em;
word-wrap: break-word; }
#actualites main article img, #emplois main article img, #index-news article img {
max-width: 100%; }
#actualites main article a, #emplois main article a, #index-news article a {
color: #ffcd05;
font-size: .8em;

View File

@ -23,13 +23,21 @@
{% block main %}
<article>
<form method="post">
<form method="post" enctype="multipart/form-data">
<label>Titre
<input name="title" value="{{ post.title }}" />
</label>
<label>Description
<textarea name="summary">{{ post.summary }}</textarea>
</label>
<label>Image
{% if post._image %}
<img alt="" src="{{ url_for('post_image', path=post._image) }}" />
<input name="_image_path" id="_image_path" value="{{ post._image }}" type="hidden"/>
<input type="submit" name="delete_image" value="Supprimer l'image" class="button" />
{% endif %}
<input name="image" id="image" type="file" value="{{ post.image }}" />
</label>
<label>Contenu de l'article
<textarea name="content" id="content">{{ post.content }}</textarea>
</label>

View File

@ -16,7 +16,7 @@
Il est possible de soutenir le développement de l'AFPy en cotisant ou en effectuant un don.
</p>
<form action="{{ url_for('pages', name='adhesions') }}">
<input type="submit" value="S'inscrire" />
<input type="submit" value="S'inscrire" class="button" />
</form>
<h2>Actualités</h2>

View File

@ -32,3 +32,10 @@ def test_404():
assert response.status_code == 404
response = app.test_client().get('/feed/unknown')
assert response.status_code == 404
def test_read_posts():
response = app.test_client().get('/posts/actualites')
assert response.status_code == 200
response = app.test_client().get('/posts/emplois')
assert response.status_code == 200