Exemple #1
0
def update_post(article_title):
    a = find_art(article_title)
    if not a:
        flash(f"Article not found")
        return redirect(url_for("home"))
    i, a = a
    f = ArticleForm()
    if request.method == "GET":
        f.title.data = a.get("title")
        f.body.data = a.get("body")
        f.url.data = a.get("url")
        f.source.data = a.get("source")
        f.author.data = a.get("author")
        f.date.data = a.get("date")
    if request.method == "POST":
        req = request.form.copy()
        req["body"] = req["body"].replace("\r", "")
        articles.pop(i)
        articles.insert(i, req)
    if f.validate_on_submit():
        flash(f"Updated {f.title.data}", "success")
        if f.homesub.data:
            return redirect(url_for("home"))
        if f.nextsub.data:
            if len(articles) <= i + 1:
                # flash(f"Updated {f.title.data} TESTING", "success")
                return redirect(url_for("add_article"))
            else:
                return redirect(
                    url_for("update_post",
                            article_title=articles[i + 1]['title']))
    return render_template("article_form.html", form=f, legend="Create Post")
Exemple #2
0
def create_article():
    categories = Categories.query.all()
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        title = article_form.title.data
        body = article_form.body.data
        category_id = article_form.category_id.data
        author_id = current_user.id
        image = article_form.image.data
        date = datetime.datetime.now().strftime('%d.%m..%Y')
        if image is not None or image != '':
            img = True
        else:
            img = False
        if len(body) > 300:
            big_body = True
        else:
            big_body = False
        article = Article(title=title,
                          body=body,
                          category_id=category_id,
                          author_id=author_id,
                          img=img,
                          img_url=image,
                          big=big_body,
                          date=date)
        db.session.add(article)
        db.session.commit()
        return redirect(url_for('homepage'))
    return render_template('new_article.html',
                           form=article_form,
                           categories=categories)
Exemple #3
0
def art_add():
    articleform=ArticleForm()
    if articleform.validate_on_submit():
        data=articleform.data
        #update picture
        datas=secure_filename(articleform.logo.data.filename)
        logo=change_filename(datas)
        if not os.path.exists(app.config["UP"]):
            os.makedirs(app.config["UP"])
        #save file
        articleform.logo.data.save(app.config["UP"]+"/"+logo)
        #get userID
        user=User.query.filter_by(username=session["user"]).first()

        user_id=user.id
        #save data
        articale =Article(
            title=data["title"],
            category=data["category"],
            user_id=user_id,
            logo=logo,
            content=data["content"],
            addTime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        )
        db.session.add(articale)
        db.session.commit()
        flash(u"Add review successfully!","ok")


    return render_template("artadd.html",form=articleform)
Exemple #4
0
def edit_article(article_id):
    article1 = Article.query.get_or_404(article_id)
    form = ArticleForm(obj=article1)
    if form.validate_on_submit():
        form.update_article(article1)
        return redirect(url_for('article'))
    return render_template('admin/edit_article.html',
                           form=form,
                           article=article1)
Exemple #5
0
def add_article():
    f = ArticleForm()
    if request.method == "POST":
        req = request.form.copy()
        req["body"] = req["body"].replace("\r", "")
        articles.append(req)
    if f.validate_on_submit():
        flash(f"Added {f.title.data}", "success")
        return redirect(url_for("home"))
    return render_template("article_form.html", form=f, legend="Create Post")
Exemple #6
0
def article_update(id):
	article = Article.query.get(id)
	form = ArticleForm(request.form, obj=article)
	if request.method == 'POST':
		if form.validate_on_submit():
			form.populate_obj(article)
			db.session.commit()
		
			flash(u'게시글을 수정하였습니다.', 'success')
			return redirect(url_for('article_list'))

	return render_template('article/update.html', form=form, active_tab='article_update')
Exemple #7
0
def new_article():
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        article = Article()
        article.form_to_object(article_form)
        article.new_article(current_user.id)
        flash('文章提交成功')
        return redirect(
            url_for('views_blueprint.get_article_by_id',
                    article_id=article.id))
    return new_render_template('edit_article.html',
                               form=article_form,
                               page_title='NEW ARTICLE')
