def edit(page_id, post_id=None): # dealing with editing a new page or existing page if post_id is None: return template('page_edit.html', data=db.get_posts(page_id, post_id)) else: # dealing with editing or creating a new post belonging to a page return template('post_edit.html', data=db.get_posts(page_id, post_id), authors=db.get_authors())
def test_get_stars(self): user_id1 = "user_id1" user_id2 = "user_id2" hash_tag = "hash_tag" creator_id = "creator_id" # Write the first post by a user. insert_now1 = datetime(2010, 6, 23) insert_data1 = PostInsertData(creator_id, "data1", [hash_tag], insert_now1) post_id1 = self._add_post(insert_data1) # Write the second post by a user. insert_now2 = datetime(2011, 7, 24) insert_data2 = PostInsertData(creator_id, "data2", [hash_tag], insert_now2) post_id2 = self._add_post(insert_data2) # The first user stars the first post. starred_now1 = datetime(2012, 8, 25) db.star_post(user_id1, post_id1, starred_now1) self._assert_post(insert_data1, db.get_post(user_id1, post_id1), True, 1) self._assert_post(insert_data1, db.get_post(user_id2, post_id1), False, 1) # The second user stars the first post. starred_now2 = datetime(2013, 9, 26) db.star_post(user_id2, post_id1, starred_now2) self._assert_post(insert_data1, db.get_post(user_id1, post_id1), True, 2) self._assert_post(insert_data1, db.get_post(user_id2, post_id1), True, 2) # The first user stars the second post. starred_now3 = datetime(2014, 10, 27) db.star_post(user_id1, post_id2, starred_now3) self._assert_post(insert_data2, db.get_post(user_id1, post_id2), True, 1) self._assert_post(insert_data2, db.get_post(user_id2, post_id2), False, 1) # Get both stars for the first post. # Assert that the second user is returned first because its star is more recent. self._assert_stars(post_id1, [user_id2, user_id1]) # Assert that the second post is starred only by the first user. self._assert_stars(post_id2, [user_id1]) def _assert_user_id1_posts(user_id1_posts): self.assertEqual(2, len(user_id1_posts)) self._assert_post(insert_data2, user_id1_posts[0], True, 1) self._assert_post(insert_data1, user_id1_posts[1], True, 2) def _assert_user_id2_posts(user_id2_posts): self.assertEqual(2, len(user_id2_posts)) self._assert_post(insert_data2, user_id2_posts[0], False, 1) self._assert_post(insert_data1, user_id2_posts[1], True, 2) # Assert that the stars are seen by each user for all posts. _assert_user_id1_posts(db.get_posts(user_id1)) _assert_user_id2_posts(db.get_posts(user_id2)) # Assert that the stars are seen by each user for all posts with a hash tag. _assert_user_id1_posts(db.get_posts_with_hashtag(user_id1, hash_tag)) _assert_user_id2_posts(db.get_posts_with_hashtag(user_id2, hash_tag)) # Assert that the stars are seen by each user for all posts by a given user. _assert_user_id1_posts(db.get_posts_by_user(user_id1, creator_id)) _assert_user_id2_posts(db.get_posts_by_user(user_id2, creator_id))
def profile(): username = current_user.username if username: posts = get_posts() return render_template('profile.html', posts=posts, username=username) else: return redirect(url_for('home'))
def index(request): users = get_users(session, request.session['username'])[1] posts = get_posts(session, request.session['username'])[1] return render_template('index.html', username=request.session['username'], name=request.session['name'], users=users, posts=posts)
def posts(): if flask.g.logged_in: all_posts = db.get_posts(flask.g.user_id) renderable_all_posts = _get_renderable_post_sequence(all_posts) summary = resource_summary.summary_for_renderable_post_sequence(renderable_all_posts) now = datetime.utcnow() return flask.render_template("all_posts.html", posts=renderable_all_posts, resource_summary=summary, now_datetime=now) else: return flask.render_template("sign_in.html")
def posts(site_id, page_id, action): # if id is 'new', then create page if action == 'list': page_name = get_page_name(site_id, page_id) return template('page.html', data=get_posts(site_id, page_id), page=page_name, site=site_id) # if page_id == 'new': # return template('page_edit.html', data=None) # else get list of posts for this page else: return template('page.html', data=db.get_posts(page_id))
def index(): if request.method == "POST": if not "uuid" in session: session["uuid"] = str(uuid.uuid4()) content = request.form.get("content")[:280] post_id = make_post(session["uuid"], content) return redirect("/post?id=" + str(post_id)) posts = [] if "uuid" in session: posts = get_posts(session["uuid"]) return render_template("index.html", posts=posts, csp=get_csp())
def GET(self, tid): tid = utils.dec_tid(tid) # tid can be entered in URL, so we need to verify if it is valid if not db.is_thread(tid): return 'Access denied' # page doesn't exist # check if current user is on the list of users of this thread user = db.get_user(session.uid) (guests, uids) = db.get_thread_users(db.get_lang(session.uid), tid) if uids and session.uid not in uids: return 'Access denied' # tid is out of the list of users # if page is refreshed or the user switches between edit and # preview mode, we want to preserve the text in textarea message = session.page_data['message'] if session.page_data['preview']: message = utils.markdown_to_html(message) # emoticons come from http://www.veryicon.com/icons/emoticon/the-black/ # read names of emot icons and split the list into N rows emots = os.listdir('static' + os.sep + 'em') emots = zip(*[iter(emots)]*(len(emots)//config.emots_rows)) html = render.thread(tr.text[db.get_lang(session.uid)], db.get_posts(session.uid, tid), user['nick'], user['name'], utils.hue_to_color(user['hue']), guests, db.get_thread_title(tid), session.page_data['preview'], message, emots) # save the fact of visiting this thread in history db.mark_read(session.uid, tid) return html
def test_get_posts(self): # Write the first post by one user. hash_tags1 = ["hash_tag1", "hash_tag2"] now1 = datetime(2013, 9, 26) insert_data1 = PostInsertData("user_id1", "data1", hash_tags1, now1) post_id1 = self._add_post(insert_data1) # Write the second post by another user. hash_tags2 = ["hash_tag3"] now2 = datetime(2014, 10, 27) insert_data2 = PostInsertData("user_id2", "data2", hash_tags2, now2) post_id2 = self._add_post(insert_data2) # Assert that the first post is read correctly. self._assert_post(insert_data1, db.get_post(self.client_id, post_id1)) # Assert that the second post is read correctly. self._assert_post(insert_data2, db.get_post(self.client_id, post_id2)) # Get both posts. all_posts = db.get_posts(self.client_id) self.assertEqual(2, len(all_posts)) # Assert that the second post is returned first because it is more recent. self._assert_post(insert_data2, all_posts[0], 0) # Assert that the first post is returned last because it is less recent. self._assert_post(insert_data1, all_posts[1], 0)
def get_positives(): #req = json.loads(request.data) #data = json.loads(req['data']) return get_posts()
def GET(self): posts = db.get_posts() return render.site(render.index(posts))
def index(self): posts = [dereference_author(p) for p in db.get_posts()] return {"posts":posts, "page_title": "Home"}
def index(): posts = db.get_posts() return render_template('index.html', posts=posts)
def home(): ''' This method is used to diplay the home page. ''' rows = db.get_posts(posts=20) return render_template("home.html", rows=rows)
def GET(self): posts = db.get_posts() return json_response(posts)