Niklas Brachmann
11 years ago
6 changed files with 94 additions and 7 deletions
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
from django.core.management.base import NoArgsCommand, CommandError |
||||
from cash.models import * |
||||
from django.utils.translation import ugettext as _ |
||||
from django.template.loader import get_template |
||||
from django.template import Context |
||||
from django.utils import translation |
||||
from django.utils.dateformat import DateFormat |
||||
from django.utils.formats import get_format |
||||
from django.core.mail import send_mass_mail |
||||
import datetime |
||||
|
||||
RANGE = 24 |
||||
USERSETTINGS_URL = 'https://cypher/kasse/usersettings/' |
||||
|
||||
class Command(NoArgsCommand): |
||||
help = 'Sends out the daily digest to all users with transactions in the last %dh' % RANGE |
||||
|
||||
def handle_noargs(self, **options): |
||||
translation.activate('de') |
||||
|
||||
tpl = get_template('cash/daily_digest.txt') |
||||
|
||||
messages = [] |
||||
for a in Account.objects.all(): |
||||
context = {'name': '%s %s' % (a.user.first_name, a.user.last_name), |
||||
'credit': a.credit, |
||||
'range': RANGE, |
||||
'url': USERSETTINGS_URL} |
||||
|
||||
transactions = Transaction.objects.filter(account = a).filter(timestamp__gte = datetime.datetime.now() - datetime.timedelta(hours = RANGE)) |
||||
|
||||
if transactions.count() > 0: |
||||
lengths = {'timestamp': len(_('date')), 'description': len(_('subject')), 'amount': len(_('amount'))} |
||||
sum = 0 |
||||
for t in transactions: |
||||
lengths['timestamp'] = max(lengths['timestamp'], len(DateFormat(t.timestamp).format(get_format('SHORT_DATETIME_FORMAT')))) |
||||
lengths['description'] = max(lengths['description'], len(t.description)) |
||||
lengths['amount'] = max(lengths['amount'], len(str(t.amount))) |
||||
t.description = t.description.split('\n') |
||||
|
||||
sum += t.amount |
||||
|
||||
lengths['sum'] = lengths['timestamp'] + lengths['description'] + lengths['amount'] |
||||
context['lengths'] = lengths |
||||
context['tl'] = transactions |
||||
context['sum'] = sum |
||||
|
||||
messages.append((_('Account Statement'), tpl.render(Context(context)), 'cypher@lug-saar.de', ['%s %s <%s>' % (a.user.first_name, a.user.last_name, a.user.email)])) |
||||
|
||||
send_mass_mail(tuple(messages)) |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
{% load i18n %} |
||||
Hallo, {{ name }}! |
||||
|
||||
du erhältst diese automatisch generierte Mail des Kassensystems, da es |
||||
innerhalb der letzten {{ range }} Stunden folgende Bewegungen auf deinem Konto gab: |
||||
|
||||
|
||||
{{ "Datum"|ljust:lengths.timestamp }} {{ "Betreff"|ljust:lengths.description }} {{ "Betrag"|rjust:lengths.amount }} |
||||
{% for t in tl %} |
||||
{{ t.timestamp|date:"SHORT_DATETIME_FORMAT"|ljust:lengths.timestamp }} {% trans t.subject|ljust:lengths.description %} {{ t.amount|floatformat:2|rjust:lengths.amount }}€ |
||||
{% for line in t.description %}{{ ""|ljust:lengths.timestamp }} {{ line }}{% endfor %} |
||||
{% endfor %} |
||||
{{ "------------"|rjust:lengths.sum }} |
||||
{{ sum|floatformat:2|rjust:lengths.sum }}€ |
||||
|
||||
Dein aktuelles Guthaben beträgt {{ credit|floatformat:2 }}€. |
||||
|
||||
Es grüßt |
||||
das Kassensystem |
||||
|
||||
PS: Wenn du diese Mail in Zukunft nicht mehr erhalten, oder andere Einstellungen |
||||
ändern möchtest, so kannst du das auf der folgenden Seite tun: |
||||
{{ url }} |
||||
(im internen Netzwerk des Vereins) |
Loading…
Reference in new issue