def get(self): self.user = users.get_current_user() self.prun_user = None request_path = path(self.request).lower().replace('profile', '').strip('/') if not is_empty(request_path): self.prun_user = PrunUser.find_by_id(long(request_path)) if not self.prun_user: show_error_page(self, 404, 'No such user') return elif self.user: # If no user id provided, show currently logged-in user's profile self.prun_user = PrunUser.find_or_create(self.user) else: self.redirect('/') # Redirect back to the home page. No point showing an error page for ths. return self.user_profile = UserProfile.find_or_create(self.prun_user) self.template_parameters = { "user": self.user, "user_profile": self.user_profile, "login_url": users.create_login_url(self.request.path), "logout_url": users.create_logout_url(self.request.path) } self.response.out.write(render_template("profile.html", self.template_parameters))
def initialize_fields(self, user): self.prun_user = PrunUser.find_or_create(user) self.user_profile = UserProfile.find_or_create(self.prun_user) websites_list = "\n".join([site for site in self.user_profile.websites if site]) if self.user_profile.websites else '' self.template_parameters = { "user": user, "user_profile": self.user_profile, "websites_list": websites_list, "login_url": users.create_login_url(self.request.path), "logout_url": users.create_logout_url(self.request.path) }