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 index(): user_count = User.count() print(user_count) if user_count == 0: # Run setup wizard. print('Redirecting to setup.') return redirect(url_for('.setup')) custom_front_page = get_setting('custom-front-page', '') if custom_front_page: try: return render(custom_front_page) except TemplateNotFound: return render("error.html", title="Custom Front Page", error="You have configured a custom front page but the file ({}) was not found in your theme's template directory.".format(custom_front_page)) return redirect('/blog/')
def admin_posts_add(): content = Content() content.created_on = datetime.now() content.body = '' content.title = '' content.tags = '' content.parser = 'markdown' return render('admin_content.html', user=g.user, content_type="Post", action="Add", content=content)
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 main(): """@todo: Docstring for main. :returns: @todo """ # Clear the frozen directory for file in os.listdir(FROZEN_DIR): if file != '.empty': path = os.path.abspath(os.path.join(FROZEN_DIR, file)) if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) # Copy themes theme_dirs = get_theme_dirs() for theme_dir in theme_dirs: dest = os.path.join(FROZEN_DIR, theme_dir[0]) shutil.copytree(theme_dir[1], dest) # Copy Uploads shutil.copytree(os.path.abspath('uploads/'), os.path.abspath(os.path.join(FROZEN_DIR, 'uploads/'))) # Render all the templates with app.app_context(): theme = get_current_theme() app.jinja_env.globals['theme_static'] = theme_static contents = Content.filter(Content.published == True).all() for content in contents: template = content.template f_template = 'freeze-{}'.format(content.template) freeze_template = os.path.join('impression/themes/', theme.identifier, 'templates/', f_template) if (os.path.isfile(os.path.abspath(freeze_template))): template = f_template html = render(template, content=content, menu_items=get_menu_items(), freeze=True) with open('frozen/{}.html'.format(content.slug), 'w') as f: f.write(html)
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())
def logout(): session['userid'] = None return render('login.html')
def setup(): import shlex import subprocess user_count = User.count() # print(user_count) if user_count > 0: # We already have a user. No running setup. return redirect(url_for('.index')) if request.method == 'POST': payload = get_payload(request) if payload.get('email') and payload.get('password'): user = User(username=payload.get('email'), password=payload.get('password'), firstname=payload.get('firstname'), lastname=payload.get('lastname')) my_role = Role(name='admin') my_role.add_abilities('create_users', 'delete_users', 'create_content', 'delete_content', 'upload_files', 'delete_files', 'change_settings') user.add_roles('admin', 'superadmin') login_user(user) args = shlex.split("alembic history") p = subprocess.Popen(args, stdout=subprocess.PIPE) output, error = p.communicate() data = output.split('\n') latest_alembic = None for row in data: if "(head)" in row: cols = row.split(" ") latest_alembic = cols[2].strip() if latest_alembic: print("Stamping with latest Alembic revision: %s" % latest_alembic) args = shlex.split("alembic stamp %s" % latest_alembic) subprocess.Popen(args, stdout=subprocess.PIPE) from impression.upgrade import THEMES, SYNTAX_THEMES # Create some system settings Setting(name='blog-title', vartype='str', system=True).insert() Setting(name='blog-copyright', vartype='str', system=True).insert() Setting(name='blog-theme', vartype='str', system=True, value='impression').insert() Setting(name='posts-per-page', vartype='int', system=True, value=4).insert() Setting(name='bootstrap-theme', vartype='str', system=True, value='sandstone', allowed=json.dumps(THEMES)).insert() Setting(name='syntax-highlighting-theme', vartype='str', system=True, value='monokai.css', allowed=json.dumps(SYNTAX_THEMES)).insert() Setting(name='custom-front-page', vartype='str', system=True).insert() Setting(name='allowed-extensions', vartype='list', system=True, value="['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif', 'tiff']").insert() Setting(name='upload-directory', vartype='str', system=True, value='uploads/').insert() Setting(name='max-file-size', vartype='int', system=True, value=16777216).insert() safe_commit() flash("Initial Setup Complete", "success") return redirect(url_for('admin_controller.admin_settings')) return render('setup.html')
def admin_files_list(): files = File.all() return render('admin_files_list.html', files=files)
def admin_posts_edit(content_id): content = Content.get(content_id) return render('admin_content.html', user=g.user, content_type=content.type, action="Edit", content=content)
def admin_files_add(): return render('admin_file.html')
def render_page(content_id): content = Content.get(content_id) if not content: content = Content.filter(Content.slug == content_id).first() return render('page.html', user=g.user, content=content)
def login(): if g.user and g.user.admin: return redirect(url_for('admin')) return render('login.html')
def index(): return render('index.html', user=g.user)
def admin(): return render('admin_index.html', user=g.user)
def admin_posts_list(): contents = Content.filter(Content.type == 'post').all() return render('admin_content_list.html', contents=contents, content_type="Posts")