Exemple #8
0
def dashboard():
    form = ArticleForm()
    if request.method == 'POST' and form.validate_on_submit():
        details = request.form
        title = details['title']
        content = details['body']
        cur = mysql.connection.cursor()
        cur.execute("INSERT INTO articles(title,body,author) values(%s,%s,%s)",
                    (title, content, session['s_name']))
        mysql.connection.commit()
        cur.close()
        flash(f'Article posted', 'success')
        return redirect(url_for("home"))
    return render_template("dashboard.html", form=form)
Exemple #9
0
def new_article():
    form = ArticleForm()
    if form.validate_on_submit():
        title = form.title.data
        body = form.body.data
        is_verified = form.is_verified.data
        article = Article(title=title,
                          body=body,
                          is_verified=is_verified,
                          user=current_user)
        db.session.add(article)
        db.session.commit()
        return redirect(url_for("get_article", article_id=article.id))
    return render_template('new_article.html', form=form)
Exemple #10
0
def newarticle():
    form = ArticleForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            title=form.data['title']
    	    body = form.data['body']
	    a=Article(title=title,body=body,timestamp=datetime.datetime.now(),author=g.user)
	    try:
	        db.session.add(a)
	        db.session.commit()
	        flash(u'发帖完成')
	    except Exception, e:
	        flash(u'发帖失败')
            return render_template('newarticle.html', title = 'newarticle',form = form)
Exemple #11
0
def edit_article(article_id):
    article = Article()
    article.search_by_id(article_id)
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        article.form_to_object(article_form)
        article.update_article()
        flash('文章更新成功')
        return redirect(
            url_for('views_blueprint.get_article_by_id',
                    article_id=article.id))
    article_form.object_to_form(article)  # ??此行语句位置对功能实现有重大影响
    return new_render_template('edit_article.html',
                               form=article_form,
                               page_title='EDIT ARTICLE')
Exemple #12
0
def edit_article(article_id):
    article: Article = Article.query.filter_by(id=article_id).first()
    form = ArticleForm()
    if form.validate_on_submit():
        article.title = form.title.data
        article.body = form.body.data
        article.is_verified = form.is_verified.data
        db.session.add(article)
        db.session.commit()
        return redirect(url_for("get_article", article_id=article.id))
    else:
        form.title.data = article.title
        form.body.data = article.body
        form.is_verified.data = article.is_verified
        return render_template('edit_article.html', form=form)
Exemple #13
0
def write_submit():
    form = ArticleForm()
    if not form.validate_on_submit():
        logger.debug(form.referer)
        abort(400)
    article = Article()
    article.id = form.id.data
    article.author = current_user.nickname
    article.title = form.title.data
    article.ms_title = ''
    article.classification = form.classification.data
    article.content = xss_clean(form.content.data)
    article.manuscript = ''
    article.last_modified_time = datetime.datetime.now()
    article.visibility = 1
    check_article = db.session.query(Article).filter(
        Article.id == article.id).scalar()
    if check_article and (check_article.author != current_user.nickname):
        #no right to modified
        logger.debug('you can\'t')
        abort(400)
    try:
        db.session.merge(article)
        # db.session.merge(article)
        db.session.commit()
        article_info = {
            'id':
            article.id,
            'author':
            article.author,
            'title':
            article.title,
            'classification':
            article.classification,
            'classification_obj':
            article.classification_obj,
            'create_time':
            str(article.create_time),
            'last_modified_time':
            article.last_modified_time.strftime('%Y-%m-%d %H:%M:%S'),
            'key_word':
            article.key_word
        }
        redis.hmset('articles', {article.id: json.dumps(article_info)})
    except Exception, e:
        logger.debug(e)
        db.session.rollback()
        abort(500)
Exemple #14
0
def create_article():
    article_form = ArticleForm()
    if article_form.validate_on_submit():
        title = article_form.title.data
        body = article_form.body.data
        category_id = article_form.category_id.data
        author_id = current_user.id

        article = Article(title=title, body=body, category_id=category_id, author_id=author_id)
        db.session.add(article)
        db.session.commit()

        flash(f'Создана статья "{article.title}" (#{article.id})', category='success')

        return redirect(url_for('homepage'))

    return render_template('new_article.html', form=article_form)
Exemple #15
0
def add_note():
    """Add a note."""
    form = ArticleForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # Get the right number - the article ID
            number = 1
            notes = Note.all().order('-number')
            if notes.count() > 0:
                number = notes[0].number + 1

            note = Note(
                number=number,
                title=form.title.data,
                content=form.content.data,
                tags=form.tags.data,
            )
            note.save()
            return redirect(note.get_absolute_url())
    action_url = url_for('add_note')
    return render_template('add_note.html', form=form, action_url=action_url)
