def nuitparminute(request):
#lieu = SunTimes(longitude, latitude, altitude, zone)
lieu = SunTimes(longitude, latitude, altitude)
maintenant = local_tz.localize(datetime.now()) #voir http://pytz.sourceforge.net/
lever = lieu.riselocal(maintenant)
coucher = lieu.setlocal(maintenant)
coucherHier = lieu.setlocal(maintenant - timedelta(1))
leverDemain = lieu.riselocal(maintenant + timedelta(1))
if lever <= maintenant <= coucher:
#On est en journée ; on sélectionne les photos allant du coucher de la veille au lever de ce jour
night_photo_list = Photo.objects.filter(appareil=3).filter(date__gt=coucherHier, date__lt=lever).order_by('-date')
horaire = [lever.strftime('%Hh %Mmn'), lever.day, lever.month, coucherHier.strftime('%Hh %Mmn'), coucherHier.day, coucherHier.month]
elif maintenant < lever:
#On est après minuit, mais avant le lever. On sélectionne les photos de coucherHier à maintenant
night_photo_list = Photo.objects.filter(appareil=3).filter(date__gt=coucherHier).order_by('-date')
horaire = [lever.strftime('%Hh %Mmn'), lever.day, lever.month, coucherHier.strftime('%Hh %Mmn'), coucherHier.day, coucherHier.month]
else:
#On est avant minuit mais après le coucher. On sélectionne les photos de coucher à maintenant
night_photo_list = Photo.objects.filter(appareil=3).filter(date__gt=coucher).order_by('-date')
horaire = [leverDemain.strftime('%Hh %Mmn'), leverDemain.day, leverDemain.month, coucher.strftime('%Hh %Mmn'), coucher.day, coucher.month]
context = {
'night_photo_list': night_photo_list,
'horaire': horaire
}
return render(request, "{}/nuitParMinute.html".format(appli), context)
{% extends "camera/base.html" %}
{% load static %}
{% block header %}
<h1 class="monh1">La nuit heure par heure</h1>
<pre>
Coucher : {% if horaire %}{{ horaire.3 }} - le {{horaire.4}}/{{horaire.5}}{% endif %}
Lever : {% if horaire %}{{ horaire.0 }} - le {{horaire.1}}/{{horaire.2}}{% endif %}
</pre>
{% endblock %}
{% block content %}
<table>
<tr>
{% for photo in night_photo_list %}
<td>
<a href="{% static photo.file_photo_jpg %}">
<img class="centre-image imgresponsive" src="{% static photo.file_photo_jpg %}" height="150" width="225" alt="photo nocturne indisponible"/><figcaption>{{photo.name}} - {{photo.appareil}}</figcaption>
</a>
</td>
{% if forloop.last %}
</tr>
{% else %}
{% if forloop.counter|divisibleby:"3" %}
</tr><tr>
{% endif %}
{% endif %}
{% endfor %}
</table>
{% endblock %}