Ejemplo n.º 1
0
def createNewProfile(user):

    # Create an empty profile
    userProfile = UserProfile(user = user)
    userProfile.put()  # save the new (and empty) profile in the Datastore in order to obtain its key
    logging.info("New profile created, key = " + str(userProfile.key()))

    # User settings
    userSettings = UserSettings(parent = userProfile)
    userSettings.put()
    userProfile.userSettings = userSettings

    # Primary email address (needed for notifications, etc.)
    userEmail = UserEmail(parent = userProfile,
                          itemValue = user.email(),  # "*****@*****.**"
                          privacyType = 'Home',
                          primary = True)
    userEmail.put()

    userProfile.defaultGroup  = createNewGroup(userProfile, 'Default')
    userProfile.defaultPersona = createNewPersona(userProfile, 'Default', userEmail)
    userProfile.publicPersona  = createNewPersona(userProfile, 'Public', userEmail)

    # Save the updated user profile
    userProfile.put()

    
    nickname = UserNickname(parent = userProfile,
                            itemValue = user.nickname())
    nickname.put()

    return userProfile
Ejemplo n.º 2
0
    def getUserProfile(self):

        try:
          getattr(self, 'userProfile')
          return True
        except AttributeError:
          self.userProfile = UserProfile.all(keys_only = True).filter("user ="******"/profile/view")
             return False
          self.userProfile = UserProfile.get(self.userProfile)
          return True
Ejemplo n.º 3
0
 def userprofile(self):
 
     self.sendContent('templates/Admin_UserProfile.html',
                         activeEntry = "",
                         templateVariables = {
         'userProfiles': UserProfile.all(),
     })
Ejemplo n.º 4
0
    def view(self):   # form for editing details

        userProfile = UserProfile.all().filter("user ="******"Profile",
                         templateVariables = {
            'firstlogin': firstLogin,
            'userProfile': userProfile,
            'months': monthNames,
            'primaryEmail': userProfile.emails.filter("primary =", True).get(),
            'additionalEmails': userProfile.emails.filter("primary =", False).order('-creationTime').fetch(limit = 1000),
            'phones': userProfile.phones.order('-creationTime').fetch(limit = 1000),
            'ims': userProfile.ims.order('-creationTime').fetch(limit = 1000),
            'wwws': userProfile.webpages.order('-creationTime').fetch(limit = 1000),
            'addresses': userProfile.addresses.order('-creationTime').fetch(limit = 1000),
            'nicknames': userProfile.nicknames.order('-creationTime').fetch(limit = 1000),
            'companies': userProfile.companies.order('-creationTime').fetch(limit = 1000),
            'genders': genders,
            'countries': countries,
            'imTypes': { x:imTypes for x in privacyTypes },
            'wwwTypes': { x:wwwTypes for x in privacyTypes },
            'phoneTypes': { x:phoneTypes for x in privacyTypes },
            'privacyTypes': privacyTypes,
        })
Ejemplo n.º 5
0
    def post(self):
      
        upload_files = self.get_uploads('files[]')  # 'file' is file upload field in the form
        blob_info = upload_files[0]
        
        img = images.Image(blob_key=str(blob_info.key()))
        
        # we must execute a transform to access the width/height
        img.im_feeling_lucky() # do a transform, otherwise GAE complains.

        # set quality to 1 so the result will fit in 1MB if the image is huge
        img.execute_transforms(output_encoding=images.JPEG,quality=1)

        user = users.get_current_user()
        userProfile = UserProfile.all().filter("user =", user).get()
        userPhoto = UserPhoto(parent = userProfile,
                              image = blob_info.key(),
                              width = img.width,
                              height = img.height,
                              servingUrl = images.get_serving_url(blob_info.key()))
        userPhoto.put()
        
        template = jinja_environment.get_template('templates/Profile_Thumbnail.html')
        self.response.out.write(template.render({
            'photo': userPhoto,
        }))
Ejemplo n.º 6
0
 def getUserProfile(self):
     '''
     Retrieves the UserProfile for the current user from the Datastore.
     If the profile does not exist, the user is redirected to the profile
     edit page.
     '''
     try:
         getattr(self, "userProfile")
         return True
     except AttributeError:
         self.userProfile = UserProfile.all(keys_only = True).filter("user ="******"/profile/view")
             return False
         self.userProfile = UserProfile.get(self.userProfile)  # retrieve actual data from datastore
         return True
Ejemplo n.º 7
0
    def searchemail(self):

        # Search for the owner of the email address
        email = self.request.get("email")
        email = email.lower()

        userEmail = UserEmail.all(keys_only=True).filter("itemValue =", email).get()
        if not userEmail:

            self.sendJsonOK({"found": False})

        else:

            # Check if it's not my own email address
            userProfile = UserProfile.get(userEmail.parent())
            if userProfile.key() == self.userProfile.key():
                raise AjaxError("It is your own email address.")

            # Check if there already is a Psinque from that user
            psinque = self._getPsinqueFrom(userProfile)
            if not psinque is None:
                raise AjaxError("You already have a psinque with this email address.")

            # Check if the account is active
            if not userProfile.active:
                self.sendJsonOK({"found": False})  # act like this person is not registered

            self.sendJsonOK(
                {
                    "found": True,
                    "key": str(userProfile.key()),
                    "displayName": userProfile.displayName,
                    "publicEnabled": userProfile.publicEnabled,
                }
            )
Ejemplo n.º 8
0
    def addpublic(self):

        friendsProfile = UserProfile.get(self.getRequiredParameter("key"))

        psinque = self._getPsinqueFrom(friendsProfile)
        if not psinque is None:
            raise AjaxError("You already have this psinque")

        contact = self._addPublicPsinque(friendsProfile)
        if not contact[0]:
            self._sendNewContact(contact[1])
        else:
            raise AjaxError("Incoming psinque already exists.")
Ejemplo n.º 9
0
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")