added docs CUD

This commit is contained in:
2017-07-23 11:07:51 +02:00
parent fc29d5da24
commit 56605c5166
9 changed files with 264 additions and 13 deletions

View File

@@ -19,9 +19,12 @@ from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message, Attachment
from datetime import *
import hashlib
from docutils.core import publish_parts
from sqlalchemy.exc import DBAPIError
from ..security import groupfinder
from ..models.default import *
from ..models.members import (
get_member_by_email,
)
@@ -64,6 +67,81 @@ def home(request):
'page_title': u"%s %s" % (membre.prenom, membre.nom),
}
@view_config(route_name='doc_list', renderer='../templates/doc_list.pt', permission='view')
def doc_list(request):
# lire toutes les docs
docs = get_docs(request, 0)
return {
'page_title': u"Documents",
'docs': docs,
}
@view_config(route_name='doc_edit', renderer='../templates/doc_edit.pt', permission='view')
def doc_edit(request):
doc_id = request.matchdict['doc_id']
url = request.route_url('doc_edit',doc_id=doc_id)
message = u""
if doc_id == '0':
titre = "Nouvelle doc"
intitule = u""
texte = u""
theme = u""
else:
titre = "Modifier la doc : %s" % str(doc_id)
doc = get_docs(request, doc_id)
intitule = doc.intitule
texte = doc.texte
theme = doc.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_doc(request, doc_id, intitule, texte, theme)
return HTTPFound(location=request.route_url('doc_list')
else:
message = "Veuillez saisir un intitule et un texte."
if 'form.deleted' in request.params:
if doc_id <> '0':
delete_doc(request, doc_id)
request.session.flash(u"<%s> est supprimée avec succès." % intitule, 'success')
return HTTPFound(location=request.route_url('doc_list')
return {
'page_title': titre,
'url': url,
'message': message,
'doc_id': doc_id,
'intitule': intitule,
'texte': texte,
'theme': theme,
'themes': ["CONDUITE","EXAMEN","RESULTAT","INTERNE"],
}
@view_config(route_name='doc_view', renderer='../templates/doc_view.pt', permission='view')
def doc_view(request):
doc_id = request.matchdict['doc_id']
current_route_path = request.current_route_path()
doc = get_docs(request, doc_id)
intitule = doc.intitule
# insèrer le path de static/img
img_path = 'image:: %s/static/img/' % request.application_url
texte = doc.texte.replace('image:: static/img/', img_path)
# convertir reST en HTML
texte = publish_parts(texte, writer_name='html')['html_body']
return {
'page_title': intitule,
'texte': texte,
'doc_id': doc_id,
}
def envoyerMail(request, destinataire, objet, corps):
body = u"""