...
 
Commits (2)
nobody.jpg

1.69 KB

{% 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>Exports de trombinoscopes à imprimer</h1>
<form method="post" action="">
<fieldset><legend>Options</legend>
{% csrf_token %}
<label for="laclasse">Sélection :</label>
<select id="laclasse" name="laclasse">
{% for c in lesclasses %}
<option>{{c}}</option>
{% endfor %}
</select>
</fieldset>
<input type="submit" value="Télécharger le trombinoscope"/>
</form>
</body>
</html>
<!--
Local Variables:
mode: nxml
End:
-->
......@@ -28,6 +28,12 @@ class PhotoWithTitle:
self._title=title
return
def __str__(self):
return "%s: %s" %(self._title, self._photo)
def __lt__(self, other):
return self._title.upper() < other._title.upper()
@property
def photo(self):
return self._photo
......@@ -53,6 +59,9 @@ class Trombi:
self._photos=photos
return
def __str__(self):
return "Trombi({}: [{}])".format(self._title, ", ".join([str(p) for p in self._photos]))
@property
def title(self):
return self._title
......@@ -114,7 +123,6 @@ def pageGen(template=None, trombi=None):
i=1
for pwt in trombi.photos:
# insertion de la photo
print("GRRR", i)
image=cells[i].getElementsByTagName("draw:image")[0]
target=hashImageFileName(pwt.photo)
image.setAttribute("xlink:href", target)
......@@ -131,7 +139,6 @@ def pageGen(template=None, trombi=None):
# limitation aux cases du tableau !
if i > maxPhotos:
# on ajoute un tableau neuf au bout quand le précédent est plein
print("GRRR, on ajoute un tableau neuf au bout")
table1=deepcopy(table0)
theText=page.getElementsByTagName("office:text")[0]
theText.appendChild(table1)
......
......@@ -6,7 +6,7 @@ from .autoretouche import jpgPrefix, FaceImage
from .forms import ImportCsvForm
from photodb.settings import BASE_DIR, MEDIA_ROOT
import re, os, base64, uuid, csv, json, io
from .trombi import Trombi, PhotoWithTitle, pageGen
def json_response(F):
"""
......@@ -405,5 +405,38 @@ def trombi(request):
Export de trombinoscopes sous forme de fichiers ODT ou HTML
autonomes
"""
return render(request,"pose/trombi.html",{
})
tout="Toutes les photos"
rien="Photos sans classe"
if request.method=="POST":
laclasse=request.POST.get("laclasse")
if laclasse==tout:
persons=Person.objects.all()
elif laclasse == rien:
persons=Person.objects.filter(className__isnull=True)
else:
persons=Person.objects.filter(className=laclasse)
trombi=Trombi(
laclasse,
sorted(
[PhotoWithTitle(
os.path.join(MEDIA_ROOT, os.path.basename(p.photo.url)),
"%s %s" %(p.lastName, p.firstName))
for p in persons if p.photo] + \
[PhotoWithTitle(
os.path.join(BASE_DIR, "nobody.jpg"),
"%s %s" %(p.lastName, p.firstName))
for p in persons if not p.photo]
)
)
zipIO=pageGen(trombi=trombi)
return HttpResponse(zipIO.read(), content_type="application/vnd.oasis.opendocument.text")
else:
persons=Person.objects.all()
lesclasses=[tout] + \
sorted(list({p.className for p in persons}-{None})) + \
[rien]
print("GRRRR lesclasses=", lesclasses)
return render(request, "pose/trombi.html",{
"lesclasses": lesclasses,
})