コード例 #1
0
ファイル: routes.py プロジェクト: AlexYov/First_Flask_App
def index():

    title = 'Homepage'
    users = User.query.all()
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Пост опубликован')
        return redirect(url_for('auth.index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.followed_posts().paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    next_page = None
    prev_page = None
    if posts.has_next:
        next_page = url_for('auth.index', page=posts.next_num)
    if posts.has_prev:
        prev_page = url_for('auth.index', page=posts.prev_num)
    return render_template('index.html',
                           title=title,
                           users=users,
                           posts=posts.items,
                           form=form,
                           next_page=next_page,
                           prev_page=prev_page)
コード例 #2
0
def index():
    form = PostForm()
    if current_user.can(Permission.WRITE_ARTICLES) and \
        form.validate_on_submit():
        post = Post(body=form.body.data,
                    author=current_user._get_current_object())
        db.session.add(post)
        return redirect(url_for('.index'))
    page = request.args.get('page', 1, type=int)
    show_followed = False
    if current_user.is_authenticated:
        show_followed = bool(request.cookies.get('show_followed'))
    if show_followed:
        query = current_user.followed_posts
    else:
        query = Post.query
    pagination = query.order_by(Post.timestamp.desc()).paginate(
        page,
        per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
        error_out=False)
    posts = pagination.items
    return render_template('index.html',
                           form=form,
                           posts=posts,
                           pagination=pagination,
                           show_followed=show_followed)
コード例 #3
0
ファイル: views.py プロジェクト: BohnSix/myblog
def wbsy():
    form = PostForm()
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.timestamp.desc()).paginate(
        page, current_app.config['POSTS_PER_PAGE'], False)
    blog_info = BlogInfo.query.first()
    next_url = url_for('main.wbsy',
                       page=posts.next_num if posts.has_next else None)
    prev_url = url_for('main.wbsy',
                       page=posts.prev_num if posts.has_prev else None)

    if form.validate_on_submit():
        post = Post(content=form.content.data, timestamp=datetime.now())
        db.session.add(post)
        db.session.commit()
        return redirect(
            url_for('auth.wbsy',
                    form=form,
                    posts=posts.items,
                    blog_info=blog_info,
                    next_url=next_url,
                    prev_url=prev_url))
    return render_template('wbsy.html',
                           form=form,
                           posts=posts.items,
                           blog_info=blog_info,
                           next_url=next_url,
                           prev_url=prev_url)
コード例 #4
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your submission is processing!')
        return redirect(url_for('main.submission'))
    return render_template("index.html", title='Home Page', form=form)
コード例 #5
0
ファイル: routes.py プロジェクト: mikescor/login-service
def index():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post is now live!')
        return redirect(url_for('main.index'))
    return render_template('index.html', title='Home', form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: rioadinugraha/herokutest
def make_event():
    form = PostForm()
    if form.is_submitted():
        print("submitted")
    if form.validate():
        print("valid")

    if form.validate_on_submit():
        print(form.errors)
        print(form.image.data)
        if not form.image.data:
            print('no files has been uploaded')
            post = Post(title=form.title.data,
                        body=form.details.data,
                        user_id=current_user.id,
                        max_participant=form.max_participant.data,
                        start_time=form.start_time.data,
                        socialHours=form.socialHours.data)
        else:
            f = form.image.data
            filename = secure_filename(f.filename)
            f.save(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
            print(os.path.join(current_app.config['UPLOAD_FOLDER'], filename))
            url = url_for('auth.download_file', filename=filename)
            # filename = images.save(form.image.data)
            # print(filename)
            # url = images.path(filename)
            # print(url)
            # url = images.url(filename)
            # print(url)
            # url = url [11:]

            filedata = {"image_filename": filename, "image_url": url}
            # filedata = jsonify(filedata)
            try:
                new_Post = requests.post(
                    "http://localhost:5001/images/", json=filedata
                )  #CHANGE THIS LINK TO WHATEVER DOMAIN U HAVE FOR THE MICROSERVICE
            except requests.exceptions.ConnectionError:
                flash("image upload service unavailable")
                redirect(url_for("auth.make_event"))

            post = Post(title=form.title.data,
                        body=form.details.data,
                        user_id=current_user.id,
                        max_participant=form.max_participant.data,
                        start_time=form.start_time.data,
                        socialHours=form.socialHours.data,
                        filename=filename)
        db.session.add(post)
        db.session.commit()
        flash('We have received your application', 'success')
        return redirect(url_for('auth.index'))
    return render_template('make_event.html', user=current_user, form=form)
コード例 #7
0
def edit(id):
    post = Post.query.get_or_404(id)
    if current_user != post.author and \
        not current_user.can(Permission.ADMINISTER):
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.body = form.body.data
        db.session.add(post)
        flash('这篇文章已经被更新了')
        return redirect(url_for('.post', id=post.id))
    form.body.data = post.body
    return render_template('edit_post.html', form=form)
コード例 #8
0
def edit():
    form = PostForm()
    if form.validate_on_submit():
        print('hello')
        post = Post(title=form.title.data,
                    body=form.body.data,
                    author=current_user)
        print(post)
        db.session.add(post)
        db.session.commit()
        return redirect(url_for('.post', id=post.id))
    posts = db.session.query(Post.id, Post.title, Post.body).all()

    return render_template('posts/edit.html', form=form, post=posts)
コード例 #9
0
ファイル: views.py プロジェクト: BohnSix/myblog
def edit_post(id):
    post = Post.query.filter_by(id=id).first()
    blog_info = BlogInfo.query.first()
    form = PostForm()

    if form.validate_on_submit():
        post.content = form.content.data
        post.timestamp = datetime.now()
        db.session.commit()
        return redirect(url_for('auth.manage'))

    form.content.data = post.content
    return render_template('auth/editPost.html',
                           form=form,
                           blog_info=blog_info)
コード例 #10
0
ファイル: routes.py プロジェクト: milolou/microblog
def index():
    form = PostForm()
    if form.validate_on_submit():
        language = guess_language(form.post.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        post = Post(body=form.post.data,author=current_user,language=language)
        db.session.add(post)
        db.session.commit()
        flash(_('Your post is now live!'))
        return redirect(url_for('auth.index'))
    page = request.args.get('page',1,type=int)
    posts = current_user.followed_posts().paginate(
        page,app.config['POSTS_PER_PAGE'],False)
    next_url = url_for('auth.index',page=posts.next_num) if posts.has_next else None
    prev_url = url_for('auth.index',page=posts.prev_num) if posts.has_prev else None
    return render_template('index.html',title=_('Home Page'),form=form,
                           posts=posts.items,next_url=next_url,prev_url=prev_url)
コード例 #11
0
def index():
    # user = {'username': '******'}
    # posts = [
    #     {
    #         'author': {'username': '******'},
    #         'body': 'Demo Flask with some seconds'
    #     },
    #     {
    #         'author': {'username': '******'},
    #         'body': 'Code back-end for production'
    #     }
    # ]

    # ==== FORM POST ====
    form = PostForm()
    if form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post is now live!')
        return redirect(url_for('index'))
    page = request.args.get('page', 1, type=int)
    # posts = current_user.followed_posts().all()

    # Tham số 1: số thứ tự trang hiện tại, bắt đầu từ 1
    # Tham số 2: Số đơn vị trên một trang
    # Tham số 3: Cờ hiệu lỗi, True - 404, False trả về rỗng
    posts = current_user.followed_posts().paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('index', page=posts.prev_num) \
        if posts.has_prev else None
    return render_template('index.html',
                           title='Home Page',
                           form=form,
                           posts=posts.items,
                           next_url=next_url,
                           prev_url=prev_url)
コード例 #12
0
def profile():
    form = PostForm()
    user = User.query.filter_by(username=current_user.username).first()
    #print(user.password_hash)
    #print('This is users = ',User.query.order_by(User.username).all())
    if user.number_of_questions == 0:
        msg = 'You do not have enough questions'
    else:
        msg = ''
    if user.number_of_questions != 0 and form.validate_on_submit():
        post = Post(body=form.post.data, author=current_user)
        db.session.add(post)
        
        
        user.number_of_questions = user.number_of_questions - 1
        
        db.session.commit()
        
        msg = 'You will receive a reply soon'
        
    username = current_user.username
    user = User.query.filter_by(username=username).first()
    return render_template('profile.html',msg=msg,year_now=year_now,form=form)