def new_thread(key=None): user = active_user() if has_permission(user,'new-thread'): new_thread = Thread() first_post = Post() name = bottle.request.forms.get("name") content = bottle.request.forms.get("content") tags = parse_tags(bottle.request.forms.get("tags","")) first_post.update({ "owner":user.key, "content":content }) new_thread.update({ "name":name, "owner":user.key, "posts":[first_post.key], "tags":tags }) forum = Forum.load(forum_key()) target = Category.load(decrypt(key)) if key else forum target.threads.append(new_thread.key) target.save() new_thread.save() return flash_message("Your thread has been created.","/thread/"+new_thread.slug+"/","Success") raise bottle.HTTPError(404, """Sorry, but we weren't able to find what you were looking for. I hope that someday you do find it, but when you do, it won't be here. """)
def _get_posts(cursor, limit, condition=None): if condition: posts, next_cursor, more = Post.query(eval(condition)).order( -Post.date ).fetch_page(limit, start_cursor=cursor) else: posts, next_cursor, more = Post.query().order( -Post.date ).fetch_page(limit, start_cursor=cursor) return posts, next_cursor, more
def post(self): self.name = self.request.get('name') self.author = str(users.get_current_user()) if (users.is_current_user_admin()): post = Post(name = self.name, description = self.request.get('description').encode('utf-8'), author = self.author) post.put() return self.redirect('/?msg=El post se ha realizado correctamente') else: return self.redirect('/?msg=No puede escribir posts porque no es administrador del sitio web.')
def create_post(urlsafe_chatroom_id, user_email, content): chatroom = get_chatroom(urlsafe_chatroom_id) if chatroom.status != 'active': raise ValueError( "Posts cannot be published while chatroom is suspended.") post = Post(chatroom_key=chatroom.key, user_email=user_email, content=content) post.put() return post
def post(self): subject = self.request.get('subject') content = self.request.get('content') # let's check we have a subject and a content if subject and content: post = Post(subject=subject, content=content, user=User.by_id(self.uid())) # post creation post.put() self.redirect('/') # if something is wrong let's show the error else: error = 'Sorry, we need both, title and content.' self.render_new_post(subject, content, error)
def post(self): subject = self.request.get('subject') content = self.request.get('content') # let's check we have a subject and a content if subject and content: post = Post( subject=subject, content=content, user=User.by_id(self.uid()) ) # post creation post.put() self.redirect('/') # if something is wrong let's show the error else: error = 'Sorry, we need both, title and content.' self.render_new_post(subject, content, error)
def _do_older_pagination(request, cursor, limit): if (request.get('prev_go') == 'newer'): cursor = cursor.reversed() query = Post.query().order( -Post.date ) posts, next_cursor, more = query.fetch_page(int(request.get('numEls')), start_cursor=cursor) if (request.get('prev_go') == 'newer'): posts, next_cursor, more = query.fetch_page(limit, start_cursor=next_cursor) return posts, next_cursor, more
def _do_newer_pagination(request, cursor, limit): if (request.get('prev_go') == 'older'): cursor = cursor.reversed() query = Post.query().order( Post.date ) posts, next_cursor, more = query.fetch_page(int(request.get('numEls')), start_cursor=cursor) if (request.get('prev_go') == 'older'): posts, next_cursor, more = query.fetch_page(limit, start_cursor=next_cursor) ''' posts es devuelto como una lista inversa ''' return posts[::-1], next_cursor, more
def update(self): toUpdate = self.request.get('id') post = Post.get_by_id(int(toUpdate)) post.description = self.request.get('description') post.last_edit_author = str(users.get_current_user()) if post.description and post.last_edit_author and toUpdate: post.put() self.redirect("/?msg=El post ha sido editado correctamente.") else: self.redirect('/?msg=El post no ha podido actualizarse.')
def submit_post(key): user = active_user() if has_permission(user,'create-post'): post = Post() thread = Thread.load(decrypt(key)) content = bottle.request.forms.get("content","").strip() assert len(content)>0 post.update({"content":content,"owner":user.key}) thread.posts.append(post) thread.save() post.save()
def post(self, post_id): post = Post.get_by_id(int(post_id)) content = self.request.get('content') # let's check if user is logged in if self.user: # and there is something in the content field if content: comment = Comment(post=post, user=User.by_id(self.uid()), content=content) comment.put() self.render_post(post) else: error = "Your comment can't be empty" self.render_post(post, error) # user not logged in, let's go to the login page else: self.redirect('/login')
def post(self, post_id): post = Post.by_id(int(post_id)) subject = self.request.get('subject') content = self.request.get('content') # check if we have both subject and content if subject and content: # check if the user is the post owner or somebody cheating if post.user.key().id() == self.uid(): post.subject = subject post.content = content post.put() self.redirect('/') # if something is missing, let's show it to the user else: error = 'Sorry, we need both, title and content.' self.render('edit-post.html', post=post, user=self.user, error=error)
def post(self, post_id): post = Post.get_by_id(int(post_id)) content = self.request.get('content') # let's check if user is logged in if self.user: # and there is something in the content field if content: comment = Comment( post=post, user=User.by_id(self.uid()), content=content ) comment.put() self.render_post(post) else: error = "Your comment can't be empty" self.render_post(post, error) # user not logged in, let's go to the login page else: self.redirect('/login')
def post(self, post_id): post = Post.by_id(int(post_id)) subject = self.request.get('subject') content = self.request.get('content') # check if we have both subject and content if subject and content: # check if the user is the post owner or somebody cheating if post.user.key().id() == self.uid(): post.subject = subject post.content = content post.put() self.redirect('/') # if something is missing, let's show it to the user else: error = 'Sorry, we need both, title and content.' self.render( 'edit-post.html', post=post, user=self.user, error=error )
def get_posts(s_, g): url, forum_id, t_id, year = g if year == 2018: resp = s_.post(url, data={ "rem": "Remove", "ac_year": year, "ac_day": "", "ac_month": "" }) else: resp = s_.post(url, data={ "set": "GO", "ac_year": year, "ac_day": "", "ac_month": "" }) d = pq(resp.text) found_posts = [] z = d.find(".post") for h in z: post_id = int(re.match("post(\d+)", d(h).attr("id")).group(1)) user_id = int( re.search("userid-(\d+)", d(h).find(".userinfo").attr("class")).group(1)) post_body = d(h).find(".postbody").html() fail = [ "<!-- google_ad_section_start -->", "<!-- google_ad_section_end -->" ] for f in fail: post_body = post_body.replace(f, "") post_date_str = d(h).find(".postdate").text().replace( "#", "").replace("?", "").strip() post_date = datetime.strptime(post_date_str, '%b %d, %Y %H:%M') p = Post.insert(post_id, user_id, post_body, t_id, post_date) found_posts += [p] return found_posts
def post(self): # somebody is trying to vote, let's check if is logged in if self.user: post = Post.by_id(int(self.request.get('post_id'))) user = self.user vote = int(self.request.get('vote')) # prepare the new vote new_vote = Vote(post=post, user=user, vote=vote) # check the user has not voted on this post before no_vote = True votes = Vote.by_post(post) for v in votes: # if user has already voted then False if v.user.key().id() == self.uid(): no_vote = False # has not voted before, let's put the vote if no_vote: new_vote.put() self.redirect('/') # not logged in, let's go to the login page else: self.redirect('/login')
def get(self): posts = Post.get_all() self.render('home.html', posts=posts, user=self.user)
def post(self, post_id): post = Post.get_by_id(int(post_id)) # check if the user is the post owner if post.user.key().id() == self.uid(): post.delete() self.redirect('/')
def get(self, post_id): post = Post.get_by_id(int(post_id)) self.render('delete-post.html', post=post, user=self.user)
def init(): try: Post.init("posts") except Exception as e: print(e)
def get(self, post_id): post = Post.get_by_id(int(post_id)) self.render_post(post)
def get(self): posts = Post.all().order('-created').fetch(limit=10) self.render('index.html', posts=posts)
def _get_posts_with_condition(cursor, limit, condition): return Post.query(condition).order( -Post.date ).fetch_page(limit, start_cursor=cursor)
def get_posts_in(urlsafe_chatroom_id): chatroom = get_chatroom(urlsafe_chatroom_id) return Post.query(Post.chatroom_key == chatroom.key).fetch()
def create(self) -> Post: return Post( title=self.fake.name(), content=self.fake.text(), )