Exemplo n.º 1
0
def edit(title):
    Title = "Edit Article"
    form = ArticleForm()
    article = posts.find_one({'title': title})
    form.title.data = article['title']
    form.body.data = article['body']

    if request.method == 'POST' and form.validate_on_submit():
        title = request.form['title']
        body = request.form['body']
        posts.update_one({'_id': article['_id']}, {
            "$set": {
                'title': title,
                'body': body,
                'timestamp': datetime.datetime.now().strftime('%d-%m-%Y %H:%M')
            }
        })

        flash('Article Edited.', 'success')
        return redirect(url_for("articles"))

    return render_template("edit.html",
                           article=article,
                           title=Title,
                           form=form)
Exemplo n.º 2
0
def create_article():
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        title = article_form.title.data
        body = article_form.body.data
        address = article_form.address.data
        img = article_form.img.data
        category_id = article_form.category_id.data
        author_id = current_user.name
        phone_number = article_form.phone_number.data
        article = Post(title=title, body=body,address=address,category_id=category_id,img=img,phone_number=phone_number,author_id=author_id)
        db.session.add(article)
        db.session.commit()
        return redirect('/')
    return render_template('add.html', form=article_form)
Exemplo n.º 3
0
def add_article():
    title = "Blog"
    form = ArticleForm()

    if request.method == 'POST' and form.validate_on_submit():
        user = users.find_one({'username': current_user.username})

        articles = {
            'title': form.title.data,
            'body': form.body.data,
            'timestamp': datetime.datetime.now().strftime('%d-%m-%Y %H:%M'),
            'user_id': user['_id'],
            'author': user['username'],
            'comments': {}
        }

        if user:
            posts.insert(articles)

        flash('Article Created', 'success')
        return redirect(url_for('dashboard'))

    return render_template("add_article.html", form=form, title=title)
Exemplo n.º 4
0
def newarti():
    form = ArticleForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            ar = Article()
            ar.create_time = request.form.get('create_time')
            ar.project_type = request.form.get('project_type')
            ar.project_name = request.form.get('project_name')
            ar.fiber_type = request.form.get('fiber_type')
            ar.fiber_length = request.form.get('fiber_length')
            ar.closure_type = request.form.get('closure_type')
            ar.closure_number = request.form.get('closure_number')
            ar.other_things = request.form.get('other_things')
            ar.reason = request.form.get('reason')
            ar.recycle_fiber_type = request.form.get('recycle_fiber_type')
            ar.recycle_fiber_length = request.form.get('recycle_fiber_length')
            ar.create_user_id = current_user.id
            ar.approver_id = current_user.id
            db.session.add(ar)
            db.session.commit()
            return redirect('/newarti')

    articles = Article.query.filter_by(create_user_id=current_user.id)
    return render_template("createArti.html", form=form, articles=articles)