Exemple #16
0
def edit_article(number):
    """Add a article."""
    article = get_aritle_by_number(number)
    if article is None:
        return render_template('404.html'), 404

    form = ArticleForm(
        title=article.title,
        content=article.content,
        is_public=article.is_public,
        tags=article.tags,
    )
    if request.method == 'POST':
        if form.validate_on_submit():
            article.title = form.title.data
            article.content = form.content.data
            article.is_public = form.is_public.data
            article.tags = form.tags.data
            article.save()
            return redirect(article.get_absolute_url())
    action_url = url_for('edit_article', number=number)
    return render_template('add_article.html', form=form, action_url=action_url)
Exemple #17
0
def edit_article(id):
    form = ArticleForm()
    cur = mysql.connection.cursor()
    details = request.form
    cur.execute("select title,body from articles where id=%s", [id])
    res = cur.fetchone()
    #populate the data intially
    form.title.data = res[0]
    form.body.data = res[1]
    #details['body'] = res[1]
    if request.method == 'POST' and form.validate_on_submit():

        title = details['title']
        content = details['body']

        cur.execute("update articles set title=%s,body=%s where id=%s",
                    [title, content, id])
        mysql.connection.commit()
        cur.close()
        flash(f'Article Updated', 'success')
        return redirect(url_for("home"))
    return render_template("dashboard.html", form=form)
Exemple #18
0
def write_auto_save():
    form = ArticleForm()
    if not form.validate_on_submit():
        abort(400)
    article = Article()
    article.id = form.id.data
    article.ms_title = form.title.data
    article.manuscript = xss_clean(form.content.data)
    article.author = current_user.nickname
    check_article = db.session.query(Article).filter(
        Article.id == article.id).scalar()
    if check_article and (check_article.author != current_user.nickname):
        #no right to modified
        abort(400)
    try:
        db.session.merge(article)
        # db.session.merge(article)
        db.session.commit()
    except Exception, e:
        logger.debug(e)
        db.session.rollback()
        return json.dumps({'result': False})
Exemple #19
0
def add_article():
    form = ArticleForm()
    if form.validate_on_submit():
        if form.name.data != get_credential_name() or form.password.data != get_credential_password():
            return render_template("/add_article.html", form=form)
        indata = Article(form.data)
        data = copy(indata.__dict__)
        del data["_sa_instance_state"]
        last = Article.query.order_by(Article.id.desc()).first()
        if last:
            indata.id = last.id + 1
        else:
            indata.id = 1
        try:
            db.session.add(indata)
            db.session.commit()
        except Exception as e:
            print("\n FAILED entry: {}\n".format(json.dumps(data)))
            print(e)
            sys.stdout.flush()
            return redirect(url_for("manager.errors", errors="\n FAILED entry: {}\n".format(json.dumps(data))))
        return redirect(url_for("manager.success"))
    return render_template("/add_article.html", form=form)
Exemple #20
0
def article_create():
	form = ArticleForm()

	# if request.method == 'GET':
	# 	return render_template('article/create.html', active_tab='article_create')
	# elif request.method == 'POST':
	if request.method == 'POST':
		if form.validate_on_submit():

			article = Article(
				title=form.title.data,
				author=form.author.data,
				category=form.category.data,
				content=form.content.data
			)

			db.session.add(article)
			db.session.commit()

			flash(u'게시글을 작성하였습니다.', 'success')
			return redirect(url_for('article_list'))

	return render_template('article/create.html', form=form, active_tab='article_create')
Exemple #21
0
def article_create():
    if g.user_name == None:
        flash(u'로그인 후 이용해주세요.', 'danger')
        return redirect(url_for('log_in'))
    else:
        form = ArticleForm()
        if request.method == 'POST':
            if form.validate_on_submit():

                article = Article(
                    title = form.title.data,
                    author = form.author.data,
                    category = form.category.data,
                    content = form.content.data,
                )

            db.session.add(article)
            db.session.commit()

            flash(u'게시글을 작성하였습니다.', 'success')
            return redirect(url_for('article_list'))

    return render_template('article/create.html', form=form, active_tab='article_create')
Exemple #22
0
def add_article():
    form = ArticleForm()
    if form.validate_on_submit():
        form.create_article()
        return redirect(url_for('article'))
    return render_template('admin/add_article.html', form=form)