...
 
Commits (3)
......@@ -109,8 +109,36 @@ dd {
.vignette {
display: inline-block;
box-shadow: 5px 2px 2px grey;
border-radius: 0.5em;
padding: 0.5em;
}
.vignette img {
width: 8em;
}
#vignettesIndex {
width:800px;
margin: 20px auto;
}
#inlineVignetteFrame {
width: 100%;
height: 400px;
box-shadow: 10px 5px 5px grey;
border-radius: 1em;
padding: 1em;
}
.export {
display: inline-block;
box-shadow: 10px 5px 5px grey;
border-radius: 1em;
padding: 1em;
}
.export.current {
box-shadow: 10px 5px 5px orange;
background: lightcyan;
}
jQuery(document).ready(function () {
$("#loading").hide();
});
function showLoading(){
$("#loading").show();
return true;
}
/**
* set the default export to show
**/
function defaultExport(el){
var id = el.getAttribute("data-id");
$("#export_id").val(id);
$("form").first().submit();
}
/**
* set an export to delete
**/
function deleteExport(el){
var id = el.getAttribute("data-id");
$("#export_id").val(id);
$("#must_delete").val(1);
$("form").first().submit();
}
{% load static %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Export pour Pronote</title>
<script src="{% static 'jquery.js' %}" type="text/javascript"></script>
<link rel="stylesheet" href="{% static 'jquery-ui-themes/smoothness/jquery-ui.css' %}"/>
<script src="{% static 'jquery-ui/jquery-ui.js' %}" type="text/javascript"></script>
<script type="text/javascript" src="{% static 'pourPronote.js' %}"></script>
<link rel="stylesheet" href="{% static 'portrait.css' %}" type="text/css"/>
<link rel="stylesheet" type="text/css" href="{% static '/admin/css/base.css' %}" />
</head>
<body>
<h1>Photos du dossier <b>{{destdir}}</b></h1>
<div id="vignettes">
{% for v in vignettes %}
<div class="vignette">
<img src="{{v.url}}" alt="{{v.prenom}} {{v.nom}}"/> <br/>
{{v.prenom}} <b>{{v.nom}}</b>
</div>
{% endfor %}
</div>
</body>
</html>
<!--
Local Variables:
mode: nxml
End:
-->
......@@ -7,30 +7,53 @@
<script src="{% static 'jquery.js' %}" type="text/javascript"></script>
<link rel="stylesheet" href="{% static 'jquery-ui-themes/smoothness/jquery-ui.css' %}"/>
<script src="{% static 'jquery-ui/jquery-ui.js' %}" type="text/javascript"></script>
<script type="text/javascript" src="{% static 'importeCSV.js' %}"></script>
<script type="text/javascript" src="{% static 'pourPronote.js' %}"></script>
<link rel="stylesheet" href="{% static 'portrait.css' %}" type="text/css"/>
<link rel="stylesheet" type="text/css" href="{% static '/admin/css/base.css' %}" />
</head>
<body>
{{grrr}}
<form action="" method="post" onsubmit="return showLoading()">
<fieldset>
<legend>Exports pour Pronote</legend>
{% csrf_token %}
<div id="exports">
{% for e in exports %}
<div class="export {% if e.pk == currentexport %}current{% endif %}">
{{e.directory}}<br/>
{{e.modifDate}}<br/>
{{e.comment}}<br/>
<button onclick="defaultExport(this)" data-id="{{e.pk}}">
Choisir cet export
</button><br/>
<button onclick="deleteExport(this)" data-id="{{e.pk}}">
Effacer cet export
</button><br/>
</div>
{% endfor %}
</div>
<input type="hidden" name="export_id" id="export_id" value="0"/>
<input type="hidden" name="must_delete" id="must_delete" value="0"/>
<input type="hidden" name="current_export" id="current_export" value="{{currentexport}}"/>
<input type="submit" value="Nouvel export"/>
</fieldset>
</form>
<div id="footer">
<h3>Liens :</h3>
<ul>
<li>Photos exportées dans le dossier <b>{{destdir}}</b></li>
<li><a href="/">Retour à la page d'accueil</a></li>
</ul>
</div>
<div id="loading">
<img src="{% static 'loading.gif' %}" alt="loading"/>
</div>
<div id="vignettes">
{% for v in vignettes %}
<div class="vignette">
<img src="{{v.url}}" alt="{{v.prenom}} {{v.nom}}"/> <br/>
{{v.prenom}} <b>{{v.nom}}</b>
</div>
{% endfor %}
{% if currentexport %}
<div id="vignettesIndex">
<iframe id="inlineVignetteFrame"
title="Vignettes"
src="{{url}}/index.html">
</iframe>
</div>
{% endif %}
</body>
</html>
<!--
......
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse
from django.utils import timezone
from .models import Person
from .models import Person, Export
from .autoretouche import jpgPrefix, FaceImage
from .forms import ImportCsvForm
from photodb.settings import BASE_DIR
from photodb.settings import BASE_DIR, MEDIA_ROOT
import re, os, base64, uuid, csv, json, io
......@@ -318,31 +318,85 @@ def pourPronote(request):
Exports the photos into a directory, as expected by the software
Pronote.
"""
from tempfile import mkdtemp
from subprocess import call
persons=Person.objects.all()
destdir=mkdtemp(prefix='Pronote_')
exports=Export.objects.filter(flavor=1) # 1 is Pronote, see models.py
if "export_id" not in request.POST:
#no usable export so far
return render(request,"pose/pourPronote.html",{
"destdir": "",
"exports": exports,
})
vignettes=[]
for p in persons:
nom=p.lastName
prenom=p.firstName
photo=p.photo
if photo and nom and prenom:
path=os.path.join(BASE_DIR, "photos", os.path.basename(photo.path))
target="{prenom}.{nom}.jpg".format(
prenom=protege(sansAccent(prenom)).lower(),
nom=protege(sansAccent(nom)).lower(),
if request.POST.get("export_id")=="0":
# create a completely new export
now=timezone.now()
date=now.strftime("%Y-%m-%d+%H-%M-%S")
directory="Pronote-"+date
export=Export(
directory = directory,
modifDate = now,
flavor = 1, # Pronote
comment="no comment",
)
export.save()
persons=Person.objects.all()
destdir=os.path.join(MEDIA_ROOT,directory)
os.makedirs(destdir, exist_ok=True)
for p in persons:
nom=p.lastName
prenom=p.firstName
photo=p.photo
if photo and nom and prenom:
path=os.path.join(BASE_DIR, "photos", os.path.basename(photo.path))
target="{prenom}.{nom}.jpg".format(
prenom=protege(sansAccent(prenom)).lower(),
nom=protege(sansAccent(nom)).lower(),
)
cmd="cp {p} {t}".format(
p=path, t=os.path.join(destdir, target))
call(cmd, shell=True)
vignettes.append({
"nom": nom,
"prenom": prenom,
"url": target,
})
indexPage=render(request,"pose/dirPronoteContent.html",{
"destdir": destdir+"/",
"vignettes" : vignettes,
})
with open(os.path.join(
BASE_DIR, "photos",export.directory,"index.html"),"w"
) as outfile:
outfile.write(indexPage.content.decode("utf-8"))
else: # request.POST.get("export_id")!="0"
export=Export.objects.get(pk=int(request.POST.get("export_id")))
if request.POST.get("must_delete")=="1":
# erase the directory of this export
cmd="rm -rf {path}".format(
path=os.path.join(BASE_DIR,"photos",export.directory)
)
cmd="cp {p} {t}".format(
p=path, t=os.path.join(destdir, target))
print("GRRRR", cmd)
call(cmd, shell=True)
vignettes.append({
"nom": nom,
"prenom": prenom,
"url": photo.url,
})
export.delete()
# should we still show a directory's content?
ce=request.POST.get("current_export","")
ei=request.POST.get("export_id")
if ce and ce!="0" and ce!=ei:
export=Export.objects.get(pk=int(ce))
else:
export=None
else:
pass # nothing to do, the export is already the right one
exports=Export.objects.filter(flavor=1) # 1 is Pronote, see models.py
url=os.path.join('/photos', export.directory) if export else None
destdir=os.path.join(MEDIA_ROOT,export.directory)+"/" if export else None
currentexport=export.pk if export else 0
return render(request,"pose/pourPronote.html",{
"destdir": destdir+"/",
"vignettes" : vignettes,
"exports" : exports,
"url": url,
"destdir": destdir,
"currentexport": currentexport,
})