def createNewPersona(userProfile, personaName, userEmail): persona = Persona(parent = userProfile, name = personaName) persona.put() permitEmail = PermitEmail(parent = persona, userEmail = userEmail) permitEmail.put() generateVCard(persona) logging.info("New persona created, key = " + str(persona.key())) return persona.key()
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 removecompany(self): item = self._getItemByKey(UserCompany) for persona in Persona.all().filter("company =", item): persona.company = None persona.put() item.delete() self.sendJsonOK()
def removenickname(self): item = self._getItemByKey(UserNickname) for persona in Persona.all().filter("nickname =", item): persona.nickname = None persona.put() item.delete() self.sendJsonOK()
def view(self): if self.getUserProfile(): self.sendContent('templates/Personas.html', activeEntry = "Personas", templateVariables = { 'userProfile': self.userProfile, 'companies': self._getCompanies(), 'nicknames': self._getNicknames(), 'photos': self._getPhotos(), 'personas': Persona.all(). \ ancestor(self.userProfile). \ order("name"), })
def removephoto(self): key = self.getRequiredParameter('key') try: photo = UserPhoto.get(key) for persona in Persona.all().filter("picture =", photo): persona.picture = None persona.put() photo.image.delete() photo.delete() self.sendJsonOK() except datastore_errors.BadKeyError: raise AjaxError("Photo not found.")
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 deleteProfile(userProfileKey): userProfile = UserProfile.get(userProfileKey) for e in CardDAVLogin.all().ancestor(userProfile): e.delete() for e in IndividualPermit.all().ancestor(userProfile): e.delete() for e in Persona.all().ancestor(userProfile): e.delete() for e in Psinque.all().ancestor(userProfile): e.delete() for e in Contact.all().ancestor(userProfile): e.delete() for e in Group.all().ancestor(userProfile): e.delete() for e in UserAddress.all().ancestor(userProfile): e.delete() for e in UserEmail.all().ancestor(userProfile): e.delete() for e in UserIM.all().ancestor(userProfile): e.delete() for e in UserPhoneNumber.all().ancestor(userProfile): e.delete() for e in UserPhoto.all().ancestor(userProfile): e.image.delete() e.delete() for e in UserNickname.all().ancestor(userProfile): e.delete() for e in UserCompany.all().ancestor(userProfile): e.delete() for e in UserWebpage.all().ancestor(userProfile): e.delete() if not userProfile.userSettings is None: userProfile.userSettings.delete() userProfile.delete() logging.info("User profile deleted")
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 _getPersonaByName(self, personaName): return Persona.all(). \ ancestor(self.userProfile). \ filter("name =", personaName). \ get()
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!")
def addpersona(self): personaName = self.getRequiredParameter('name') personaIndex = self.getRequiredParameter('index') # Error checking if personaName == "Public": raise AjaxError("Cannot create another public persona") if personaName == "Default": raise AjaxError("Cannot create another default private persona") try: # Check if the persona already exists persona = self._getPersonaByName(personaName) # Create a new Persona newPersona = Persona(parent = self.userProfile, name = personaName) newPersona.put() for email in self.userProfile.emails: permitEmail = PermitEmail(parent = newPersona, userEmail = email) permitEmail.put() for im in self.userProfile.ims: permitIM = PermitIM(parent = newPersona, userIM = im) permitIM.put() for www in self.userProfile.webpages: permitWebpage = PermitWebpage(parent = newPersona, userWebpage = www) permitWebpage.put() for phone in self.userProfile.phones: permitPhoneNumber = PermitPhoneNumber(parent = newPersona, userPhoneNumber = phone) permitPhoneNumber.put() for address in self.userProfile.addresses: permitAddress = PermitAddress(parent = newPersona, userAddress = address) permitAddress.put() # Generate the Persona's vCard and eTag: generateVCard(newPersona) self.sendContent('templates/Persona_Persona.html', activeEntry = "Personas", templateVariables = { 'persona': newPersona, 'companies': self._getCompanies(), 'nicknames': self._getNicknames(), 'photos': self._getPhotos(), 'userProfile': self.userProfile, 'personaIndex': personaIndex, }) except datastore_errors.BadKeyError: raise AjaxError("Persona with that name already exists")
def _updateAllVCards(self): for persona in Persona.all().ancestor(self.userProfile): generateVCard(persona)