def do_get_posts_success_test(userNum): for i in range(0, userNum): username = "******" + str(i) password = "******" text = "This is test text." utils.get_posts(username, password, text, userNum) print('get posts by normal users success\n')
def sort_user(request,sort): if request.method == 'GET': posts = get_posts() post_form = PostForm() comment_form = CommentForm() if sort == 'mybanks': username = str(request.user) user = get_user(username) likes = [int(like) for like in user.get('likes','')] posts = [post for post in posts if post.get('post_id','') in likes] sorted_posts = sorted(posts,key=get_post_time) posts = list(reversed(sorted_posts)) else: username = str(sort) posts = [post for post in posts if post.get('author','') == username] # if len(posts) > params.post_limit: # posts = posts[:params.post_limit] context = { 'posts':posts, 'post_form':post_form, 'comment_form':comment_form, 'sort':sort, } return render(request,'forum/home.html',context)
def generate(): posts = utils.get_posts() ppp = config['posts_per_page'] pages = int(math.ceil(float(len(posts)) / ppp)) utils.clear_dir('site/page') for i in range(pages): page_content = render_template('frontend/index.html', config=config, frontend=True, current=i + 1, first=(i == 0), last=(i == pages - 1), posts=posts[i * ppp:(i + 1) * ppp]) file('site/page/%s.html' % (i + 1), 'w').write( page_content.encode(config['encoding'])) if i == 0: file('site/index.html', 'w').write( page_content.encode(config['encoding'])) not_found_content = render_template('404.html', config=config, frontend=True) file('site/404.html', 'w').write( not_found_content.encode(config['encoding'])) utils.clear_dir('site/posts') infos = utils.get_post_infos() feed = AtomFeed(config['title'], feed_url=config['url_root'] + '/posts.atom', url=config['url_root']) for info in infos: with open('posts/%s' % info['filename'], 'r') as f: content = f.read().decode(config['encoding']) title = utils.get_title(content) content = utils.postprocess_post_content(info['slug'], content, False) html_content = render_template('frontend/post.html', config=config, frontend=True, title=title, content=content) file('site/posts/%s.html' % info['slug'], 'w').write( html_content.encode(config['encoding'])) feed_content = render_template('feed.html', config=config, content=content) feed.add(title, feed_content, content_type='html', url=make_external('/posts/' + info['slug']), author='Tony Wang', published=utils.date_localize_from_utc(info['time'], True), updated=utils.date_localize_from_utc(info['time'], True)) file('site/posts.atom', 'w').write(str(feed.get_response().iter_encoded(config['encoding']).next())) return 'Done!'
def get(self): posts, age = utils.get_posts() if self.request.url.endswith('.json'): self.response.headers['Content-Type'] = ('application/json; ' 'charset=UTF-8') allPosts = [{'content': p.content, 'created': p.created.strftime('%c'), 'subject': p.subject} for p in Post.query().order(-Post.created)] self.response.write(json.dumps(allPosts)) else: self.render('/templates/blogfront.html', posts=posts, age=utils.age_str(age))
def home(request,*args): posts = get_posts() post_form = PostForm() comment_form = CommentForm() sorted_posts = sorted(posts,key=get_post_time) posts = list(reversed(sorted_posts)) if len(posts) > params.post_limit: posts = posts[:params.post_limit] context = { 'posts':posts, 'post_form':post_form, 'comment_form':comment_form } return render(request,'forum/home.html',context)
def render_result(): """ Redirects to respective pages according to the action chosen by user First page of posts are fetched using the utils method get_posts. Views and Text is passed onto html for display. For add, redirected to an html page to input text. """ action = request.form['action'] session['visibility'] = request.form['vis'] == 'pub' if(action == 'list'): resp = utils.get_posts(g.graph,session['visibility'],session['page']['id']) return render_template('display_posts.html', data = resp, next = resp['next']) elif (action == 'add'): return render_template('input_post.html') else: return redirect(url_for('error')) #TODO: add this page
def sort(request,sort): if request.method == 'GET': posts = get_posts() post_form = PostForm() comment_form = CommentForm() if sort: if sort == 'time': sorted_posts = sorted(posts,key=get_post_time) posts = list(reversed(sorted_posts)) if sort == 'likes': sorted_posts = sorted(posts,key=get_post_likes) posts = list(reversed(sorted_posts)) # if len(posts) > params.post_limit: # posts = posts[:params.post_limit] context = { 'posts':posts, 'post_form':post_form, 'comment_form':comment_form, 'sort':sort, } return render(request,'forum/home.html',context)
def get(self): content = utils.get_posts() self.render_json([p.create_dict() for p in content])
def update_posts(): global posts posts = get_posts(url)