def removepersona(self): try: persona = Persona.get(self.getRequiredParameter('key')) except datastore_errors.BadKeyError: raise AjaxError("Persona not found") # Check for errors if persona.name == "Public": # cannot remove the public persona raise AjaxError("Cannot remove the public persona") if persona.name == "Default": # cannot remove the default persona raise AjaxError("Cannot remove the default private persona") # Get all contacts that use this persona and assign them the default persona contacts = Contact.all(). \ ancestor(self.userProfile). \ filter("persona =", persona) defaultPersona = self._getPersonaByName("Default") for contact in contacts: contact.persona = defaultPersona contact.put() # Remove all children individual permits individualPermits = IndividualPermit.all().ancestor(persona) for individualPermit in individualPermits: individualPermit.delete() persona.delete() # and the persona itself self.sendJsonOK()
def _getPersonaUpdateVCard(self): personaKey = self.getRequiredParameter('key') persona = Persona.get(personaKey) if persona.vcardNeedsUpdating: reallyGenerateVCard(persona) return persona
def setgeneral(self): try: persona = Persona.get(self.getRequiredParameter('key')) newName = self.request.get("name") if newName != "": persona.name = newName persona.canViewPrefix = self.getRequiredBoolParameter('prefix') persona.canViewGivenNames = self.getRequiredBoolParameter('givennames') persona.canViewRomanGivenNames = self.getRequiredBoolParameter('givennamesroman') persona.canViewFamilyNames = self.getRequiredBoolParameter('familynames') persona.canViewRomanFamilyNames = self.getRequiredBoolParameter('familynamesroman') persona.canViewSuffix = self.getRequiredBoolParameter('suffix') persona.canViewBirthday = self.getRequiredBoolParameter('birthday') persona.canViewGender = self.getRequiredBoolParameter('gender') company = self.request.get("company") if company != "None": persona.company = Key(company) else: persona.company = None nickname = self.request.get("nickname") if nickname != "None": persona.nickname = Key(nickname) else: persona.nickname = None photoKey = self.request.get("photo") if photoKey != "": photo = UserPhoto.get(photoKey) persona.picture = photo persona.put() generateVCard(persona) self.sendJsonOK() except datastore_errors.BadKeyError: raise AjaxError("Persona not found.")
def changepersona(self): try: contact = Contact.get(self.getRequiredParameter("contact")) except datastore_errors.BadKeyError: raise AjaxError("Contact does not exist") try: persona = Persona.get(self.getRequiredParameter("persona")) except datastore_errors.BadKeyError: raise AjaxError("Persona does not exist") if contact.persona == persona: self.sendJsonOK() return contact.persona = persona contact.put() if persona.public: if contact.outgoing: contact.outgoing.private = False contact.outgoing.put() Notifications.notifyDowngradedPsinque(contact.outgoing) if contact.friendsContact: contact.friendsContact.status = "public" contact.friendsContact.put() if contact.outgoing: contact.outgoing.persona = persona contact.outgoing.put() self.sendJsonOK()
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!")