def _addPublicPsinque(self, friendsProfile): contact = contactExists(self.userProfile, friendsProfile) if contact is None: contactExisted = False contact = Contact( parent=self.userProfile, friend=friendsProfile, group=self.userProfile.defaultGroup, persona=self.userProfile.publicPersona, ) contact.put() friendsContact = Contact.all().ancestor(friendsProfile).filter("friend =", self.userProfile).get() if not friendsContact is None: persona = friendsContact.persona if not persona.public: contact.status = "private" else: persona = friendsProfile.publicPersona newPsinque = Psinque( parent=contact, fromUser=friendsProfile, private=False, persona=persona, status="established" ) newPsinque.put() if not friendsContact is None: if friendsContact.incoming: contact.outgoing = friendsContact.incoming friendsContact.outgoing = newPsinque friendsContact.put() contact.incoming = newPsinque contact.put() return [contactExisted, contact, newPsinque]
def get(self, personaKey): self.user = users.get_current_user() if not self.getUserProfile(): self.sendJsonError("User profile not found") try: persona = Persona.get(personaKey) friendsProfile = persona.parent() if not contactExists(self.userProfile, friendsProfile) is None: self.sendJsonError("Person already in contacts.") return existingPsinque = Psinque.all(keys_only = True).ancestor(self.userProfile).filter("fromUser ="******"An incoming psinque from this person already exists") return newPsinque = Psinque(parent = self.userProfile, fromUser = friendsProfile, status = "established", private = not persona.public, persona = persona) newPsinque.put() # Contact on user's side if persona.public: status = "public" else: status = "private" contact = Contact(parent = self.userProfile, incoming = newPsinque, friend = friendsProfile, group = self.userProfile.defaultGroup, status = status, persona = self.userProfile.publicPersona) contact.put() # Contact on user's friend's side friendsContact = Contact(parent = friendsProfile, outgoing = newPsinque, friend = self.userProfile, friendsContact = contact, group = friendsProfile.defaultGroup, status = status, persona = persona) friendsContact.put() contact.friendsContact = friendsContact contact.put() self.displayMessage("templates/Message_Success.html", templateVariables = { 'message': 'You have successfully added a new contact to your contact list', }) except datastore_errors.BadKeyError: self.sendJsonError("Persona not found!")