Skip to content

Commit

Permalink
add: bookings reminder
Browse files Browse the repository at this point in the history
  • Loading branch information
vcardoneit committed Jan 21, 2024
1 parent 2088ea1 commit 10208ef
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- **Gestione prenotazioni**
- **API per inserire prenotazione - /api/addprt/**
- **Esportazione dati in CSV**
- **Promemoria prenotazioni via e-mail**

## Installation with Docker
#### Docker compose
Expand Down Expand Up @@ -72,6 +73,7 @@ volumes:
| `POSTGRES_USER` |
| `POSTGRES_PASSWORD` |
| `POSTGRES_DB` |
| `NOTIFYEMAIL` |

## Problems / Questions
<b>Email:</b> jupiter@vcardone.it
Expand Down
4 changes: 2 additions & 2 deletions donatori/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def esporta(request):
response = HttpResponse(content_type="text/csv", headers={"Content-Disposition": 'attachment; filename="donatori.csv"'})
lDonatori = mDonatori.objects.all()
writer = csv.writer(response)
writer.writerow(["tessera", "dataiscrizione", "grupposang", "nome", "cognome", "datadinascita", "luogodinascita", "codicefiscale", "indirizzo", "comune", "tel", "email"])
writer.writerow(["tessera", "codiceqr", "dataiscrizione", "grupposang", "nome", "cognome", "datadinascita", "luogodinascita", "codicefiscale", "indirizzo", "comune", "tel", "email", "privacy_a", "privacy_b", "privacy_c", "modReferti"])
for x in lDonatori:
writer.writerow([x.tessera, x.dataiscrizione, x.grupposang, x.nome, x.cognome, x.datadinascita, x.luogodinascita, x.codicefiscale, x.indirizzo, x.comune, x.tel, x.email])
writer.writerow([x.tessera, x.qrverify, x.dataiscrizione, x.grupposang, x.nome, x.cognome, x.datadinascita, x.luogodinascita, x.codicefiscale, x.indirizzo, x.comune, x.tel, x.email, x.privacy_a, x.privacy_b, x.privacy_c, x.modReferti])

return response
else:
Expand Down
1 change: 1 addition & 0 deletions jupiter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'prenotazioni',
'rest_framework',
'rest_framework_api_key',
'django_apscheduler',
]

MIDDLEWARE = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-01-21 10:57

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('prenotazioni', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='prenotazioni',
old_name='primadonazione',
new_name='analisieffettuate',
),
]
2 changes: 1 addition & 1 deletion prenotazioni/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class prenotazioni(models.Model):
nome = models.CharField(max_length=255)
telefono = models.CharField(max_length=255)
data = models.DateField(null=True)
primadonazione = models.CharField(max_length=255)
analisieffettuate = models.CharField(max_length=255)
2 changes: 1 addition & 1 deletion prenotazioni/templates/prenotazioni.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<th scope="col" class="text-center">Nome</th>
<th scope="col" class="text-center">Telefono</th>
<th scope="col" class="text-center">Data</th>
<th scope="col" class="text-center">Prima Donazione</th>
<th scope="col" class="text-center">Analisi effettuate</th>
</tr>
</thead>
<tbody>
Expand Down
34 changes: 34 additions & 0 deletions prenotazioni/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
from datetime import datetime, timedelta
from django.core.mail import EmailMessage
from .models import prenotazioni


def notificaPrenotazioni():
gg = datetime.now() + timedelta(days=1)
dbListaPrenotazioni = prenotazioni.objects.filter(data=gg.date())

if not dbListaPrenotazioni:
return

listaPrenotazioni = "<br>".join([f"<b>Nome:</b> {prenotazione.nome} - <b>Telefono:</b> {prenotazione.nome} - <b>Ha effettuato le analisi predonazione:</b> {prenotazione.analisieffettuate}" for prenotazione in dbListaPrenotazioni])

oggetto = "Prenotazioni donazione sangue " + gg.strftime("%d/%m/%Y")

corpo = f'Prenotazioni per la donazione del sangue di domani: <br><br>{listaPrenotazioni}'

notifyemail = os.environ.get('NOTIFYEMAIL', '')

if notifyemail:
listaEmail = notifyemail.split(',')
else:
listaEmail = []

email = EmailMessage(
oggetto,
corpo,
os.getenv("DEFAULT_FROM_EMAIL"),
listaEmail,
)
email.content_subtype = "html"
email.send()
18 changes: 17 additions & 1 deletion prenotazioni/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from .serializers import prenotazioniSer
from .models import prenotazioni
from idoneita.models import idoneita as lidoneita
from apscheduler.schedulers.background import BackgroundScheduler
from django_apscheduler.jobstores import DjangoJobStore, register_events, register_job
from .utils import notificaPrenotazioni


class addprt(APIView):
Expand Down Expand Up @@ -41,7 +44,7 @@ def conferma(request):
return redirect('prenotazioni')
else:
prenotazione = prenotazioni.objects.get(id=prenotazione)
if (prenotazione.primadonazione == "Si"):
if (prenotazione.analisieffettuate == "Si"):

idoneita = lidoneita.objects.create()
idoneita.nominativo = prenotazione.nome
Expand Down Expand Up @@ -75,3 +78,16 @@ def elimina(request):
return redirect('prenotazioni')
else:
return redirect("/")


scheduler = BackgroundScheduler()
scheduler.add_jobstore(DjangoJobStore(), "default")


@register_job(scheduler, "cron", day_of_week="thu", hour=14, id="jobNotificaPrt", replace_existing=True)
def jobNotifica():
notificaPrenotazioni()


register_events(scheduler)
scheduler.start()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ psycopg2-binary==2.9.9
pillow==10.1.0
qrcode==7.4.2
djangorestframework==3.14.0
djangorestframework_api_key==3.0.0
djangorestframework_api_key==3.0.0
django-apscheduler==0.6.2

0 comments on commit 10208ef

Please sign in to comment.