def retrieve_content(): return_value = success('The content was retrieved.') return_value['contents'] = [] payload = get_payload(request) content_id = payload.get('id') if content_id: content = Content.get(content_id) if content: return_value['contents'] = [content.to_dict(camel_case=True)] else: return_value['success'] = False return_value['messages'] = ['No content found with that ID.'] else: # No ID passed... we should return more than one result. current_page = payload.get('current_page', 1) page_size = payload.get('page_size', 5) content_type = payload.get('content_type', 'post') published = payload.get('published', True) contents = Content.filter(Content.type == content_type)\ .filter(Content.published == published)\ .order_by(Content.published_on.desc()) contents, maxpages = paginate(contents, current_page, page_size) if contents: return_value['contents'] = results_to_dict( contents, camel_case=True) return jsonify(return_value)
def retrieve_content(): return_value = success('The content was retrieved.') return_value['contents'] = [] payload = get_payload(request) content_id = payload.get('id') if content_id: content = Content.get(content_id) if content: return_value['contents'] = [content.to_dict(camel_case=True)] else: return_value['success'] = False return_value['messages'] = ['No content found with that ID.'] else: # No ID passed... we should return more than one result. current_page = payload.get('current_page', 1) page_size = payload.get('page_size', 5) content_type = payload.get('content_type', 'post') published = payload.get('published', True) contents = Content.filter(Content.type == content_type)\ .filter(Content.published == published)\ .order_by(Content.published_on.desc()) contents, maxpages = paginate(contents, current_page, page_size) if contents: return_value['contents'] = results_to_dict(contents, camel_case=True) return jsonify(return_value)
def blog_index(page=1, tag=None): tag_chunks = [] tags = json.loads(get_tags_in_use()) if tags: if len(tags) > 16: tags = tags[:16] tag_chunks = chunks(tags, 4) limit = get_setting("posts-per-page", 4) posts = Content.filter(Content.published == True)\ .filter(Content.type == "post")\ .order_by(Content.published_on.desc()) if tag: posts = posts.filter(Content.tags.contains(tag)) posts, max_pages = paginate(posts, page, limit) return render('index.html', user=import_user(), posts=posts, current_page=page, max_pages=max_pages, tag_chunks=tag_chunks, tag=tag, menu_items=get_menu_items())