refonte de folder.pt et docs_search.pt
This commit is contained in:
@@ -24,16 +24,6 @@
|
||||
<textarea class="form-control monospace-font" rows="15" cols="40" id="texte" name="texte">${doc.texte}</textarea>
|
||||
</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">
|
||||
<label class="control-label col-xs-2">Dossier</label>
|
||||
<div class="col-xs-7">
|
||||
|
||||
@@ -20,24 +20,28 @@
|
||||
</div><!-- row -->
|
||||
|
||||
<div class="row">
|
||||
<div tal:condition="docs">
|
||||
<table class="table table-striped table-bordered">
|
||||
<tr tal:repeat="ligne docs">
|
||||
<td><a href="/doc_view/${ligne.doc_id}"><b>${ligne.intitule}</b></a></td>
|
||||
<td>${ligne.tag1}</td>
|
||||
<td>${ligne.cree_le.strftime("%d-%m-%Y")}</td>
|
||||
<td>${ligne.modif_le.strftime("%d-%m-%Y")}</td>
|
||||
</tr>
|
||||
<div tal:condition="dt_data != '[]'">
|
||||
<table id="folder_list" class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Tags</th>
|
||||
<th>Date</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<div tal:condition="not docs">
|
||||
<p class="text-danger text-center">Aucun document ne correspond à la recherche</p>
|
||||
<div tal:condition="dt_data == '[]'">
|
||||
<h3 class="text-center">Aucun élément trouvé pour ce critère</h3>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
|
||||
<script>
|
||||
<script type="text/javascript">
|
||||
var dataSet = ${dt_data};
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#search-form').formValidation({
|
||||
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) {
|
||||
var code = e.keyCode || e.which;
|
||||
if (code === 13) {
|
||||
|
||||
@@ -6,18 +6,44 @@
|
||||
<a href="${request.application_url}/doc_edit/${topic}/0" tal:condition="not layout.isAnonymous()">[ Créer ]</a>
|
||||
</p>
|
||||
<div class="row">
|
||||
<table class="table">
|
||||
<tr tal:repeat="ligne docs">
|
||||
<td><a href="/doc_view/${ligne.doc_id}"><b>${ligne.intitule}</b></a></td>
|
||||
<td>${ligne.tag1}</td>
|
||||
<td>${ligne.cree_le.strftime("%d-%m-%Y")}</td>
|
||||
</tr>
|
||||
<table id="folder_list" class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Titre</th>
|
||||
<th>Tags</th>
|
||||
<th>Date</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
@@ -1,164 +1,189 @@
|
||||
# -*- coding: utf8 -*-
|
||||
from pyramid.response import Response
|
||||
from pyramid.renderers import render, get_renderer
|
||||
from pyramid.view import (
|
||||
view_config,
|
||||
forbidden_view_config,
|
||||
)
|
||||
from pyramid.httpexceptions import (
|
||||
HTTPFound,
|
||||
HTTPNotFound,
|
||||
HTTPForbidden,
|
||||
)
|
||||
|
||||
from ..models.contents import *
|
||||
|
||||
def isAnonymous(request):
|
||||
logged_in = request.authenticated_userid
|
||||
return logged_in is None
|
||||
|
||||
@view_config(route_name='folder', renderer='../templates/contents/folder.pt')
|
||||
def folder(request):
|
||||
topic = request.matchdict['topic']
|
||||
logged_in = request.authenticated_userid
|
||||
|
||||
# lire toutes les docs du topic
|
||||
docs = get_docs_bytopic(request, topic, logged_in)
|
||||
|
||||
return {
|
||||
'page_title': "Contenu de %s" % topic.upper(),
|
||||
'docs': docs,
|
||||
'topic': topic,
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_edit', renderer='../templates/contents/doc_edit.pt', permission='view')
|
||||
def doc_edit(request):
|
||||
topic = request.matchdict['topic']
|
||||
doc_id = request.matchdict['doc_id']
|
||||
url = request.route_url('doc_edit', topic=topic, doc_id=doc_id)
|
||||
logged_in = request.authenticated_userid
|
||||
|
||||
# si anonyme, interdire de modifier les docs
|
||||
if isAnonymous(request):
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
message = ""
|
||||
|
||||
statuts = ['private', 'public']
|
||||
|
||||
if doc_id == '0':
|
||||
titre = "Nouveau doc"
|
||||
# nouveau
|
||||
doc = {}
|
||||
doc['intitule'] = ''
|
||||
doc['texte'] = ''
|
||||
doc['topic'] = topic
|
||||
doc['statut'] = 'private'
|
||||
tags = {}
|
||||
else:
|
||||
titre = "Modifier : %s" % str(doc_id)
|
||||
doc = get_docs(request, doc_id)
|
||||
tags = get_docs_tags(request, doc.doc_id)
|
||||
|
||||
d_tags = get_d_tags_manquant(request, topic, doc_id)
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
new_values = {}
|
||||
for param, db_value in doc.items():
|
||||
if param in request.params and request.params[param] != db_value:
|
||||
new_values[param] = request.params[param]
|
||||
|
||||
if new_values:
|
||||
new_values['topic'] = topic
|
||||
update_doc(request, doc_id, new_values)
|
||||
if doc_id != '0':
|
||||
return HTTPFound(location=request.route_url('doc_view', doc_id=doc_id))
|
||||
else:
|
||||
return HTTPFound(location=request.route_url('folder',topic=topic))
|
||||
|
||||
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." % doc.intitule, 'success')
|
||||
return HTTPFound(location=request.route_url('folder',topic=topic))
|
||||
|
||||
return {
|
||||
'page_title': titre,
|
||||
'url': url,
|
||||
'message': message,
|
||||
'doc_id': doc_id,
|
||||
'doc': doc,
|
||||
'topic': topic,
|
||||
'tags': tags,
|
||||
'd_tags': d_tags,
|
||||
'statuts': statuts,
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_search', renderer='../templates/contents/doc_search.pt')
|
||||
def doc_search(request):
|
||||
|
||||
logged_in = request.authenticated_userid
|
||||
critere = ''
|
||||
docs = []
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
critere = request.params['critere']
|
||||
# si afficher tous les fiches ?
|
||||
docs = get_docs_bycritere(request, critere, logged_in)
|
||||
|
||||
return {
|
||||
'page_title': "Rechercher",
|
||||
'docs': docs,
|
||||
'critere': critere,
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_view', renderer='../templates/contents/doc_view.pt')
|
||||
def doc_view(request):
|
||||
|
||||
doc_id = request.matchdict['doc_id']
|
||||
|
||||
# lire le document
|
||||
doc = get_docs(request, doc_id)
|
||||
|
||||
# si anonyme, interdire de voir les docs privés
|
||||
if isAnonymous(request) and doc.statut == 'private':
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
if doc_id == '2':
|
||||
# mouvements portfolio, retour vers portfolio
|
||||
url_retour = request.route_url('portfolio')
|
||||
else:
|
||||
url_retour = request.route_url('folder',topic=doc.topic)
|
||||
|
||||
tags = get_docs_tags(request, doc.doc_id)
|
||||
|
||||
# insèrer le path de static/img
|
||||
texte = doc.texte.replace('static/img/', "%s/static/img/" % request.application_url)
|
||||
|
||||
# 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)
|
||||
|
||||
return HTTPFound(location=request.route_url('doc_edit', topic=topic, doc_id=doc_id))
|
||||
# -*- coding: utf8 -*-
|
||||
from pyramid.response import Response
|
||||
from pyramid.renderers import render, get_renderer
|
||||
from pyramid.view import (
|
||||
view_config,
|
||||
forbidden_view_config,
|
||||
)
|
||||
from pyramid.httpexceptions import (
|
||||
HTTPFound,
|
||||
HTTPNotFound,
|
||||
HTTPForbidden,
|
||||
)
|
||||
import json
|
||||
|
||||
from ..models.contents import *
|
||||
|
||||
def isAnonymous(request):
|
||||
logged_in = request.authenticated_userid
|
||||
return logged_in is None
|
||||
|
||||
@view_config(route_name='folder', renderer='../templates/contents/folder.pt')
|
||||
def folder(request):
|
||||
topic = request.matchdict['topic']
|
||||
logged_in = request.authenticated_userid
|
||||
|
||||
# lire toutes les docs du topic
|
||||
items = get_docs_bytopic(request, topic, logged_in)
|
||||
|
||||
# construire la liste
|
||||
liste=[]
|
||||
for item in items:
|
||||
# lire le(s) tag(s) du documents
|
||||
tags = get_docs_tags(request, item.doc_id)
|
||||
tags_list = ''
|
||||
for tag in tags:
|
||||
tags_list += tag.tag + ', '
|
||||
|
||||
cree_le = item.cree_le.strftime('%d/%m/%Y')
|
||||
d = (item.intitule, tags_list, cree_le, item.doc_id)
|
||||
liste.append(d)
|
||||
|
||||
return {
|
||||
'page_title': "Contenu de %s" % topic.upper(),
|
||||
'topic': topic,
|
||||
'dt_data': json.dumps(liste),
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_edit', renderer='../templates/contents/doc_edit.pt', permission='view')
|
||||
def doc_edit(request):
|
||||
topic = request.matchdict['topic']
|
||||
doc_id = request.matchdict['doc_id']
|
||||
url = request.route_url('doc_edit', topic=topic, doc_id=doc_id)
|
||||
logged_in = request.authenticated_userid
|
||||
|
||||
# si anonyme, interdire de modifier les docs
|
||||
if isAnonymous(request):
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
message = ""
|
||||
|
||||
statuts = ['private', 'public']
|
||||
|
||||
if doc_id == '0':
|
||||
titre = "Nouveau doc"
|
||||
# nouveau
|
||||
doc = {}
|
||||
doc['intitule'] = ''
|
||||
doc['texte'] = ''
|
||||
doc['topic'] = topic
|
||||
doc['statut'] = 'private'
|
||||
tags = {}
|
||||
else:
|
||||
titre = "Modifier : %s" % str(doc_id)
|
||||
doc = get_docs(request, doc_id)
|
||||
tags = get_docs_tags(request, doc.doc_id)
|
||||
|
||||
d_tags = get_d_tags_manquant(request, topic, doc_id)
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
new_values = {}
|
||||
for param, db_value in doc.items():
|
||||
if param in request.params and request.params[param] != db_value:
|
||||
new_values[param] = request.params[param]
|
||||
|
||||
if new_values:
|
||||
new_values['topic'] = topic
|
||||
update_doc(request, doc_id, new_values)
|
||||
if doc_id != '0':
|
||||
return HTTPFound(location=request.route_url('doc_view', doc_id=doc_id))
|
||||
else:
|
||||
return HTTPFound(location=request.route_url('folder',topic=topic))
|
||||
|
||||
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." % doc.intitule, 'success')
|
||||
return HTTPFound(location=request.route_url('folder',topic=topic))
|
||||
|
||||
return {
|
||||
'page_title': titre,
|
||||
'url': url,
|
||||
'message': message,
|
||||
'doc_id': doc_id,
|
||||
'doc': doc,
|
||||
'topic': topic,
|
||||
'tags': tags,
|
||||
'd_tags': d_tags,
|
||||
'statuts': statuts,
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_search', renderer='../templates/contents/doc_search.pt')
|
||||
def doc_search(request):
|
||||
|
||||
logged_in = request.authenticated_userid
|
||||
critere = ''
|
||||
liste=[]
|
||||
|
||||
if 'form.submitted' in request.params:
|
||||
critere = request.params['critere']
|
||||
# si afficher tous les fiches ?
|
||||
items = get_docs_bycritere(request, critere, logged_in)
|
||||
|
||||
# construire la liste
|
||||
for item in items:
|
||||
# lire le(s) tag(s) du documents
|
||||
tags = get_docs_tags(request, item.doc_id)
|
||||
tags_list = ''
|
||||
for tag in tags:
|
||||
tags_list += tag.tag + ', '
|
||||
|
||||
cree_le = item.cree_le.strftime('%d/%m/%Y')
|
||||
d = (item.intitule, tags_list, cree_le, item.doc_id)
|
||||
liste.append(d)
|
||||
|
||||
return {
|
||||
'page_title': "Rechercher",
|
||||
'dt_data': json.dumps(liste),
|
||||
'critere': critere,
|
||||
}
|
||||
|
||||
@view_config(route_name='doc_view', renderer='../templates/contents/doc_view.pt')
|
||||
def doc_view(request):
|
||||
|
||||
doc_id = request.matchdict['doc_id']
|
||||
|
||||
# lire le document
|
||||
doc = get_docs(request, doc_id)
|
||||
|
||||
# si anonyme, interdire de voir les docs privés
|
||||
if isAnonymous(request) and doc.statut == 'private':
|
||||
return HTTPFound(location=request.route_url('home'))
|
||||
|
||||
if doc_id == '2':
|
||||
# mouvements portfolio, retour vers portfolio
|
||||
url_retour = request.route_url('portfolio')
|
||||
else:
|
||||
url_retour = request.route_url('folder',topic=doc.topic)
|
||||
|
||||
tags = get_docs_tags(request, doc.doc_id)
|
||||
|
||||
# insèrer le path de static/img
|
||||
texte = doc.texte.replace('static/img/', "%s/static/img/" % request.application_url)
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user