def get(self,post_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get() if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories post = db.get( helper.parse_post_id( post_id ) ) comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000) comments = helper.order_comment_list_in_memory(comments) prefetch.prefetch_comment_list(comments) display_post_title = True prefetch.prefetch_posts_list([post]) if helper.is_json(post_id): comments_json = [c.to_json() for c in comments if not c.father_ref()] if(self.request.get('callback')): self.response.headers['Content-Type'] = "application/javascript" self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')') else: self.response.headers['Content-Type'] = "application/json" self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json})) else: helper.killmetrics("Pageview","Post", "view", session, "",self) self.response.out.write(template.render('templates/post.html', locals())) except db.BadKeyError: self.redirect('/')
def post(self, post_id): session = get_current_session() if session.has_key('user'): message = helper.sanitizeHtml(self.request.get('message')) user = session['user'] key = self.request.get('comment_key') if len(message) > 0 and key == keys.comment_key: try: post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get() if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories post = db.get( helper.parse_post_id( post_id ) ) post.remove_from_memcache() comment = Comment(message=message,user=user,post=post) comment.put() helper.killmetrics("Comment","Root", "posted", session, "",self) vote = Vote(user=user, comment=comment, target_user=user) vote.put() Notification.create_notification_for_comment_and_user(comment,post.user) self.redirect('/noticia/' + post_id) except db.BadKeyError: self.redirect('/') else: self.redirect('/noticia/' + post_id) else: self.redirect('/login')
def post(self, post_id): session = get_current_session() if session.has_key('user'): message = helper.sanitizeHtml(self.request.get('message')) user = session['user'] if len(message) > 0: try: post = Post.all().filter( 'nice_url =', helper.parse_post_id(post_id)).get() if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories post = db.get(helper.parse_post_id(post_id)) post.remove_from_memcache() comment = Comment(message=message, user=user, post=post) comment.put() vote = Vote(user=user, comment=comment, target_user=user) vote.put() Notification.create_notification_for_comment_and_user( comment, post.user) self.redirect('/noticia/' + post_id) except db.BadKeyError: self.redirect('/') else: self.redirect('/noticia/' + post_id) else: self.redirect('/login')
def get(self,post_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get() if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories post = db.get( helper.parse_post_id( post_id ) ) comments = Comment.all().filter("post =", post.key()).order("-karma").fetch(1000) comments = helper.order_comment_list_in_memory(comments) prefetch.prefetch_comment_list(comments) display_post_title = True prefetch.prefetch_posts_list([post]) if helper.is_json(post_id): comments_json = [c.to_json() for c in comments if not c.father_ref()] if(self.request.get('callback')): self.response.headers['Content-Type'] = "application/javascript" self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'post':post.to_json(),'comments':comments_json})+')') else: self.response.headers['Content-Type'] = "application/json" self.response.out.write(simplejson.dumps({'post':post.to_json(),'comments':comments_json})) else: self.response.out.write(template.render('templates/post.html', locals())) except db.BadKeyError: self.redirect('/')
def post(self, post_id): session = get_current_session() title = helper.sanitizeHtml(self.request.get('title')) message = helper.sanitizeHtml(self.request.get('message')) if session.has_key('user'): user = session['user'] try: post = db.get(helper.parse_post_id(post_id)) if post.can_edit(): if len(title) > 0: post.title = title if post.message is not None and message is not None: post.message = message post.edited = True post.put() #index with indextank helper.indextank_document(helper.base_url(self), post) self.redirect('/noticia/' + str(post.key())) else: self.redirect('/') except db.BadKeyError: self.redirect('/') else: self.redirect('/')
def post(self, code): session = get_current_session() code = helper.parse_post_id( helper.sanitizeHtml(self.request.get('code'))) password = helper.sanitizeHtml(self.request.get('password')) password_confirm = helper.sanitizeHtml( self.request.get('password_confirm')) if password != password_confirm: session['error'] = "Ocurrió un error al confirmar el password" self.redirect('/recovery/' + code) return ticket = Ticket.all().filter('code', code).filter('is_active', True).fetch(1) if len(ticket) == 1: ticket = ticket[0] user = ticket.user user.password = User.slow_hash(password) user.put() ticket.is_active = False ticket.put() session[ 'success'] = "Se ha cambiado el password correctamente, ya puedes iniciar sesión con tus nuevas credenciales" self.redirect('/login') else: self.redirect('/')
def get(self, user): page = helper.sanitizeHtml(self.request.get('pagina')) target_user_str= helper.sanitizeHtml(helper.parse_post_id(user)) perPage = 20 page = int(page) if page else 1 realPage = page - 1 if realPage > 0: prevPage = realPage session = get_current_session() if session.has_key('user'): user = session['user'] target_user = User.all().filter('lowercase_nickname =', target_user_str).fetch(1) if len(target_user) > 0: posts = Post.all().filter('user ='******'-created').fetch(perPage,perPage * realPage) if (page * perPage) < Post.all().filter('user ='******'-created').count(): nextPage = page + 1 prefetch.prefetch_posts_list(posts) i = perPage * realPage + 1 for post in posts: post.number = i i = i + 1 if helper.is_json(self.request.url): posts_json = [p.to_json() for p in posts] if(self.request.get('callback')): self.response.headers['Content-Type'] = "application/javascript" self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'posts':posts_json})+');') else: self.response.headers['Content-Type'] = "application/json" self.response.out.write(simplejson.dumps({'posts':posts_json})) else: self.response.out.write(template.render('templates/main.html', locals())) else: self.redirect('/')
def get(self,code): session = get_current_session() code = helper.parse_post_id(code) if session.has_key('error'): error = session['error'] ticket = Ticket.all().filter('code',code).filter('is_active',True).fetch(1) if len(ticket) == 1: ticket = ticket[0] self.response.out.write(template.render('templates/new-password.html', locals())) else: self.redirect('/')
def get(self, code): session = get_current_session() code = helper.parse_post_id(code) if session.has_key('error'): error = session['error'] ticket = Ticket.all().filter('code', code).filter('is_active', True).fetch(1) if len(ticket) == 1: ticket = ticket[0] self.response.out.write( template.render('templates/new-password.html', locals())) else: self.redirect('/')
def get(self, comment_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: comment = db.get(helper.parse_post_id(comment_id)) if comment.can_edit(): self.response.out.write(template.render('templates/edit-comment.html', locals())) else: self.redirect('/') except db.BadKeyError: self.redirect('/') else: self.redirect('/')
def get(self, post_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: post = db.get(helper.parse_post_id(post_id)) if post.can_edit(): self.response.out.write( template.render('templates/edit-post.html', locals())) else: self.redirect('/') except db.BadKeyError: self.redirect('/') else: self.redirect('/')
def get(self, post_id): session = get_current_session() if session.has_key('user'): try: post = db.get(helper.parse_post_id(post_id)) if post.can_edit(): post.delete() except: self.redirect('/') session['post_error'] = "Noticia borrada exitosamente, ahora puedes agregar otra" self.redirect('/agregar') else: self.redirect('/')
def get(self,nickname): nickname = helper.parse_post_id(nickname) session = get_current_session() if session.has_key('user'): user = session['user'] if session.has_key('profile_saved'): profile_saved = session.pop('profile_saved') profiledUser = User.all().filter('nickname =',nickname).fetch(1) if len(profiledUser) == 1: profiledUser = profiledUser[0] #TODO fix this horrible way of testing for the user if session.has_key('user') and user.key() == profiledUser.key(): my_profile = True #self.response.out.write(template.render('templates/profile.html', locals())) helper.render(self,profiledUser,'templates/profile.html', locals()) else: self.redirect('/')
def get(self, nickname): nickname = helper.parse_post_id(nickname) session = get_current_session() if session.has_key('user'): user = session['user'] if session.has_key('profile_saved'): profile_saved = session.pop('profile_saved') profiledUser = User.all().filter('nickname =', nickname).fetch(1) if len(profiledUser) == 1: profiledUser = profiledUser[0] #TODO fix this horrible way of testing for the user if session.has_key('user') and user.key() == profiledUser.key(): my_profile = True #self.response.out.write(template.render('templates/profile.html', locals())) helper.render(self, profiledUser, 'templates/profile.html', locals()) else: self.redirect('/')
def get(self, nickname): nickname = helper.parse_post_id(nickname) session = get_current_session() if session.has_key('user'): user = session['user'] if session.has_key('profile_saved'): profile_saved = session.pop('profile_saved') profiledUser = User.all().filter('nickname =', nickname).fetch(1) if len(profiledUser) == 1: profiledUser = profiledUser[0] #TODO fix this horrible way of testing for the user if session.has_key('user') and user.key() == profiledUser.key(): my_profile = True if helper.is_json(self.request.url): if (self.request.get('callback')): self.response.headers[ 'Content-Type'] = "application/javascript" self.response.out.write( self.request.get('callback') + '(' + simplejson.dumps({ 'nickname': profiledUser.nickname, 'karma': profiledUser.karma, 'twitter': profiledUser.twitter, 'github': profiledUser.github, 'hn': profiledUser.hnuser }) + ')') else: self.response.headers[ 'Content-Type'] = "application/javascript" self.response.out.write( simplejson.dumps({ 'nickname': profiledUser.nickname, 'twitter': profiledUser.twitter, 'karma': profiledUser.karma, 'github': profiledUser.github, 'hn': profiledUser.hnuser })) else: self.response.out.write( template.render('templates/profile.html', locals())) else: self.redirect('/')
def post(self, comment_id): session = get_current_session() message = helper.sanitizeHtml(self.request.get('message')) if session.has_key('user'): user = session['user'] try: comment = db.get(helper.parse_post_id(comment_id)) if comment.can_edit(): if message is not None: comment.message = message comment.edited = True comment.put() self.redirect('/noticia/' + str(comment.post.key())) else: self.redirect('/') except db.BadKeyError: self.redirect('/') else: self.redirect('/')
def post(self,code): session = get_current_session() code = helper.parse_post_id(helper.sanitizeHtml(self.request.get('code'))) password = helper.sanitizeHtml(self.request.get('password')) password_confirm = helper.sanitizeHtml(self.request.get('password_confirm')) if password != password_confirm : session['error'] = "Ocurrió un error al confirmar el password" self.redirect('/recovery/'+code) return ticket = Ticket.all().filter('code',code).filter('is_active',True).fetch(1) if len(ticket) == 1: ticket = ticket[0] user = ticket.user user.password = User.slow_hash(password) user.put() ticket.is_active = False ticket.put() session['success'] = "Se ha cambiado el password correctamente, ya puedes iniciar sesión con tus nuevas credenciales" self.redirect('/login') else: self.redirect('/')
def get(self, post_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: post = db.get(helper.parse_post_id(post_id)) comments = Comment.all().filter( "post =", post.key()).order("-karma").fetch(1000) comments = helper.order_comment_list_in_memory(comments) prefetch.prefetch_comment_list(comments) display_post_title = True prefetch.prefetch_posts_list([post]) if helper.is_json(post_id): comments_json = [ c.to_json() for c in comments if not c.father_ref() ] if (self.request.get('callback')): self.response.headers[ 'Content-Type'] = "application/javascript" self.response.out.write( self.request.get('callback') + '(' + simplejson.dumps({ 'post': post.to_json(), 'comments': comments_json }) + ')') else: self.response.headers['Content-Type'] = "application/json" self.response.out.write( simplejson.dumps({ 'post': post.to_json(), 'comments': comments_json })) else: self.response.out.write( template.render('templates/post.html', locals())) except db.BadKeyError: self.redirect('/')
def get(self,nickname): nickname = helper.parse_post_id(nickname) session = get_current_session() if session.has_key('user'): user = session['user'] if session.has_key('profile_saved'): profile_saved = session.pop('profile_saved') profiledUser = User.all().filter('nickname =',nickname).fetch(1) if len(profiledUser) == 1: profiledUser = profiledUser[0] #TODO fix this horrible way of testing for the user if session.has_key('user') and user.key() == profiledUser.key(): my_profile = True if helper.is_json(self.request.url): if(self.request.get('callback')): self.response.headers['Content-Type'] = "application/javascript" self.response.out.write(self.request.get('callback')+'('+simplejson.dumps({'nickname':profiledUser.nickname, 'karma':profiledUser.karma,'twitter':profiledUser.twitter,'github':profiledUser.github,'hn':profiledUser.hnuser})+')') else: self.response.headers['Content-Type'] = "application/javascript" self.response.out.write(simplejson.dumps({'nickname':profiledUser.nickname,'twitter':profiledUser.twitter, 'karma':profiledUser.karma, 'github':profiledUser.github,'hn':profiledUser.hnuser})) else: self.response.out.write(template.render('templates/profile.html', locals())) else: self.redirect('/')