diff options
author | Leif Johansson <leifj@sunet.se> | 2012-02-10 12:56:16 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2012-02-10 12:56:16 +0100 |
commit | 8c6b3e68a1866642a8c6e1366237f47f8392c916 (patch) | |
tree | 7fb75686af1a5018b358b18ecfed49061000ac77 | |
parent | ae821d0696be63c31bd5a325298cfa8eee3b48cb (diff) |
email sending and clean-room reminder
-rw-r--r-- | src/meetingtools/apps/room/tasks.py | 26 | ||||
-rw-r--r-- | src/meetingtools/settings.py | 3 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/meetingtools/apps/room/tasks.py b/src/meetingtools/apps/room/tasks.py index aff5332..6506cbf 100644 --- a/src/meetingtools/apps/room/tasks.py +++ b/src/meetingtools/apps/room/tasks.py @@ -16,6 +16,10 @@ import logging from datetime import datetime,timedelta from lxml import etree from django.db.models import Q +from django.contrib.humanize.templatetags import humanize +from meetingtools.apps.userprofile.models import profile +from django.core.mail import send_mail +from meetingtools.settings import NOREPLY, BASE_URL def _owner_username(api,sco): logging.debug(sco) @@ -194,7 +198,25 @@ def import_transactions(): except ObjectDoesNotExist: pass # we only care about rooms we know about here +@task(name="meetingtools.apps.room.tasks.mail") +def send_message(user,subject,message): + try: + p = user.get_profile() + if p and p.email: + send_mail(subject,message,NOREPLY,[p.email]) + else: + logging.info("User %s has no email address - email not sent" % user.username) + except ObjectDoesNotExist: + logging.info("User %s has no profile - email not sent" % user.username) + except Exception,exc: + send_message.retry(exc=exc) + +@periodic_task(run_every=crontab(hour="*", minute="*", day_of_week="*")) def clean_old_rooms(): for acc in ACCluster.objects.all(): - then = datetime.now() - timedelta(days=365) - then = then.replace(microsecond=0)
\ No newline at end of file + then = datetime.now() - timedelta(days=30) + then = then.replace(microsecond=0) + with ac_api_client(acc) as api: + for room in Room.objects.filter(lastvisited__lt=then): + logging.debug("room %s was last used %s" % (room.name,humanize.naturalday(room.lastvisited))) + send_message.apply_async([room.creator,"You have an unused meetingroom at %s" % BASE_URL,"Do you still need %s (%s)?" % (room.name,room.permalink())])
\ No newline at end of file diff --git a/src/meetingtools/settings.py b/src/meetingtools/settings.py index 4706503..34c5d5f 100644 --- a/src/meetingtools/settings.py +++ b/src/meetingtools/settings.py @@ -138,3 +138,6 @@ CARROT_BACKEND = "django" import djcelery djcelery.setup_loader() + +NOREPLY = "no-reply@sunet.se" +AUTH_PROFILE_MODULE = "userprofile.UserProfile"
\ No newline at end of file |