def handle_post(self, email, account_info):
     if self.request.get("project_entity_key"):
         project_key = ndb.Key(urlsafe=self.request.get("project_entity_key"))
         project = project_key.get()
     else:
         project = Project(parent=utils.get_parent_key_for_email(email))
         project_key = project.key
     
     #add all users we find to the project.users, likewise add the project to the User entity
     users = [ndb.Key(urlsafe=self.request.get("user_entity_key"))]    
     potential_users_list = self.request.get_all("project_collaborator")
     for potential_user in potential_users_list:
         if potential_user and potential_user != utils.get_profile_for_email(email).name:
             profile_query = Profile.query(Profile.name == potential_user)
             for profile in profile_query:
                 user_key = profile.key.parent()
                 users.append(user_key)
     
     administrators = [ndb.Key(urlsafe=self.request.get("user_entity_key"))]
     
     project.title = self.request.get("project_title")
     project.description = self.request.get("project_description")
     project.administrators = administrators
     project.users = users
     project.put()
     
     for user_key in users:
         user = user_key.get()
         if not user.projects:
             user.projects = [project.key]
         else:
             user.projects.append(project.key)
         user.put()
         
     self.redirect(self.request.referer)
 def handle_post(self, email, account_info):
     if self.request.get("project_entity_key"):
         project_key = ndb.Key(urlsafe=self.request.get("project_entity_key"))
         project = project_key.get()
     else:
         project = Project(parent=utils.get_parent_key_for_email(email))
         project_key = project.key
     
     #add all users we find to the project.users, likewise add the project to the User entity
     admin_key_list = []
     admin_list = self.request.get_all("admin_selected")   
     for admin_str in admin_list:
         admin_key = ndb.Key(urlsafe=admin_str)
         admin_key_list.append(admin_key.parent())
     project.administrators = admin_key_list
     project.put()
     
     self.redirect(self.request.referer)
 def handle_post(self, email, account_info):
     if self.request.get("project_entity_key"):
         project_key = ndb.Key(urlsafe=self.request.get("project_entity_key"))
         project = project_key.get()
     else:
         project = Project(parent=utils.get_parent_key_for_email(email))
         project_key = project.key
     
     title = self.request.get("title")
     description = self.request.get("description")
     project.title = title
     project.description = description
     
     admin_key_list = []
     admin_list = self.request.get_all("admin_selected")   
     for admin_str in admin_list:
         admin_key = ndb.Key(urlsafe=admin_str)
         admin_key_list.append(admin_key.parent())
     project.administrators = admin_key_list
     
     if self.get_uploads() and len(self.get_uploads()) == 1:
         logging.info("Received an image blob with this profile update.")
         media_blob = self.get_uploads()[0]
         project.picture = media_blob.key()
     else:
         # There is a chance this is an edit in which case we should check for an existing blob key.
         original_blob_key = self.request.get("original_blob_key")
         if original_blob_key:
             logging.info("Attaching original blob key (this must have been an edit or duplicate)")
             project.picture = BlobKey(original_blob_key)
     
     potential_invitees = self.request.get_all("project_collaborator")
     for potential_user in potential_invitees:
         if potential_user and potential_user != utils.get_profile_for_email(email).name:
             profile_query = Profile.query(Profile.name == potential_user)
             for profile in profile_query:
                 user_key = profile.key.parent()
             user = user_key.get()
             if user_key not in project.users:
                 notification_count = Notification.query(Notification.project_key == project_key, 
                                                         ndb.OR(Notification.sender == user_key, 
                                                                Notification.receiver == user_key)).count()
                 if notification_count == 0:
                     notification = Notification(parent=user_key)
                     notification.sender = account_info.key
                     notification.receiver = user_key
                     notification.project_key = project_key
                     notification.message = utils.get_profile_for_email(email).name + " would like you to join " + project.title
                     notification.type = Notification.NotificationTypes.COLLABORATE
                     notification.put()
     
     project_status_str = self.request.get("status")
     if project_status_str == 'ACTIVE':   
         project.status = Project.ProjectStatus.ACTIVE
     elif project_status_str == 'ARCHIVED':
         project.status = Project.ProjectStatus.ARCHIVED
     elif project.status == 'COMPLETED':
         project.status = Project.ProjectStatus.COMPLETED
     
     project.put()
     
     self.redirect(self.request.referer)