Remplacer simpleMDE par un éditeur maison #110

Merged
Darks merged 34 commits from new_editor into dev 2022-12-18 00:08:52 +01:00
2 changed files with 40 additions and 38 deletions
Showing only changes of commit 8cd862078b - Show all commits

View File

@ -3,56 +3,57 @@ from app.models.program import Program
from app.models.thread import Thread
from app.models.comment import Comment
from app.models.tag import Tag
from app.models.attachment import Attachment
from app.utils.render import render
from app.forms.programs import ProgramCreationForm
from flask_login import current_user
from flask_login import login_required, current_user
from flask import redirect, url_for, flash
@app.route('/programmes/soumettre', methods=['GET', 'POST'])
@login_required
def program_submit():
if current_user.is_authenticated:
form = ProgramCreationForm()
if form.validate_on_submit():
# First create a new thread
# TODO: Reuse a thread when performing topic promotion
th = Thread()
db.session.add(th)
db.session.commit()
form = ProgramCreationForm()
if form.validate_on_submit():
# First create a new thread
# TODO: Reuse a thread when performing topic promotion
th = Thread()
db.session.add(th)
db.session.commit()
# Create its top comment
c = Comment(current_user, form.message.data, th)
db.session.add(c)
db.session.commit()
th.set_top_comment(c)
db.session.merge(th)
# Create its top comment
c = Comment(current_user, form.message.data, th)
db.session.add(c)
db.session.commit()
th.set_top_comment(c)
db.session.merge(th)
# Then build the actual program
p = Program(current_user, form.name.data, th)
db.session.add(p)
db.session.commit()
# Then build the actual program
p = Program(current_user, form.name.data, th)
db.session.add(p)
db.session.commit()
# Add tags
for tag in form.tags.selected_tags():
db.session.add(Tag(p, tag))
db.session.commit()
# Add tags
for tag in form.tags.selected_tags():
db.session.add(Tag(p, tag))
db.session.commit()
# Manage files
attachments = []
for file in form.attachments.data:
if file.filename != "":
a = Attachment(file, c)
attachments.append((a, file))
db.session.add(a)
db.session.commit()
for a, file in attachments:
a.set_file(file)
# Manage files
attachments = []
for file in form.attachments.data:
if file.filename != "":
a = Attachment(file, c)
attachments.append((a, file))
db.session.add(a)
db.session.commit()
for a, file in attachments:
a.set_file(file)
current_user.add_xp(20)
current_user.update_trophies('new-program')
current_user.add_xp(20)
current_user.update_trophies('new-program')
flash('Le programme a bien été soumis', 'ok')
return redirect(url_for('program_index'))
flash('Le programme a bien été soumis', 'ok')
return redirect(url_for('program_index'))
return render('/programs/submit.html', form=form)

View File

@ -13,6 +13,7 @@ import yaml
import slugify
import readline
from PIL import Image
from PIL.Image import Resampling
help_msg = """
@ -269,7 +270,7 @@ def generate_trophy_icons():
icon = img.crop((26*x+1, 26*y+1, 26*x+25, 26*y+25))
# Skip blank squares in the source image
if len(icon.getcolors()) > 1:
yield icon.resize((48,48), resample=Image.NEAREST)
yield icon.resize((48,48), resample=Resampling.NEAREST)
for (name, icon) in zip(names, trophy_iterator(img)):
icon.save(os.path.join(dst, f"{name}.png"))