Beispiel #1
0
 def save(self):
     to_user = User.objects.get(username=self.cleaned_data["to_user"])
     message = self.cleaned_data["message"]
     invitation = FriendshipInvitation(from_user=self.user, to_user=to_user, message=message, status="2")
     invitation.save()
     if notification:
         notification.send([to_user], "friends_invite", {"invitation": invitation})
         notification.send([self.user], "friends_invite_sent", {"invitation": invitation})
     return invitation
Beispiel #2
0
    def save(self, commit=True):
        """
        Checks the send_now field in the form and when True sends out the
        announcement through notification if present.
        """

        announcement = super(AnnouncementAdminForm, self).save(commit)
        if self.cleaned_data["send_now"]:
            if notification:
                users = User.objects.all()
                notification.send(users, "announcement", {
                    "announcement": announcement,
                }, on_site=False, queue=True)
        return announcement
Beispiel #3
0
 def save(self):
     to_user = User.objects.get(username=self.cleaned_data["to_user"])
     message = self.cleaned_data["message"]
     invitation = FriendshipInvitation(from_user=self.user,
                                       to_user=to_user,
                                       message=message,
                                       status="2")
     invitation.save()
     if notification:
         notification.send([to_user], "friends_invite",
                           {"invitation": invitation})
         notification.send([self.user], "friends_invite_sent",
                           {"invitation": invitation})
     return invitation
Beispiel #4
0
 def accept(self, new_user):
     # mark invitation accepted
     self.status = "5"
     self.save()
     # auto-create friendship
     friendship = Friendship(to_user=new_user, from_user=self.from_user)
     friendship.save()
     # notify
     if notification:
         notification.send([self.from_user], "join_accept", {"invitation": self, "new_user": new_user})
         friends = []
         for user in friend_set_for(new_user) | friend_set_for(self.from_user):
             if user != new_user and user != self.from_user:
                 friends.append(user)
         notification.send(friends, "friends_otherconnect", {"invitation": self, "to_user": new_user})
Beispiel #5
0
 def accept(self, new_user):
     # mark invitation accepted
     self.status = "5"
     self.save()
     # auto-create friendship
     friendship = Friendship(to_user=new_user, from_user=self.from_user)
     friendship.save()
     # notify
     if notification:
         notification.send([self.from_user], "join_accept", {
             "invitation": self,
             "new_user": new_user
         })
         friends = []
         for user in friend_set_for(new_user) | friend_set_for(
                 self.from_user):
             if user != new_user and user != self.from_user:
                 friends.append(user)
         notification.send(friends, "friends_otherconnect", {
             "invitation": self,
             "to_user": new_user
         })
Beispiel #6
0
 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()
         self.status = "5"
         self.save()
         if notification:
             notification.send([self.from_user], "friends_accept", {"invitation": self})
             notification.send([self.to_user], "friends_accept_sent", {"invitation": self})
             for user in friend_set_for(self.to_user) | friend_set_for(self.from_user):
                 if user != self.to_user and user != self.from_user:
                     notification.send([user], "friends_otherconnect", {"invitation": self, "to_user": self.to_user})
Beispiel #7
0
 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()
         self.status = "5"
         self.save()
         if notification:
             notification.send([self.from_user], "friends_accept",
                               {"invitation": self})
             notification.send([self.to_user], "friends_accept_sent",
                               {"invitation": self})
             for user in friend_set_for(self.to_user) | friend_set_for(
                     self.from_user):
                 if user != self.to_user and user != self.from_user:
                     notification.send([user], "friends_otherconnect", {
                         "invitation": self,
                         "to_user": self.to_user
                     })