mirror of
				https://gitlab.crans.org/bde/nk20-scripts
				synced 2025-10-31 07:09:52 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
 | |
| # SPDX-License-Identifier: GPL-3.0-or-later
 | |
| 
 | |
| from datetime import date, timedelta
 | |
| 
 | |
| from django.core.mail import send_mail
 | |
| from django.core.management import BaseCommand
 | |
| from django.template.loader import render_to_string
 | |
| from django.utils.translation import activate
 | |
| from food.models import Food
 | |
| from member.models import Club
 | |
| 
 | |
| 
 | |
| class Command(BaseCommand):
 | |
|     def add_arguments(self, parser):
 | |
|         parser.add_argument("--report", "-r", action='store_true', help="Report the list of food to GCKs")
 | |
|         parser.add_argument("--club", "-c", action='store_true', help="Report the list of food to club")
 | |
| 
 | |
|     def handle(self, *args, **options):
 | |
|         activate('fr')
 | |
|         
 | |
|         foods = Food.objects.filter(end_of_life='').order_by('expiry_date').distinct().all()
 | |
| 
 | |
|         if options["report"]:
 | |
|             plain_text = render_to_string("scripts/food_report.txt", context=dict(foods=foods))
 | |
|             html = render_to_string("scripts/food_report.html", context=dict(foods=foods))
 | |
|             send_mail("[Note Kfet] Liste de la nourriture à la Kfet", plain_text, "Note Kfet 2020 <notekfet2020@crans.org>",
 | |
|                       recipient_list=["respo-info.bde@lists.crans.org", "gck.bde@lists.crans.org"],
 | |
|                       html_message=html)
 | |
| 
 | |
|         if options["club"]:
 | |
|             for club in Club.objects.all():
 | |
|                 if Food.objects.filter(end_of_life='', owner=club).count() > 0:
 | |
|                     plain_text = render_to_string("scripts/food_report.txt",
 | |
|                                                   context=dict(foods=foods.filter(owner=club)))
 | |
|                     html = render_to_string("scripts/food_report.html",
 | |
|                                             context=dict(foods=foods.filter(owner=club)))
 | |
|                     send_mail("[Note Kfet] Liste de la nourriture de votre club", plain_text, "Note Kfet 2020 <notekfet2020@crans.org>",
 | |
|                               recipient_list=[club.email],
 | |
|                               html_message=html)
 | |
| 
 |