コード例 #1
0
ファイル: admin.py プロジェクト: rylew2/FundNotify
def edit_blog(blog_id):
    if not current_user.is_admin:
        return render_extensions('401.html')

    if request.method == 'POST':
        try:
            content = str(request.form['content'])
        except Exception:
            content = ''

        try:
            slug = str(request.form['slug'])
        except Exception:
            slug = ''

        try:
            title = str(request.form['title'])
        except Exception:
            title = ''

        post = Post(title=title, body=content, slug=slug)
        post.save()

        current_user.posts.append(post)
        current_user.save()

    post_obj = Post.query.filter_by(id=int(blog_id)).first()
    post_content = {
        'title': str(post_obj.title),
        'slug': str(post_obj.slug),
        'body': str(post_obj.body),
    }

    return render_extensions('admin/edit_blog.html', post=post_content)
コード例 #2
0
ファイル: admin.py プロジェクト: rylew2/FundNotify
def new_blog():
    if not current_user.is_admin:
        return render_extensions('401.html')

    if request.method == 'POST':
        try:
            content = str(request.form['content'])
        except Exception:
            content = ''

        try:
            slug = str(request.form['slug'])
        except Exception:
            slug = ''

        try:
            title = str(request.form['title'])
        except Exception:
            title = ''

        post = Post(title=title, body=content, slug=slug)
        post.save()

        current_user.posts.append(post)
        current_user.save()

    return render_extensions('admin/new_blog.html')
コード例 #3
0
ファイル: blog.py プロジェクト: rylew2/FundNotify
def blog_page(page=None):
    """

    :param page:
    :return:
    """

    page = int(page)
    _page_size = 3  # TODO: move into settings

    if page is None or page <= 0:
        next_page = 0
        prev_page = 1
        current = True
    else:
        next_page = page - 1
        prev_page = page + 1
        current = False

    posts = get_page(_page_size, page)

    return render_extensions("blog/blog_page.html",
                             posts=posts,
                             next_page=next_page,
                             prev_page=prev_page,
                             current=current)
コード例 #4
0
ファイル: blog.py プロジェクト: rylew2/FundNotify
def blog_detail(pk):
    """

    :param pk:
    :return:
    """

    post = get_post_detail(int(pk))
    return render_extensions("blog/blog_detail.html", post=post)
コード例 #5
0
def home():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            redirect_url = request.args.get("next") or url_for("user.profile")
            return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_extensions("public/home.html", form=form)
コード例 #6
0
def register():
    form = RegisterForm(request.form, csrf_enabled=False)
    if form.validate_on_submit():
        new_user = User.create(username=form.username.data,
                               first_name=form.first_name.data,
                               last_name=form.last_name.data,
                               email=form.email.data,
                               password=form.password.data,
                               active=True)
        flash("Thank you for registering. You can now log in.", 'success')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_extensions('public/register.html', form=form)
コード例 #7
0
def about():
    form = LoginForm(request.form)
    return render_extensions("public/about.html", form=form)