1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 19:01:42 +00:00

Add timestamp to user_notification

This commit is contained in:
xiez
2012-07-04 14:25:25 +08:00
parent 62c8aba292
commit bef3039a75
2 changed files with 8 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import datetime
from django.db import models from django.db import models
from django.forms import ModelForm, Textarea from django.forms import ModelForm, Textarea
@@ -9,6 +10,7 @@ class UserNotification(models.Model):
to_user = models.EmailField(db_index=True, max_length=255) to_user = models.EmailField(db_index=True, max_length=255)
msg_type = models.CharField(db_index=True, max_length=30) msg_type = models.CharField(db_index=True, max_length=30)
detail = models.TextField() detail = models.TextField()
timestamp = models.DateTimeField(default=datetime.datetime.now)
class NotificationForm(ModelForm): class NotificationForm(ModelForm):
""" """

View File

@@ -1,6 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# encoding: utf-8 # encoding: utf-8
from datetime import datetime
import string import string
from django.core.mail import send_mail from django.core.mail import send_mail
@@ -17,6 +18,7 @@ ${msg_url}
Seafile团队 Seafile团队
''' '''
today = datetime.now()
subject = u'SeaCloud新消息' subject = u'SeaCloud新消息'
url = 'http://localhost:8000/home/my/' url = 'http://localhost:8000/home/my/'
@@ -24,6 +26,9 @@ notifications = UserNotification.objects.all()
d = {} d = {}
for e in notifications: 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): if d.has_key(e.to_user):
d[e.to_user] += 1 d[e.to_user] += 1
else: else:
@@ -32,7 +37,7 @@ for e in notifications:
for k in d.keys(): for k in d.keys():
to_user = k to_user = k
cnt = d[k] cnt = d[k]
template = string.Template(email_template) template = string.Template(email_template)
content = template.substitute(username=to_user, cnt=cnt, msg_url=url) content = template.substitute(username=to_user, cnt=cnt, msg_url=url)
send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, [to_user], \ send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, [to_user], \