Browse Source

Added command and template to send out daily digest

master
Niklas Brachmann 11 years ago
parent
commit
8c5deca83a
  1. 22
      cash/locale/de/LC_MESSAGES/django.po
  2. 0
      cash/management/__init__.py
  3. 0
      cash/management/commands/__init__.py
  4. 50
      cash/management/commands/dailydigest.py
  5. 24
      cash/templates/cash/daily_digest.txt
  6. 5
      lugcash2/settings.py

22
cash/locale/de/LC_MESSAGES/django.po

@ -8,7 +8,7 @@ msgid "" @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-09-13 16:05+0200\n"
"POT-Creation-Date: 2013-09-15 21:30+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -51,11 +51,11 @@ msgstr "Autorisiert von %(first)s %(last)s" @@ -51,11 +51,11 @@ msgstr "Autorisiert von %(first)s %(last)s"
msgid "card number"
msgstr "Kartennummer"
#: models.py:14 views.py:80
#: models.py:14 views.py:81
msgid "PIN"
msgstr "PIN"
#: models.py:15 views.py:76 templates/cash/usersettings.html:10
#: models.py:15 views.py:77 templates/cash/usersettings.html:10
msgid "daily digest"
msgstr "Tägliche Zusammenfassung"
@ -119,7 +119,7 @@ msgstr "Strichcodes" @@ -119,7 +119,7 @@ msgstr "Strichcodes"
msgid "timestamp"
msgstr "Zeitstempel"
#: models.py:127
#: models.py:127 management/commands/dailydigest.py:33
msgid "subject"
msgstr "Betreff"
@ -127,7 +127,7 @@ msgstr "Betreff" @@ -127,7 +127,7 @@ msgstr "Betreff"
msgid "description"
msgstr "Beschreibung"
#: models.py:130
#: models.py:130 management/commands/dailydigest.py:33
msgid "amount"
msgstr "Betrag"
@ -159,14 +159,22 @@ msgstr "Verkaufsprotokolleinträge" @@ -159,14 +159,22 @@ msgstr "Verkaufsprotokolleinträge"
msgid "Cancellation"
msgstr "Stornierung"
#: views.py:82
#: views.py:83
msgid "PIN (confirmation)"
msgstr "PIN (bestätigen)"
#: views.py:88
#: views.py:89
msgid "PINs do not match."
msgstr "PINs stimmen nicht überein."
#: management/commands/dailydigest.py:33
msgid "date"
msgstr "Datum"
#: management/commands/dailydigest.py:48
msgid "Account Statement"
msgstr "Kontoauszug"
#: templates/cash/base.html:27 templates/cash/base.html.py:53
msgid "Overview"
msgstr "Übersicht"

0
cash/management/__init__.py

0
cash/management/commands/__init__.py

50
cash/management/commands/dailydigest.py

@ -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))

24
cash/templates/cash/daily_digest.txt

@ -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)

5
lugcash2/settings.py

@ -191,3 +191,8 @@ AUTH_LDAP_FIND_GROUP_PERMS = True @@ -191,3 +191,8 @@ AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_staff": "cn=cashstaff,ou=group,dc=lug-saar,dc=spc"
}
# Use console output for testing
# TODO: change
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Loading…
Cancel
Save