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:
@@ -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):
|
||||||
"""
|
"""
|
||||||
|
@@ -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], \
|
||||||
|
Reference in New Issue
Block a user