1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-01 03:25:39 +00:00
seahub/tools/user_notification.py

47 lines
1.0 KiB
Python
Raw Normal View History

2012-07-04 05:52:40 +00:00
#!/usr/bin/python
# encoding: utf-8
2012-07-04 06:25:25 +00:00
from datetime import datetime
2012-07-04 05:52:40 +00:00
import string
from django.core.mail import send_mail
from notifications.models import UserNotification
import settings
email_template = u'''${username}您好:
您有${cnt}条新消息请点击下面的链接查看
${msg_url}
感谢使用我们的网站
Seafile团队
'''
2012-07-04 06:25:25 +00:00
today = datetime.now()
2012-07-04 05:52:40 +00:00
subject = u'SeaCloud新消息'
url = 'http://localhost:8000/home/my/'
notifications = UserNotification.objects.all()
d = {}
for e in notifications:
2012-07-04 06:25:25 +00:00
if today.year != e.timestamp.year or today.month != e.timestamp.month or \
today.day != e.timestamp.day:
continue
2012-07-04 05:52:40 +00:00
if d.has_key(e.to_user):
d[e.to_user] += 1
else:
d[e.to_user] = 1
for k in d.keys():
to_user = k
cnt = d[k]
2012-07-04 06:25:25 +00:00
2012-07-04 05:52:40 +00:00
template = string.Template(email_template)
content = template.substitute(username=to_user, cnt=cnt, msg_url=url)
send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, [to_user], \
fail_silently=False)