Permalink
Browse files

added notice when one of friends has a new friend, notices refactored

  • Loading branch information...
1 parent 765ebef commit 56a39402c8a74fc775fd606f67d3f16a4cd69690 @barszczmm committed Mar 18, 2012
View
@@ -2,16 +2,18 @@
from django.db.models import signals
from django.utils.translation import ugettext_noop as _
+from friends import settings as friends_settings
-if "notification" in settings.INSTALLED_APPS:
+
+if friends_settings.FRIENDS_USE_NOTIFICATION_APP and "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
- notification.create_notice_type("friends_invite", _("Invitation Received"), _("you have received an invitation"), default=1)
- notification.create_notice_type("friends_invite_sent", _("Invitation Sent"), _("you have sent an invitation"), default=1)
- notification.create_notice_type("friends_accept", _("Acceptance Received"), _("an invitation you sent has been accepted"), default=1)
- notification.create_notice_type("friends_accept_sent", _("Acceptance Sent"), _("you have accepted an invitation you received"), default=1)
- # TODO: create notifiaction about friend having new friend
+ notification.create_notice_type("friends_invite", _("Invitation Received"), _("You have received an invitation."), default=1)
+ notification.create_notice_type("friends_invite_sent", _("Invitation Sent"), _("You have sent an invitation."), default=1)
+ notification.create_notice_type("friends_accept", _("Acceptance Received"), _("An invitation you sent has been accepted."), default=1)
+ notification.create_notice_type("friends_accept_sent", _("Acceptance Sent"), _("You have accepted an invitation you received."), default=1)
+ notification.create_notice_type("friends_otherconnect", _("Other Connection"), _("One of your friends has a new friend."), default=1)
signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
View
@@ -2,7 +2,7 @@
from django.db import models
from django.db.models import Q
-from friends import signals as friends_signals
+from friends.signals import friendship_invitation_sent
class FriendshipManager(models.Manager):
@@ -35,7 +35,6 @@ class FriendshipInvitationManager(models.Manager):
def create_friendship_request(self, from_user, to_user, message=None):
inv = self.create(from_user=from_user, to_user=to_user, message=message or "")
- friends_signals.invitation_received.send(sender=None, from_user=from_user, to_user=to_user, invitation=inv)
- friends_signals.invitation_sent.send(sender=None, from_user=from_user, to_user=to_user, invitation=inv)
+ friendship_invitation_sent.send(sender=None, from_user=from_user, to_user=to_user, invitation=inv)
return inv
View
@@ -6,7 +6,7 @@
from friends.utils import get_datetime_now
from friends.managers import FriendshipManager, FriendshipInvitationManager
-from friends.signals import invitation_received, invitation_sent, acceptance_received, acceptance_sent
+from friends.signals import friendship_invitation_sent, friendship_acceptance_sent
from friends import settings as friends_settings
@@ -43,8 +43,7 @@ def accept(self):
if not Friendship.objects.are_friends(self.to_user, self.from_user):
friendship = Friendship(to_user=self.to_user, from_user=self.from_user)
friendship.save()
- acceptance_received.send(sender=None, from_user=self.from_user, to_user=self.to_user)
- acceptance_sent.send(sender=None, from_user=self.from_user, to_user=self.to_user)
+ friendship_acceptance_sent.send(sender=None, from_user=self.from_user, to_user=self.to_user)
self.delete()
def decline(self):
@@ -67,23 +66,24 @@ def delete_friendship(sender, instance, **kwargs):
else:
notification = None
-@receiver(invitation_received)
-def send_invitation_received_notification(sender, from_user, to_user, invitation, **kwargs):
- if notification:
- notification.send([to_user], "friends_invite", {"invitation": invitation})
-@receiver(invitation_sent)
+@receiver(friendship_invitation_sent, dispatch_uid="friends_send_invitation_sent_notification")
def send_invitation_sent_notification(sender, from_user, to_user, invitation, **kwargs):
if notification:
+ notification.send([to_user], "friends_invite", {"invitation": invitation})
notification.send([from_user], "friends_invite_sent", {"invitation": invitation})
-@receiver(acceptance_received)
-def send_acceptance_received_notification(sender, from_user, to_user, **kwargs):
- if notification:
- notification.send([from_user], "friends_accept", {"to_user": to_user})
-
-@receiver(acceptance_sent)
+@receiver(friendship_acceptance_sent, dispatch_uid="friends_send_acceptance_sent_notification")
def send_acceptance_sent_notification(sender, from_user, to_user, **kwargs):
if notification:
notification.send([to_user], "friends_accept_sent", {"from_user": from_user})
+ notification.send([from_user], "friends_accept", {"to_user": to_user})
+ for user in Friendship.objects.friends_for_user(to_user):
+ if user != from_user:
+ notification.send([user], "friends_otherconnect", {"your_friend": to_user, "new_friend": from_user})
+ for user in Friendship.objects.friends_for_user(from_user):
+ if user != to_user:
+ notification.send([user], "friends_otherconnect", {"your_friend": from_user, "new_friend": to_user})
+
+
View
@@ -1,7 +1,6 @@
from django.dispatch import Signal
-invitation_received = Signal(providing_args=["from_user", "to_user", "invitation"])
-invitation_sent = Signal(providing_args=["from_user", "to_user", "invitation"])
-acceptance_received = Signal(providing_args=["from_user", "to_user"])
-acceptance_sent = Signal(providing_args=["from_user", "to_user"])
-# TODO: create signal when friend id having new friend
+
+friendship_invitation_sent = Signal(providing_args=["from_user", "to_user", "invitation"])
+friendship_acceptance_sent = Signal(providing_args=["from_user", "to_user"])
+
@@ -1,2 +1,2 @@
-{% load i18n %}{% url profile_detail username=invitation.to_user.username as user_url %}
-{% blocktrans with invitation.to_user as invitation_user %}<a href="{{ user_url }}">{{ invitation_user }}</a> has accepted your friend request.{% endblocktrans %}
+{% load i18n %}
+{% blocktrans with invitation.to_user as invitation_to_user and invitation.to_user.get_profile.get_absolute_url as user_url %}<a href="{{ user_url }}">{{ invitation_to_user }}</a> has accepted your friend request.{% endblocktrans %}
@@ -1,2 +1,2 @@
-{% load i18n %}{% url profile_detail username=invitation.from_user.username as user_url %}
-{% blocktrans with invitation.from_user as invitation_from_user %}You accepted <a href="{{ user_url }}">{{ invitation_from_user }}</a>'s friend request.{% endblocktrans %}
+{% load i18n %}
+{% blocktrans with invitation.from_user as invitation_from_user and invitation.from_user.get_profile.get_absolute_url as user_url %}You accepted <a href="{{ user_url }}">{{ invitation_from_user }}</a>'s friend request.{% endblocktrans %}
@@ -1,4 +1,4 @@
-{% load i18n %}{% url invitations as invitation_page %}{% blocktrans with invitation.from_user as invitation_from_user %}{{ invitation_from_user }} has requested to add you as a friend. You can accept their invitation at:
+{% load i18n %}{% url friends_received_invitations as invitations_page %}{% blocktrans with invitation.from_user as invitation_from_user %}{{ invitation_from_user }} has requested to add you as a friend. You can accept their invitation at:
-http://{{ current_site }}{{ invitation_page }}
+http://{{ current_site }}{{ invitations_page }}
{% endblocktrans %}
@@ -1,2 +1,2 @@
-{% load i18n %}{% url invitations as invitation_page %}{% url profile_detail username=invitation.from_user.username as user_url %}
-{% blocktrans with invitation.from_user as invitation_from_user %}<a href="{{ user_url }}">{{ invitation_from_user }}</a> has requested to add you as a friend (see <a href="{{ invitation_page }}">invitations</a>){% endblocktrans %}
+{% load i18n %}{% url friends_received_invitations as invitations_page %}
+{% blocktrans with invitation.from_user as invitation_from_user and invitation.from_user.get_profile.get_absolute_url as user_url %}<a href="{{ user_url }}">{{ invitation_from_user }}</a> has requested to add you as a friend (see <a href="{{ invitations_page }}">invitations</a>){% endblocktrans %}
@@ -1 +1 @@
-{% load i18n %}{% blocktrans with invitation.to_user as invitation_to_user %}you have invited {{ invitation_to_user }} to add you as a friend.{% endblocktrans %}
+{% load i18n %}{% blocktrans with invitation.to_user as invitation_to_user %}You have invited {{ invitation_to_user }} to add you as a friend.{% endblocktrans %}
@@ -1,2 +1,2 @@
-{% load i18n %}{% url profile_detail username=invitation.to_user.username as user_url %}
-{% blocktrans with invitation.to_user as invitation_to_user %}you have invited <a href="{{ user_url }}">{{ invitation_to_user }}</a> to add you as a friend.{% endblocktrans %}
+{% load i18n %}
+{% blocktrans with invitation.to_user as invitation_to_user and invitation.to_user.get_profile.get_absolute_url as user_url %}You have invited <a href="{{ user_url }}">{{ invitation_to_user }}</a> to add you as a friend.{% endblocktrans %}
@@ -0,0 +1 @@
+{% load i18n %}{% blocktrans %}Your friend {{ your_friend }} and {{ new_friend }} are now friends.{% endblocktrans %}
@@ -0,0 +1,2 @@
+{% load i18n %}
+{% blocktrans with your_friend.get_profile.get_abolute_url as your_friend_url and new_friend.get_profile.get_absolute_url as new_friend_url %}Your friend <a href="{{ your_friend_url }}">{{ your_friend }}</a> and <a href="{{ new_friend_url }}">{{ new_friend }}</a> are now friends.{% endblocktrans %}

0 comments on commit 56a3940

Please sign in to comment.