def render_page(content_id): content = Content.get(content_id) if not content: content = Content.filter(Content.slug == content_id).first() return render(content.template, user=import_user(), content=content, menu_items=get_menu_items())
def before_app_request(): g.user = None # g.theme = g.upload_directory = get_setting('upload-directory', 'uploads/') g.allowed_extensions = get_setting('allowed-extensions', ['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'tiff']) g.max_file_size = get_setting('max-file-size', 16777216) # 16 MB g.user = import_user()
def search_page(): payload = get_payload(request) search = payload.get('search') contents = Content.filter(or_(Content.body.ilike('%{}%'.format(search)), Content.tags.ilike('%{}%'.format(search)), Content.title.ilike('%{}%'.format(search))))\ .filter(Content.published == True).all() return render('search.html', user=import_user(), contents=contents, menu_items=get_menu_items())
def render_post(content_id): tag_chunks = [] tags = json.loads(get_tags_in_use()) if tags: if len(tags) > 16: tags = tags[:16] tag_chunks = chunks(tags, 4) content = Content.get(content_id) if not content: content = Content.filter(Content.slug == content_id).first() return render(content.template, user=import_user(), content=content, tag_chunks=tag_chunks, menu_items=get_menu_items())
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())