1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

Modify group msg notification

This commit is contained in:
xiez
2012-06-26 14:20:37 +08:00
parent 29eb8ad6c9
commit 5b39f73488
7 changed files with 42 additions and 19 deletions

View File

@@ -0,0 +1,5 @@
from signals import *
from handlers import *
from models import GroupMessage
grpmsg_added.connect(grpmsg_added_cb, sender=GroupMessage)

21
group/handlers.py Normal file
View File

@@ -0,0 +1,21 @@
from seaserv import ccnet_threaded_rpc
from signals import grpmsg_added
from seahub.notifications.models import UserNotification
def grpmsg_added_cb(sender, **kwargs):
group_id = kwargs['group_id']
from_email = kwargs['from_email']
l = UserNotification.objects.filter(msg_type='group_msg',
detail=group_id)
if len(l) == 0:
group_members = ccnet_threaded_rpc.get_group_members(int(group_id))
for m in group_members:
if from_email == m.user_name:
continue
n = UserNotification(to_user=m.user_name, msg_type='group_msg',
detail=group_id)
n.save()
else:
pass

View File

@@ -1,6 +1,8 @@
import datetime
from django.db import models
from seahub.notifications.models import UserNotification
class GroupMessage(models.Model):
group_id = models.IntegerField()
from_email = models.EmailField()

3
group/signals.py Normal file
View File

@@ -0,0 +1,3 @@
import django.dispatch
grpmsg_added = django.dispatch.Signal(providing_args=["group_id", "from_email"])

View File

@@ -12,6 +12,7 @@ from pysearpc import SearpcError
from models import GroupMessage, MessageReply
from forms import MessageForm
from signals import grpmsg_added
from seahub.contacts.models import Contact
from seahub.notifications.models import UserNotification
from seahub.utils import go_error, go_permission_error, validate_group_name
@@ -140,7 +141,7 @@ def render_group_info(request, group_id, form):
repos.append(repo)
# remove user notifications
UserNotification.objects.filter(email=request.user.username,
UserNotification.objects.filter(to_user=request.user.username,
detail=str(group_id)).delete()
"""group messages"""
@@ -234,18 +235,9 @@ def group_info(request, group_id):
# clear form data
form = MessageForm()
# add user notification if not exists
l = UserNotification.objects.filter(note_type='group_msg',
detail=group_id)
if len(l) == 0:
group_members = ccnet_threaded_rpc.get_group_members(int(group_id))
for m in group_members:
if request.user.username == m.user_name:
continue
n = UserNotification(email=m.user_name,
note_type='group_msg', detail=group_id)
n.save()
# send signal
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
from_email=request.user.username)
else:
form = MessageForm()

View File

@@ -6,9 +6,9 @@ class Notification(models.Model):
primary = models.BooleanField(default=False)
class UserNotification(models.Model):
email = models.EmailField(max_length=255)
note_type = models.CharField(max_length=30)
detail = models.CharField(max_length=100)
to_user = models.EmailField(max_length=255)
msg_type = models.CharField(max_length=30)
detail = models.TextField()
class NotificationForm(ModelForm):
"""

View File

@@ -547,9 +547,9 @@ def myhome(request):
# user notifications
l = []
notes = UserNotification.objects.filter(email=request.user.username)
notes = UserNotification.objects.filter(to_user=request.user.username)
for n in notes:
if n.note_type == 'group_msg':
if n.msg_type == 'group_msg':
l.append(n.detail)
# my groups