mirror of
				https://gitlab.crans.org/bde/nk20-scripts
				synced 2025-10-30 06:49:50 +01:00 
			
		
		
		
	Plain text mode in reports
This commit is contained in:
		| @@ -14,12 +14,19 @@ from note.tables import HistoryTable | |||||||
|  |  | ||||||
|  |  | ||||||
| class Command(BaseCommand): | class Command(BaseCommand): | ||||||
|  |     def add_arguments(self, parser): | ||||||
|  |         parser.add_argument('--notes', '-n', type=int, nargs='+', help='Select note ids') | ||||||
|  |         parser.add_argument('--debug', '-d', action='store_true', help='Debug mode, print mails in stdout') | ||||||
|  |  | ||||||
|     def handle(self, *args, **options): |     def handle(self, *args, **options): | ||||||
|         activate('fr') |         activate('fr') | ||||||
|         notes = NoteUser.objects.filter( |         if "notes" in options: | ||||||
|             user__memberships__date_end__gte=timezone.now(), |             notes = NoteUser.objects.filter(pk__in=options["notes"]).all() | ||||||
|             user__profile__report_frequency__gt=0, |         else: | ||||||
|         ).distinct().all() |             notes = NoteUser.objects.filter( | ||||||
|  |                 user__memberships__date_end__gte=timezone.now(), | ||||||
|  |                 user__profile__report_frequency__gt=0, | ||||||
|  |             ).distinct().all() | ||||||
|         for note in notes: |         for note in notes: | ||||||
|             now = timezone.now() |             now = timezone.now() | ||||||
|             last_report = note.user.profile.last_report |             last_report = note.user.profile.last_report | ||||||
| @@ -41,11 +48,16 @@ class Command(BaseCommand): | |||||||
|             context = dict( |             context = dict( | ||||||
|                 user=note.user, |                 user=note.user, | ||||||
|                 table=table, |                 table=table, | ||||||
|  |                 last_transactions=last_transactions, | ||||||
|                 incoming=incoming, |                 incoming=incoming, | ||||||
|                 outcoming=outcoming, |                 outcoming=outcoming, | ||||||
|                 diff=incoming - outcoming, |                 diff=incoming - outcoming, | ||||||
|                 now=now, |                 now=now, | ||||||
|                 last_report=last_report, |                 last_report=last_report, | ||||||
|             ) |             ) | ||||||
|  |             plain = render_to_string("note/mails/weekly_report.txt", context) | ||||||
|             html = render_to_string("note/mails/weekly_report.html", context) |             html = render_to_string("note/mails/weekly_report.html", context) | ||||||
|             note.user.email_user("[Note Kfet] Rapport de la Note Kfet", html, html_message=html) |             if options["debug"]: | ||||||
|  |                 self.stdout.write(plain) | ||||||
|  |             else: | ||||||
|  |                 note.user.email_user("[Note Kfet] Rapport de la Note Kfet", plain, html_message=html) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user