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}) #self.user.message_set.create(message="Friendship requested with %s" % to_user.username) # @@@ make link like notification return invitation
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, ) invitation.save() return invitation
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}) self.user.message_set.create(message="Friendship requested with %s" % to_user.username) # @@@ make link like notification return invitation
def save(self): to_user = get_user_model().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, ) invitation.save() return invitation
def save(self): """ Overrides save so that we can use our custom clean method. """ 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, ) invitation.save() return invitation
def invite(from_user, to_user): if from_user == to_user: raise ValueError(_to_user(u"You can't request friendship with yourself.")) if Friendship.objects.are_friends(from_user, to_user): raise ValueError(_(u"You are already friends with %(username)s.") % {'username': to_user.username}) blocking = Blocking.objects.filter(from_user=to_user, to_user=from_user) if blocking.count() > 0: raise ValueError(_(u"You can't invite %(username)s to friends.") % {'username': to_user.username}) if FriendshipInvitation.objects.is_invited(from_user, to_user): raise ValueError(_(u"Already requested friendship with %(username)s.") % {'username': to_user.username}) invitation = FriendshipInvitation(from_user=from_user, to_user=to_user) invitation.save() return True
def create_friend(fromc, toc): from_user = fromc.parents[0] to_user = toc.parents[0] friendship_inv = FriendshipInvitation(from_child=fromc, from_user=from_user, to_child=toc, to_user=to_user) friendship_inv.save() friendship_inv.accept()
def add_friend(request): if request.method == 'POST': post = request.POST message = '' how_related = "4" source = '' if 'how_related' in post: how_related = post['how_related'] if 'message' in post: message=post['message'] if 'source' in post: source = post['source'] from_child_id=post['from_child'] to_child_id=post['to_child'] to_user_id=post['to_user'] if not re.match('^[0-9]+$',from_child_id): raise("Invalid input") if not re.match('^[0-9]+$',to_child_id): raise("Invalid input") if not re.match('^[0-9]+$',to_user_id): raise("Invalid input") from_user = request.user to_user = User.objects.select_related('_profile_cache').get(id=to_user_id) from_child = Child.objects.get(id=from_child_id) to_child = Child.objects.get(id=to_child_id) cv = ChildView(to_user, to_child) if not cv.can_edit_child_playlist: raise Exception('User does not have permissions to approve request') cv = ChildView(from_user, from_child) if not cv.can_edit_child_playlist: raise Exception('User does not have permissions to send request') # hardcode TODO from friends.models import FriendshipInvitation; invitation = FriendshipInvitation( from_user=from_user, to_user=to_user, from_child=from_child, to_child=to_child, message=message, how_related=how_related, status="2" ) try: invitation.save_and_notify() except IntegrityError: pass response_dict = { "success":"true", "message":"Invitation Sent"} return HttpResponse(simplejson.dumps(response_dict), mimetype='application/javascript')
bd = datetime.date.today() - datetime.timedelta(i*365) child = create_child('Bunny'+str(i),'Jackson','male', bd) family["child"+str(i)]=child adult_child = create_adult_child(user, child, 'P') adult_child = create_adult_child(user2, child, 'P') i=i+1 print "here1" families.append(family) i=1 print "to_user_email " + families[1]["father"].email + " pwd: adam79" while i < 3: friendshipinv = FriendshipInvitation(from_child = families[0]["child"+str(i)], to_child = families[1]["child"+str(i)], from_user= families[0]["father"], to_user=families[1]["father"], message="Dude. This site is awesome", how_related=4) friendshipinv.save_and_notify() i=i+1 print "here10" # print str(families) # create friendships i=1 while i < 4: friendship = Friendship(from_child = families[0]["child"+str(i)], to_child = families[1]["child"+str(i)]) friendship.save()
def create_friend(fromc, toc): from_user = fromc.parents[0] to_user = toc.parents[0] friendship_inv = FriendshipInvitation(from_child = fromc, from_user=from_user, to_child = toc, to_user=to_user) friendship_inv.save() friendship_inv.accept()
def add_friend(request): if request.method == "POST": post = request.POST message = "" how_related = "4" source = "" if "how_related" in post: how_related = post["how_related"] if "message" in post: message = post["message"] if "source" in post: source = post["source"] from_child_id = post["from_child"] to_child_id = post["to_child"] to_user_id = post["to_user"] if not re.match("^[0-9]+$", from_child_id): raise ("Invalid input") if not re.match("^[0-9]+$", to_child_id): raise ("Invalid input") if not re.match("^[0-9]+$", to_user_id): raise ("Invalid input") from_user = request.user to_user = User.objects.select_related("_profile_cache").get(id=to_user_id) from_child = Child.objects.get(id=from_child_id) to_child = Child.objects.get(id=to_child_id) cv = ChildView(to_user, to_child) if not cv.can_edit_child_playlist: raise Exception("User does not have permissions to approve request") cv = ChildView(from_user, from_child) if not cv.can_edit_child_playlist: raise Exception("User does not have permissions to send request") # hardcode TODO from friends.models import FriendshipInvitation invitation = FriendshipInvitation( from_user=from_user, to_user=to_user, from_child=from_child, to_child=to_child, message=message, how_related=how_related, status="2", ) try: invitation.save_and_notify() except IntegrityError: pass response_dict = {"success": "true", "message": "Invitation Sent"} return HttpResponse(simplejson.dumps(response_dict), mimetype="application/javascript")