...
 
Commits (9)
......@@ -10,12 +10,5 @@ clean:
find . -name "__pycache__" | xargs rm -rf
install:
install -d $(SERVERDIR)
cp *.py cherryApp.conf nobody.jpg updateDb.sh haarcascade_frontalface_default.xml $(SERVERDIR)
cp -a static templates $(SERVERDIR)
# fix the cherrypy configuration
sed -i 's%tools.staticdir.root.*%tools.staticdir.root = "/var/lib/photodb"%' $(SERVERDIR)/cherryApp.conf
install -d $(BINDIR)
cp photodbServer $(BINDIR)
.PHONY: all clean install
#!/usr/bin/python3
import os, sys, django
def usage() :
print("""\
Usage: $0 adminLoginName admin.email@example.com passwordForShell
parameters:
- adminLoginName the login name for the administrator
- admin.email@example.com the email address of the administrator
- passwordForShell a password; beware of characters not supported by sh""")
if __name__ == "__main__" :
if len(sys.argv) < 4:
usage()
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'photodb.settings')
django.setup()
from django.contrib.auth.models import User
user, _ =User.objects.get_or_create(username=sys.argv[1])
user.email=sys.argv[2]
user.set_password(sys.argv[3])
user.is_superuser=True
user.is_staff=True
user.last_name="Admin"
user.save()
print(user.last_name, user.email)
print("Superuser {} a été enregistré".format(user.username))
No preview for this file type
photodb (2.1-1) unstable; urgency=medium
* new upstream change: exports for Pronote
-- Georges Khaznadar <georgesk@debian.org> Thu, 28 Jun 2018 18:52:05 +0200
photodb (2.0-1) unstable; urgency=medium
* complete rewrite to django
......
......@@ -11,7 +11,7 @@ Package: photodb
Architecture: all
Depends: ${misc:Depends}, python3,
python3-dateutil, python3-tz, python3-odf,
python3-django, python3-django-filters, python3-django-python3-ldap
python3-django, python3-django-filters, python3-django-python3-ldap,
sqlite3,
libjs-jquery, libjs-jquery-ui, libjs-jquery-ui-theme-smoothness
Suggests: iceweasel|x-www-browser
......
......@@ -37,17 +37,19 @@ appDir=/var/lib/photodb
apacheConf=/etc/apache2/sites-available/photodb-django.conf
case "$1" in
configure)
## make a sample database if there is no database yet
[ -f /var/lib/photodb/db/names.db ] || \
cp /var/lib/photodb/db.sqlite3.sample /var/lib/photodb/db/names.db
## enable Apache's access
setfacl -m u:www-data:rwx /var/lib/photodb
setfacl -m u:www-data:rw /var/lib/photodb/db/names.db
chown www-data:www-data /var/lib/photodb
chown www-data:www-data /var/lib/photodb/db
chown www-data:www-data /var/lib/photodb/db/names.db
## enabling the production settings
cp $appDir/photodb/settings-prod.py $appDir/photodb/settings.py
## create the upload area
mkdir -p $appDir/photos
chown -R www-data:www-data $appDir/photos
chown www-data:www-data $appDir/photos
## create the database "photodb" and the role "photodb"
# cd $appDir; ./createDB1 "$dbPassword"
## recompile after the change in settings.py
......
......@@ -28,7 +28,7 @@ case "$1" in
db_purge
fi
# disable the website for apache2
if (which a2dissite); then a2dissite photodb-django; fi
if (which a2dissite); then a2dissite photodb-django; true; fi
# backup the database
# t=$(tempfile --directory /var/tmp --prefix photodb- --suffix .sql)
t=$(tempfile --directory /var/tmp --prefix photodb- --suffix .sqlite3)
......
......@@ -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,
})