refonte de folder.pt et docs_search.pt

This commit is contained in:
2021-09-13 15:04:39 +02:00
parent 24a23c5f94
commit dd8cdb7564
5 changed files with 277 additions and 193 deletions

22
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "python",
"request": "launch",
"name": "Pserve",
"python": "C:/pyramid10/Scripts/python.exe",
"program": "/pyramid10/Scripts/pserve.exe",
"args": [
"-v",
"development.ini",
"--reload"
],
"console": "integratedTerminal",
"pyramid": true,
}
]
}

View File

@@ -24,16 +24,6 @@
<textarea class="form-control monospace-font" rows="15" cols="40" id="texte" name="texte">${doc.texte}</textarea> <textarea class="form-control monospace-font" rows="15" cols="40" id="texte" name="texte">${doc.texte}</textarea>
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-xs-2" for="tag2">Statut</label>
<div class="col-xs-6">
<select class="form-control" id="tag1" name="tag1">
<div tal:repeat="item statuts">
<option value="${item}" tal:attributes="selected doc.statut==item and 'selected' or None">${item}</option>
</div>
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label class="control-label col-xs-2">Dossier</label> <label class="control-label col-xs-2">Dossier</label>
<div class="col-xs-7"> <div class="col-xs-7">

View File

@@ -20,24 +20,28 @@
</div><!-- row --> </div><!-- row -->
<div class="row"> <div class="row">
<div tal:condition="docs"> <div tal:condition="dt_data != '[]'">
<table class="table table-striped table-bordered"> <table id="folder_list" class="table">
<tr tal:repeat="ligne docs"> <thead>
<td><a href="/doc_view/${ligne.doc_id}"><b>${ligne.intitule}</b></a></td> <tr>
<td>${ligne.tag1}</td> <th>Titre</th>
<td>${ligne.cree_le.strftime("%d-%m-%Y")}</td> <th>Tags</th>
<td>${ligne.modif_le.strftime("%d-%m-%Y")}</td> <th>Date</th>
</tr> <th></th>
</tr>
</thead>
</table> </table>
</div> </div>
<div tal:condition="not docs"> <div tal:condition="dt_data == '[]'">
<p class="text-danger text-center">Aucun document ne correspond à la recherche</p> <h3 class="text-center">Aucun élément trouvé pour ce critère</h3>
</div> </div>
</div> </div>
<br /> <br />
<br /> <br />
<script> <script type="text/javascript">
var dataSet = ${dt_data};
$(document).ready(function() { $(document).ready(function() {
$('#search-form').formValidation({ $('#search-form').formValidation({
framework: 'bootstrap', framework: 'bootstrap',
@@ -62,6 +66,23 @@ $(document).ready(function() {
}, },
} }
}); });
$.fn.dataTable.moment('DD/MM/YYYY - HH:mm');
$('#folder_list').DataTable({
data: dataSet,
pageLength: 50,
bLengthChange: false,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json'
},
columnDefs: [
{ "targets": 0,
"render": function (data, type, row, meta) {
// ajouter un link vers le formulaire
return '<a href="/doc_view/' + row[3] + '">' + data + '</a>';
},
},
]
});
$('form input').on('keypress', function(e) { $('form input').on('keypress', function(e) {
var code = e.keyCode || e.which; var code = e.keyCode || e.which;
if (code === 13) { if (code === 13) {

View File

@@ -6,18 +6,44 @@
<a href="${request.application_url}/doc_edit/${topic}/0" tal:condition="not layout.isAnonymous()">[&nbsp;Créer&nbsp;]</a> <a href="${request.application_url}/doc_edit/${topic}/0" tal:condition="not layout.isAnonymous()">[&nbsp;Créer&nbsp;]</a>
</p> </p>
<div class="row"> <div class="row">
<table class="table"> <table id="folder_list" class="table">
<tr tal:repeat="ligne docs"> <thead>
<td><a href="/doc_view/${ligne.doc_id}"><b>${ligne.intitule}</b></a></td> <tr>
<td>${ligne.tag1}</td> <th>Titre</th>
<td>${ligne.cree_le.strftime("%d-%m-%Y")}</td> <th>Tags</th>
</tr> <th>Date</th>
<th></th>
</tr>
</thead>
</table> </table>
</div> </div>
<br /> <br />
<br /> <br />
</div> <script type="text/javascript">
var dataSet = ${dt_data};
$(document).ready(function() {
$.fn.dataTable.moment('DD/MM/YYYY - HH:mm');
$('#folder_list').DataTable({
data: dataSet,
pageLength: 50,
bLengthChange: false,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json'
},
columnDefs: [
{ "targets": 0,
"render": function (data, type, row, meta) {
// ajouter un link vers le formulaire
return '<a href="/doc_view/' + row[3] + '">' + data + '</a>';
},
},
]
});
});
</script>
</div> <!-- content -->
</div> </div>

View File

@@ -1,164 +1,189 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
from pyramid.response import Response from pyramid.response import Response
from pyramid.renderers import render, get_renderer from pyramid.renderers import render, get_renderer
from pyramid.view import ( from pyramid.view import (
view_config, view_config,
forbidden_view_config, forbidden_view_config,
) )
from pyramid.httpexceptions import ( from pyramid.httpexceptions import (
HTTPFound, HTTPFound,
HTTPNotFound, HTTPNotFound,
HTTPForbidden, HTTPForbidden,
) )
import json
from ..models.contents import *
from ..models.contents import *
def isAnonymous(request):
logged_in = request.authenticated_userid def isAnonymous(request):
return logged_in is None logged_in = request.authenticated_userid
return logged_in is None
@view_config(route_name='folder', renderer='../templates/contents/folder.pt')
def folder(request): @view_config(route_name='folder', renderer='../templates/contents/folder.pt')
topic = request.matchdict['topic'] def folder(request):
logged_in = request.authenticated_userid topic = request.matchdict['topic']
logged_in = request.authenticated_userid
# lire toutes les docs du topic
docs = get_docs_bytopic(request, topic, logged_in) # lire toutes les docs du topic
items = get_docs_bytopic(request, topic, logged_in)
return {
'page_title': "Contenu de %s" % topic.upper(), # construire la liste
'docs': docs, liste=[]
'topic': topic, for item in items:
} # lire le(s) tag(s) du documents
tags = get_docs_tags(request, item.doc_id)
@view_config(route_name='doc_edit', renderer='../templates/contents/doc_edit.pt', permission='view') tags_list = ''
def doc_edit(request): for tag in tags:
topic = request.matchdict['topic'] tags_list += tag.tag + ', '
doc_id = request.matchdict['doc_id']
url = request.route_url('doc_edit', topic=topic, doc_id=doc_id) cree_le = item.cree_le.strftime('%d/%m/%Y')
logged_in = request.authenticated_userid d = (item.intitule, tags_list, cree_le, item.doc_id)
liste.append(d)
# si anonyme, interdire de modifier les docs
if isAnonymous(request): return {
return HTTPFound(location=request.route_url('home')) 'page_title': "Contenu de %s" % topic.upper(),
'topic': topic,
message = "" 'dt_data': json.dumps(liste),
}
statuts = ['private', 'public']
@view_config(route_name='doc_edit', renderer='../templates/contents/doc_edit.pt', permission='view')
if doc_id == '0': def doc_edit(request):
titre = "Nouveau doc" topic = request.matchdict['topic']
# nouveau doc_id = request.matchdict['doc_id']
doc = {} url = request.route_url('doc_edit', topic=topic, doc_id=doc_id)
doc['intitule'] = '' logged_in = request.authenticated_userid
doc['texte'] = ''
doc['topic'] = topic # si anonyme, interdire de modifier les docs
doc['statut'] = 'private' if isAnonymous(request):
tags = {} return HTTPFound(location=request.route_url('home'))
else:
titre = "Modifier : %s" % str(doc_id) message = ""
doc = get_docs(request, doc_id)
tags = get_docs_tags(request, doc.doc_id) statuts = ['private', 'public']
d_tags = get_d_tags_manquant(request, topic, doc_id) if doc_id == '0':
titre = "Nouveau doc"
if 'form.submitted' in request.params: # nouveau
new_values = {} doc = {}
for param, db_value in doc.items(): doc['intitule'] = ''
if param in request.params and request.params[param] != db_value: doc['texte'] = ''
new_values[param] = request.params[param] doc['topic'] = topic
doc['statut'] = 'private'
if new_values: tags = {}
new_values['topic'] = topic else:
update_doc(request, doc_id, new_values) titre = "Modifier : %s" % str(doc_id)
if doc_id != '0': doc = get_docs(request, doc_id)
return HTTPFound(location=request.route_url('doc_view', doc_id=doc_id)) tags = get_docs_tags(request, doc.doc_id)
else:
return HTTPFound(location=request.route_url('folder',topic=topic)) d_tags = get_d_tags_manquant(request, topic, doc_id)
if 'form.deleted' in request.params: if 'form.submitted' in request.params:
if doc_id != '0': new_values = {}
delete_doc(request, doc_id) for param, db_value in doc.items():
request.session.flash(u"<%s> est supprimée avec succès." % doc.intitule, 'success') if param in request.params and request.params[param] != db_value:
return HTTPFound(location=request.route_url('folder',topic=topic)) new_values[param] = request.params[param]
return { if new_values:
'page_title': titre, new_values['topic'] = topic
'url': url, update_doc(request, doc_id, new_values)
'message': message, if doc_id != '0':
'doc_id': doc_id, return HTTPFound(location=request.route_url('doc_view', doc_id=doc_id))
'doc': doc, else:
'topic': topic, return HTTPFound(location=request.route_url('folder',topic=topic))
'tags': tags,
'd_tags': d_tags, if 'form.deleted' in request.params:
'statuts': statuts, if doc_id != '0':
} delete_doc(request, doc_id)
request.session.flash(u"<%s> est supprimée avec succès." % doc.intitule, 'success')
@view_config(route_name='doc_search', renderer='../templates/contents/doc_search.pt') return HTTPFound(location=request.route_url('folder',topic=topic))
def doc_search(request):
return {
logged_in = request.authenticated_userid 'page_title': titre,
critere = '' 'url': url,
docs = [] 'message': message,
'doc_id': doc_id,
if 'form.submitted' in request.params: 'doc': doc,
critere = request.params['critere'] 'topic': topic,
# si afficher tous les fiches ? 'tags': tags,
docs = get_docs_bycritere(request, critere, logged_in) 'd_tags': d_tags,
'statuts': statuts,
return { }
'page_title': "Rechercher",
'docs': docs, @view_config(route_name='doc_search', renderer='../templates/contents/doc_search.pt')
'critere': critere, def doc_search(request):
}
logged_in = request.authenticated_userid
@view_config(route_name='doc_view', renderer='../templates/contents/doc_view.pt') critere = ''
def doc_view(request): liste=[]
doc_id = request.matchdict['doc_id'] if 'form.submitted' in request.params:
critere = request.params['critere']
# lire le document # si afficher tous les fiches ?
doc = get_docs(request, doc_id) items = get_docs_bycritere(request, critere, logged_in)
# si anonyme, interdire de voir les docs privés # construire la liste
if isAnonymous(request) and doc.statut == 'private': for item in items:
return HTTPFound(location=request.route_url('home')) # lire le(s) tag(s) du documents
tags = get_docs_tags(request, item.doc_id)
if doc_id == '2': tags_list = ''
# mouvements portfolio, retour vers portfolio for tag in tags:
url_retour = request.route_url('portfolio') tags_list += tag.tag + ', '
else:
url_retour = request.route_url('folder',topic=doc.topic) cree_le = item.cree_le.strftime('%d/%m/%Y')
d = (item.intitule, tags_list, cree_le, item.doc_id)
tags = get_docs_tags(request, doc.doc_id) liste.append(d)
# insèrer le path de static/img return {
texte = doc.texte.replace('static/img/', "%s/static/img/" % request.application_url) 'page_title': "Rechercher",
'dt_data': json.dumps(liste),
# convertir mardown en HTML 'critere': critere,
from markdown2 import Markdown }
markdowner = Markdown()
texte = markdowner.convert(texte) @view_config(route_name='doc_view', renderer='../templates/contents/doc_view.pt')
def doc_view(request):
return {
'page_title': doc.intitule, doc_id = request.matchdict['doc_id']
'doc_id': doc_id,
'doc': doc, # lire le document
'texte': texte, doc = get_docs(request, doc_id)
'topic': doc.topic,
'tags': tags, # si anonyme, interdire de voir les docs privés
'url_retour':url_retour, if isAnonymous(request) and doc.statut == 'private':
} return HTTPFound(location=request.route_url('home'))
@view_config(route_name='tag_change') if doc_id == '2':
def tag_change(request): # mouvements portfolio, retour vers portfolio
url_retour = request.route_url('portfolio')
logged_in = request.authenticated_userid else:
action = request.matchdict['action'] url_retour = request.route_url('folder',topic=doc.topic)
topic = request.matchdict['topic']
doc_id = request.matchdict['doc_id'] tags = get_docs_tags(request, doc.doc_id)
tag = request.matchdict['tag']
# insèrer le path de static/img
change_doc_tag(request, action, doc_id, tag) texte = doc.texte.replace('static/img/', "%s/static/img/" % request.application_url)
return HTTPFound(location=request.route_url('doc_edit', topic=topic, doc_id=doc_id)) # convertir mardown en HTML
from markdown2 import Markdown
markdowner = Markdown()
texte = markdowner.convert(texte)
return {
'page_title': doc.intitule,
'doc_id': doc_id,
'doc': doc,
'texte': texte,
'topic': doc.topic,
'tags': tags,
'url_retour':url_retour,
}
@view_config(route_name='tag_change')
def tag_change(request):
logged_in = request.authenticated_userid
action = request.matchdict['action']
topic = request.matchdict['topic']
doc_id = request.matchdict['doc_id']
tag = request.matchdict['tag']
change_doc_tag(request, action, doc_id, tag)