def get(self, profile_email): """ GET request handler that renders a profile overview page. @param profile_email: The email address of the user whose profile's overview page should be rendered. @type profile_email: str """ cur_user = users.get_current_user() if not account_facade.viewer_has_access(cur_user, profile_email): self.redirect(constants.HOME_URL) section_statuses = account_facade.get_updated_sections( cur_user, profile_email) sections = constants.PORTFOLIO_SECTIONS account_facade.set_viewed(cur_user, profile_email, None) template = jinja_environment.get_template("portfolio_overview.html") template_vals = get_standard_template_dict() owner_name = util.get_full_name_from_email(profile_email) template_vals["profile_safe_email"] = util.sanitize_email(profile_email) template_vals["cur_section"] = "overview" template_vals["owner_name"] = " ".join(owner_name) template_vals["owner_first_name"] = owner_name[0] template_vals["owner_last_name"] = owner_name[1] template_vals["sections"] = sections template_vals["section_statuses"] = section_statuses content = template.render(template_vals) self.response.out.write(content)
def test_set_viewed(self): """Test indicating that a user viewed a portfolio section.""" user_1 = FakeUser("*****@*****.**") section_1_name = "section1" contents_1 = "test contents 1" viewing_timestamp = datetime.datetime(2001, 4, 5) profile_email = "safe_email" viewing_profile = models.ViewingProfile() viewing_profile.viewer_email = user_1.email() viewing_profile.profile_email = profile_email viewing_profile.section_name = section_1_name viewing_profile.last_visited = viewing_timestamp viewing_profile.put() account_facade.set_viewed(user_1, profile_email, section_1_name) updated_viewing_profile = models.ViewingProfile.get_for( user_1, profile_email, section_1_name) self.assertTrue( viewing_timestamp != updated_viewing_profile.last_visited)
def get(self, profile_email, section_name): """ GET request handler that renders the private comments for a section. @param profile_email: The email address of the user whose portfolio's comments should be displayed. @type profile_email: str @param section_name: The name of the portfolio section to render comments for. @type section_name: str """ cur_user = users.get_current_user() if not account_facade.viewer_has_access(cur_user, profile_email): self.redirect(constants.HOME_URL) new_comments = account_facade.get_new_comments( cur_user, profile_email, section_name) old_comments = account_facade.get_old_comments( cur_user, profile_email, section_name) section_statuses = account_facade.get_updated_sections( cur_user, profile_email) sections = constants.PORTFOLIO_SECTIONS account_facade.set_viewed(cur_user, profile_email, section_name) template = jinja_environment.get_template("portfolio_section.html") template_vals = get_standard_template_dict() owner_name = util.get_full_name_from_email(profile_email) template_vals["profile_safe_email"] = util.sanitize_email(profile_email) template_vals["cur_section"] = section_name template_vals["owner_name"] = " ".join(owner_name) template_vals["owner_first_name"] = owner_name[0] template_vals["owner_last_name"] = owner_name[1] template_vals["sections"] = sections template_vals["section_statuses"] = section_statuses template_vals["new_comments"] = new_comments template_vals["old_comments"] = old_comments content = template.render(template_vals) self.response.out.write(content)
def post(self, profile_email, section_name): """ POST handler for adding a priate comment to a portfolio section. @param profile_email: The email address of the user whose portfolio should recieve the new comment. @type profile_email: str @param section_name: The name of the portfolio section to add the new comment to. @type section_name: str """ cur_user = users.get_current_user() if not account_facade.viewer_has_access(cur_user, profile_email): self.redirect(constants.HOME_URL) raw_comment_contents = self.request.get("comment-contents", "") comment_contents = cgi.escape(raw_comment_contents) comment_contents = "<br>".join(comment_contents.splitlines()) new_comment = models.Comment() new_comment.author_email = cur_user.email() new_comment.profile_email = profile_email new_comment.section_name = section_name new_comment.contents = comment_contents new_comment.timestamp = datetime.datetime.now() new_comment.put() account_facade.set_viewed(cur_user, profile_email, section_name) account_facade.set_flash_message( cur_user.email(), constants.FLASH_MSG_TYPE_CONFIRMATION, constants.FLASH_MSG_ADDED_COMMENT ) self.redirect(self.request.path)