| Total Complexity | 2 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | #!/usr/bin/env python |
||
| 14 | class Command(BaseCommand): |
||
| 15 | |||
| 16 | help = 'Trigger all data from cache in version 2' |
||
| 17 | |||
| 18 | def handle(self, *args, **options): |
||
| 19 | """ |
||
| 20 | get all the digest data to send to each user |
||
| 21 | """ |
||
| 22 | now = arrow.utcnow().to(settings.TIME_ZONE) |
||
| 23 | now = now.date() |
||
| 24 | |||
| 25 | digest = Digest.objects.filter(date_end=str(now)).order_by('user', |
||
| 26 | 'date_end') |
||
| 27 | users = digest.distinct('user') |
||
| 28 | |||
| 29 | subject = 'Your digester' |
||
| 30 | |||
| 31 | msg_plain = render_to_string('digest/email.txt', |
||
| 32 | {'digest': digest, |
||
| 33 | 'subject': subject}) |
||
| 34 | msg_html = render_to_string('digest/email.html', |
||
| 35 | {'digest': digest, |
||
| 36 | 'subject': subject}) |
||
| 37 | message = msg_plain |
||
| 38 | from_email = settings.ADMINS |
||
| 39 | recipient_list = () |
||
| 40 | for user in users: |
||
| 41 | recipient_list += (user.user.email,) |
||
| 42 | |||
| 43 | send_mail(subject, message, from_email, recipient_list, |
||
| 44 | html_message=msg_html) |
||
| 45 |