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 get(self): page = helper.sanitizeHtml(self.request.get('pagina')) perPage = 20 page = int(page) if page else 1 realPage = page - 1 if realPage > 0: prevPage = realPage if (page * perPage) < Post.get_cached_count(): nextPage = page + 1 session = get_current_session() if session.has_key('user'): user = session['user'] posts = Post.all().order('-karma').fetch(perPage, realPage * perPage) 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: helper.killmetrics("Pageview","Top page", "view", session, "",self) self.response.out.write(template.render('templates/main.html', locals()))
def post(self): session = get_current_session() nickname = helper.sanitizeHtml(self.request.get('nickname')) password = helper.sanitizeHtml(self.request.get('password')) if len(nickname) > 1 and len(password) > 1: password = User.slow_hash(password) already = User.all().filter("lowercase_nickname =", nickname.lower()).fetch(1) if len(already) == 0: user = User(nickname=nickname, lowercase_nickname=nickname.lower(), password=password, about="") user.put() helper.killmetrics("Register", nickname, "do", session, "", self) random_id = helper.get_session_id(session) if session.is_active(): session.terminate() session.regenerate_id() session['random_id'] = random_id session['user'] = user self.redirect('/') else: session[ 'register_error'] = "Ya existe alguien con ese nombre de usuario <strong>" + nickname + "</strong>" self.redirect('/login') else: session[ 'register_error'] = "Porfavor escribe un username y un password" 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() 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): session = get_current_session() nickname = helper.sanitizeHtml(self.request.get('nickname')) email = helper.sanitizeHtml(self.request.get('email')) password = helper.sanitizeHtml(self.request.get('password')) if len(nickname) > 1 and len(password) > 1 and len(email) > 1: password = User.slow_hash(password); already = User.all().filter("lowercase_nickname =",nickname.lower()).fetch(1) if len(already) == 0: user = User(nickname=nickname, lowercase_nickname=nickname.lower(),email=email,password=password, about="") user.put() helper.killmetrics("Register",nickname, "do", session, "",self) random_id = helper.get_session_id(session) if session.is_active(): session.terminate() session.regenerate_id() session['random_id'] = random_id session['user'] = user self.redirect('/') else: session['register_error'] = "Ya existe alguien con ese nombre de usuario <strong>" + nickname + "</strong>" self.redirect('/login') else: session['register_error'] = "Porfavor escribe un username y un password" self.redirect('/login')
def get(self): session = get_current_session() helper.killmetrics("Logout", "", "do", session, "", self) random_id = helper.get_session_id(session) if session.is_active(): session.terminate() session.regenerate_id() session["random_id"] = random_id self.redirect('/')
def get(self): session = get_current_session() helper.killmetrics("Logout","", "do", session, "",self) random_id = helper.get_session_id(session) if session.is_active(): session.terminate() session.regenerate_id() session["random_id"] = random_id self.redirect('/')
def get(self): session = get_current_session() helper.killmetrics("Pageview","Agregar", "view", session, "",self) if session.has_key('post_error'): post_error = session.pop('post_error') if session.has_key('user'): user = session['user'] get_url = helper.sanitizeHtml(self.request.get('url_bookmarklet')) get_title = helper.sanitizeHtml(self.request.get('title_bookmarklet')) self.response.out.write(template.render('templates/submit.html', locals())) else: self.redirect('/login')
def get(self): session = get_current_session() helper.killmetrics("Pageview", "Agregar", "view", session, "", self) if session.has_key('post_error'): post_error = session.pop('post_error') if session.has_key('user'): user = session['user'] get_url = helper.sanitizeHtml(self.request.get('url_bookmarklet')) get_title = helper.sanitizeHtml( self.request.get('title_bookmarklet')) self.response.out.write( template.render('templates/submit.html', locals())) else: self.redirect('/login')
def get(self,post_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: post = db.get(post_id) if not post.already_voted(): vote = Vote(user=user, post=post, target_user=post.user) vote.put() post.remove_from_memcache() post.user.remove_from_memcache() helper.killmetrics("Vote","News", "do", session, "",self) self.response.out.write('Ok') else: self.response.out.write('No') except db.BadValueError: self.response.out.write('Bad') else: self.response.out.write('Bad')
def post(self): session = get_current_session() nickname = helper.sanitizeHtml(self.request.get('nickname')) password = helper.sanitizeHtml(self.request.get('password')) password = User.slow_hash(password); user = User.all().filter('lowercase_nickname =',nickname.lower()).filter('password ='******'random_id'] = random_id session['user'] = user[0] self.redirect('/') else: session['login_error'] = "Usuario y password incorrectos" session['login_error_nickname'] = nickname self.redirect('/login')
def post(self): session = get_current_session() nickname = helper.sanitizeHtml(self.request.get("nickname")) password = helper.sanitizeHtml(self.request.get("password")) password = User.slow_hash(password) user = User.all().filter("lowercase_nickname =", nickname.lower()).filter("password ="******"Login", nickname, "do", session, "", self) random_id = helper.get_session_id(session) if session.is_active(): session.terminate() session.regenerate_id() session["random_id"] = random_id session["user"] = user[0] self.redirect("/") else: session["login_error"] = "Tu usuario y/o contraseña son incorrectos" session["login_error_nickname"] = nickname self.redirect("/login")
def get(self, comment_id): session = get_current_session() if session.has_key('user'): user = session['user'] try: comment = db.get(comment_id) if not comment.already_voted(): vote = Vote(user=user, comment=comment, target_user=comment.user) vote.put() helper.killmetrics("Vote", "Comment", "do", session, "", self) comment.remove_from_memcache() comment.user.remove_from_memcache() self.response.out.write('Ok') else: self.response.out.write('No') except db.BadValueError: self.response.out.write('Bad') else: self.response.out.write('Bad')
def post(self,comment_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: parentComment = db.get(comment_id) comment = Comment(message=message,user=user,post=parentComment.post, father=parentComment) comment.put() helper.killmetrics("Comment","Child", "posted", session, "",self) comment.post.remove_from_memcache() vote = Vote(user=user, comment=comment, target_user=user) vote.put() Notification.create_notification_for_comment_and_user(comment,parentComment.user) self.redirect('/noticia/' + str(parentComment.post.key())) except db.BadKeyError: self.redirect('/') else: self.redirect('/responder/' + comment_id) else: self.redirect('/login')
def post(self): session = get_current_session() nickname = helper.sanitizeHtml(self.request.get('nickname')) password = helper.sanitizeHtml(self.request.get('password')) password = User.slow_hash(password) user = User.all().filter('lowercase_nickname =', nickname.lower()).filter( 'password ='******'random_id'] = random_id session['user'] = user[0] self.redirect('/') else: session['login_error'] = "Usuario y password incorrectos" session['login_error_nickname'] = nickname self.redirect('/login')
def post(self): session = get_current_session() url = self.request.get('url') title = helper.sanitizeHtml(self.request.get('title')) message = helper.sanitizeHtml(self.request.get('message')) nice_url = helper.sluglify(title) if session.has_key('user'): if len(nice_url) > 0: user = session['user'] if len(message) == 0: #is it a post or a message? #Check that we don't have the same URL within the last 'check_days' since_date = date.today() - timedelta(days=7) q = Post.all().filter("created >", since_date).filter("url =", url).count() url_exists = q > 0 q = Post.all().filter("nice_url", nice_url).count() nice_url_exist = q > 0 try: if not url_exists: if not nice_url_exist: post = Post(url=url, title=title, message=message, user=user, nice_url=nice_url) post.put() helper.killmetrics("Submit", "Link", "do", session, "", self) vote = Vote(user=user, post=post, target_user=post.user) vote.put() Post.remove_cached_count_from_memcache() #index with indextank helper.indextank_document( helper.base_url(self), post) self.redirect('/noticia/' + str(post.nice_url)) else: session[ 'post_error'] = "Este titulo ha sido usado en una noticia anterior" self.redirect('/agregar') else: session[ 'post_error'] = "Este link ha sido entregado en los ultimo 7 dias" self.redirect('/agregar') except db.BadValueError: session[ 'post_error'] = "El formato del link no es valido" self.redirect('/agregar') else: q = Post.all().filter("nice_url", nice_url).count() nice_url_exist = q > 0 if not nice_url_exist: post = Post(title=title, message=message, user=user, nice_url=nice_url) post.put() helper.killmetrics("Submit", "Post", "do", session, "", self) post.url = helper.base_url( self) + "/noticia/" + post.nice_url post.put() Post.remove_cached_count_from_memcache() vote = Vote(user=user, post=post, target_user=post.user) vote.put() #index with indextank helper.indextank_document(helper.base_url(self), post) self.redirect('/noticia/' + post.nice_url) else: session[ 'post_error'] = "Este titulo ha sido usado en una noticia anterior" self.redirect('/agregar') else: session['post_error'] = "Necesitas agregar un titulo" self.redirect('/agregar') else: self.redirect('/login')
def post(self): session = get_current_session() url = self.request.get('url') title = helper.sanitizeHtml(self.request.get('title')) message = helper.sanitizeHtml(self.request.get('message')) nice_url = helper.sluglify(title) if session.has_key('user'): if len(nice_url) > 0: user = session['user'] if len(message) == 0: #is it a post or a message? #Check that we don't have the same URL within the last 'check_days' since_date = date.today() - timedelta(days=7) q = Post.all().filter("created >", since_date).filter("url =", url).count() url_exists = q > 0 q = Post.all().filter("nice_url", nice_url).count() nice_url_exist = q > 0 try: if not url_exists: if not nice_url_exist: post = Post(url=url,title=title,message=message, user=user, nice_url=nice_url) post.put() helper.killmetrics("Submit","Link", "do", session, "",self) vote = Vote(user=user, post=post, target_user=post.user) vote.put() Post.remove_cached_count_from_memcache() #index with indextank helper.indextank_document( helper.base_url(self), post) self.redirect('/noticia/' + str(post.nice_url)); else: session['post_error'] = "Este titulo ha sido usado en una noticia anterior" self.redirect('/agregar') else: session['post_error'] = "Este link ha sido entregado en los ultimo 7 dias" self.redirect('/agregar') except db.BadValueError: session['post_error'] = "El formato del link no es valido" self.redirect('/agregar') else: q = Post.all().filter("nice_url", nice_url).count() nice_url_exist = q > 0 if not nice_url_exist: post = Post(title=title,message=message, user=user, nice_url=nice_url) post.put() helper.killmetrics("Submit","Post", "do", session, "",self) post.url = helper.base_url(self) + "/noticia/" + post.nice_url post.put() Post.remove_cached_count_from_memcache() vote = Vote(user=user, post=post, target_user=post.user) vote.put() #index with indextank helper.indextank_document( helper.base_url(self), post) self.redirect('/noticia/' + post.nice_url); else: session['post_error'] = "Este titulo ha sido usado en una noticia anterior" self.redirect('/agregar') else: session['post_error'] = "Necesitas agregar un titulo" self.redirect('/agregar') else: self.redirect('/login')