ajout p_texts
This commit is contained in:
@@ -13,6 +13,7 @@ from pyramid.httpexceptions import (
|
||||
|
||||
from pyramid_mailer.message import Message, Attachment
|
||||
from datetime import *
|
||||
from docutils.core import publish_parts
|
||||
import hashlib
|
||||
|
||||
from sqlalchemy.exc import DBAPIError
|
||||
@@ -361,3 +362,83 @@ def emails_msg(request):
|
||||
return {
|
||||
'page_title': item.COMMENT,
|
||||
'item': item,
|
||||
}
|
||||
|
||||
@view_config(route_name='text_list', renderer='../templates/parametres/text_list.pt', permission='manage')
|
||||
def text_list(request):
|
||||
|
||||
# lire toutes les text
|
||||
texts = get_texts(request, 0)
|
||||
|
||||
return {
|
||||
'page_title': "Liste des textes",
|
||||
'texts': texts,
|
||||
}
|
||||
|
||||
@view_config(route_name='text_edit', renderer='../templates/parametres/text_edit.pt', permission='manage')
|
||||
def text_edit(request):
|
||||
text_id = request.matchdict['text_id']
|
||||
url = request.route_url('text_edit',text_id=text_id)
|
||||
|
||||
message = ""
|
||||
if text_id == '0':
|
||||
titre = "Nouvelle text"
|
||||
intitule = ""
|
||||
texte = ""
|
||||
theme = ""
|
||||
else:
|
||||
titre = "Modifier la text : %s" % str(text_id)
|
||||
text = get_texts(request, text_id)
|
||||
intitule = text.intitule
|
||||
texte = text.texte
|
||||
theme = text.theme
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
intitule = request.params["intitule"]
|
||||
texte = request.params["texte"]
|
||||
theme = request.params["theme"]
|
||||
|
||||
if len(intitule) > 0 and len(texte) > 0:
|
||||
update_text(request, text_id, intitule, texte, theme)
|
||||
if text_id == '0':
|
||||
# si creation text, retour à la liste des texts
|
||||
return HTTPFound(location=request.route_url('text_list'))
|
||||
else:
|
||||
return HTTPFound(location=request.route_url('text_view', text_id=text_id))
|
||||
else:
|
||||
message = "Veuillez saisir un intitule et un texte."
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
if text_id != '0':
|
||||
delete_text(request, text_id)
|
||||
request.session.flash("'%s' a été supprimée avec succès." % intitule, 'success')
|
||||
return HTTPFound(location=request.route_url('text_list'))
|
||||
|
||||
return {
|
||||
'page_title': titre,
|
||||
'url': url,
|
||||
'message': message,
|
||||
'text_id': text_id,
|
||||
'intitule': intitule,
|
||||
'texte': texte,
|
||||
'theme': theme,
|
||||
'themes': ["EMAIL","INTERNE"],
|
||||
}
|
||||
|
||||
@view_config(route_name='text_view', renderer='../templates/parametres/text_view.pt')
|
||||
def text_view(request):
|
||||
text_id = request.matchdict['text_id']
|
||||
current_route_path = request.current_route_path()
|
||||
|
||||
text = get_texts(request, text_id)
|
||||
intitule = text.intitule
|
||||
# insèrer le path de static/img
|
||||
img_path = '%s/static/img/' % request.application_url
|
||||
|
||||
texte = text.texte.replace('static/img/', img_path)
|
||||
# convertir reST en HTML
|
||||
texte = publish_parts(texte, writer_name='html')['html_body']
|
||||
return {
|
||||
'page_title': intitule,
|
||||
'texte': texte,
|
||||
'text_id': text_id,
|
||||
|
||||
Reference in New Issue
Block a user