diff --git a/notifications/models.py b/notifications/models.py index 7ec9c35e5c..7e0dff14ed 100644 --- a/notifications/models.py +++ b/notifications/models.py @@ -1,3 +1,4 @@ +import datetime from django.db import models from django.forms import ModelForm, Textarea @@ -9,6 +10,7 @@ class UserNotification(models.Model): to_user = models.EmailField(db_index=True, max_length=255) msg_type = models.CharField(db_index=True, max_length=30) detail = models.TextField() + timestamp = models.DateTimeField(default=datetime.datetime.now) class NotificationForm(ModelForm): """ diff --git a/tools/user_notification.py b/tools/user_notification.py index ed33e0f7f3..26f16cebf7 100755 --- a/tools/user_notification.py +++ b/tools/user_notification.py @@ -1,6 +1,7 @@ #!/usr/bin/python # encoding: utf-8 +from datetime import datetime import string from django.core.mail import send_mail @@ -17,6 +18,7 @@ ${msg_url} Seafile团队 ''' +today = datetime.now() subject = u'SeaCloud:新消息' url = 'http://localhost:8000/home/my/' @@ -24,6 +26,9 @@ notifications = UserNotification.objects.all() d = {} for e in notifications: + if today.year != e.timestamp.year or today.month != e.timestamp.month or \ + today.day != e.timestamp.day: + continue if d.has_key(e.to_user): d[e.to_user] += 1 else: @@ -32,7 +37,7 @@ for e in notifications: for k in d.keys(): to_user = k cnt = d[k] - + 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], \