Exemple #1
0
def add_article():
    if request.method == 'GET':
        lanMu = ArticleType.query.all()
        return render_template('back/add-article.html', lanMu=lanMu)
    if request.method == 'POST':
        a = Article()
        Article().saveDB(a)
        return redirect(url_for('back.article'))
Exemple #2
0
def article_add():
    if request.method == 'GET':
        userid = session['user.id']
        types = ArticleType.query.filter(ArticleType.user_id == userid).all()
        return render_template('back/article_detail.html', types=types)
    if request.method == 'POST':
        title = request.form.get('title')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        userid = session['user.id']

        if title and desc and category and content:
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type_id = category
            art.user_id = userid

            art.save()

            return redirect(url_for('back.article_list'))

        else:
            error = '请填写完整的文章信息!'
            userid = session['user.id']
            types = ArticleType.query.filter(ArticleType.user_id == userid).all()
            return render_template('back/article_detail.html', types=types, error=error)
Exemple #3
0
def add_article():
    date = datetime.date.today()
    user_id = session['user_id']
    username = User.query.filter(User.user_id == user_id).first().username
    if request.method == 'GET':
        cates = Category.query.all()
        return render_template('back/add_article.html',
                               cates=cates,
                               username=username,
                               date=date)
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        # cat_name = request.form.get('category')
        tags = request.form.get('tags')
        category = request.form.get('category')
        # print(category)
        if title and content and category:
            user_id = session['user_id']
            username = User.query.filter(
                User.user_id == user_id).first().username
            article = Article()
            article.art_title = title
            article.content = content
            article.author = username
            article.tag = tags
            article.art_category = category
            article.save()
            return redirect(url_for('back.article'))
        return render_template('back/add_article.html',
                               username=username,
                               date=date)
Exemple #4
0
def articles_list_add():
    if request.method == 'GET':
        types = ArticleType.query.all()
        return render_template('back/articles_list_add.html', types=types)
    elif request.method == 'POST':
        title = request.form.get('title')
        desc = request.form.get('desc')
        content = request.form.get('content')
        type = request.form.get('category')
        us = session['user_id']
        if title and desc and content and type:
            # 保存
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = type
            art.us = us
            art.save()
            return redirect(url_for('back.articles_list'))
        else:
            error = '请填写完整的文章信息'
            types = ArticleType.query.all()
            return render_template('back/articles_list_add.html',
                                   error=error,
                                   types=types)
Exemple #5
0
def article_add():
    if request.method == 'GET':
        types = ArticleType.query.all()
        return render_template('back/article_add.html', types=types)
    if request.method == 'POST':
        # 获取数据
        title = request.form.get('name')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('my-editormd-html-code')
        content2 = request.form.get('my-editormd-markdown-doc')
        print(content)
        print(content2)

        if not all([title, desc, category, content]):
            error = '请填写完整信息!'
            return render_template('back/article_add.html', error=error)
        # 保存到数据库
        art = Article()
        art.title = title
        art.desc = desc
        art.type = category
        art.content = content
        art.save()
        return redirect(url_for('back.article_page', page=1))
Exemple #6
0
def update_article(id):
    if request.method == 'GET':
        u = Article.query.filter_by(id=id).first()
        lanMu = ArticleType.query.all()
        return render_template('back/update-article.html', u=u, lanMu=lanMu)

    if request.method == 'POST':
        Article().updateDB(id)
        return redirect(url_for('back.article'))
Exemple #7
0
def article_add():
    if request.method == 'GET':
        types = ArticleType.query.all()
        return render_template('back/article_detail.html', types=types)
    if request.method == 'POST':
        title = request.form.get('name')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        print(title, desc, category, content)
        if title and desc and category and content:
            article = Article.query.filter(Article.title == title).first()
            if article:
                error = '文章标题已存在'
                return redirect(url_for('back.article_add', error=error))
            else:
                art = Article()
                art.title = title
                art.desc = desc
                art.type = category
                art.content = content
                db.session.add(art)
                db.session.commit()
                return redirect(url_for('back.article_list'))

        else:
            error = '请填写完整文章信息'
            return render_template('back/article_detail.html', error=error)
Exemple #8
0
def article_add():
    if request.method == 'GET':
        types = Article_type.query.all()
        return render_template('back/article_detail.html', types=types)
    if request.method == 'POST':
        # 获取文章的标题
        title = request.form.get('name')
        # 获取文章的描述
        desc = request.form.get('desc')
        # 获取文章的分类
        category = request.form.get('category')
        # 获取文章的内容
        content = request.form.get('content')
        # 判断信息是否输入完整
        if title and desc and category and content:
            # 添加信息,并将信息提交给数据库
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = category
            db.session.add(art)
            db.session.commit()
            return redirect(url_for('back.article_list'))
        else:
            error = '请填写完整的文章信息'
            return render_template('back/article_detail.html', error=error)
Exemple #9
0
    def new_post_action(self,
                        author_id,
                        category_id,
                        all_tags_for_new_post,
                        title,
                        raw_slug,
                        body_id,
                        weight=0):
        """
        添加博文
        :param author_id: int,
        :param category_id: int,
        :param all_tags_for_new_post: list
        :param title: str,
        :param raw_slug: str,
        :param body_id: int
        :param weight:
        :return: post对象
        """
        new_identifier = self.gen_post_identifier()
        processed_slug = self.make_up_slug(raw_slug)
        try:
            assert not self.has_duplicate_slug(processed_slug)
        except AssertionError:
            processed_slug = self.resolve_conflict_slug(processed_slug)
        post = Article(title=title,
                       slug=processed_slug,
                       identifier=new_identifier,
                       author_id=author_id,
                       body_id=body_id,
                       view_counts=setting.INITIAL_VIEW_COUNTS,
                       weight=weight,
                       category_id=category_id)
        need_add_tags = assert_new_tag_in_tags(all_tags_for_new_post)
        # 正常函数不应该走到这里,因为前面已经添加了用户自主添加的,此处主要是刚开始写的代码不完善
        if need_add_tags:
            tag_poster.new_multi_tags(need_add_tags)
        for tag_name in all_tags_for_new_post:
            tag_obj = Tag.query.filter_by(tag_name=tag_name).one()
            post.tags.append(tag_obj)

        db.session.add(post)
        db.session.commit()
        # post_id = post.post_id
        return post
Exemple #10
0
def add_article():
    if request.method == 'GET':
        # 显示所有栏目分类到后台页面
        types = Atc_type.query.filter().all()
        return render_template('back/add-article.html', types=types)

    if request.method == 'POST':
        atc = Article()
        # 获取前端页面填写的数据
        atc.title = request.form.get('title')
        atc.desc = request.form.get('describe')
        atc.content = request.form.get('content')
        atc.type = int(request.form.get('category'))
        atc.uid = session.get('user_id')  # 从session中获取正在登陆的用户id
        # 存入数据库时,判断数据合法性
        res_title = Article.query.filter(Article.title == atc.title).first()
        if atc.title == None or res_title:
            error = '标题为空或已存在!'
            return render_template('back/add-article.html', title_err=error)
        if not atc.content:
            error = '内容不能为空!'
            return render_template('back/add-article.html', content_err=error)
        atc.save_update()
        return redirect(url_for('first.article'))
Exemple #11
0
def add_article():
    if request.method == 'GET':
        return render_template('back/add-article.html')
    if request.method == 'POST':
        #获取数据
        title = request.form.get('title')
        content = request.form.get('content')
        tags = request.form.get('tags')
        category = request.form.get('category')
        create_time = request.form.get('create_time')
        #保存数据
        art = Article()
        art.title = title
        art.content = content
        art.category = category
        art.tags = tags
        art.create_time = create_time
        db.session.add(art)
        db.session.commit()
        return redirect(url_for('back.article'))
Exemple #12
0
def add_article():
    if request.method == 'GET':
        types = ArticleType.query.order_by(ArticleType.id).all()
        return render_template('back/add-article.html', types=types)
    if request.method == 'POST':
        title = request.form.get('title')
        desc = request.form.get('describe')
        content = request.form.get('content')
        type = request.form.get('category')
        art = Article()
        art.title = title
        art.desc = desc
        art.content = content
        art.type = type
        db.session.add(art)
        db.session.commit()
        return redirect(url_for('back.article'))
Exemple #13
0
def update_article(id):
    if request.method == 'GET':
        articles = Article.query.get(id)
        types = ArticleType.query.order_by(ArticleType.id).all()
        return render_template('back/update-article.html',
                               articles=articles,
                               types=types)
    if request.method == 'POST':

        Article.id = request.view_args.get('id')
        art = Article()
        if art.id == request.view_args.get('id'):
            del_article(id)
        art.id = id
        art.title = request.form['title']
        art.desc = request.form.get('describe')
        art.content = request.form.get('content')
        art.type = request.form.get('category')
        db.session.add(art)
        db.session.commit()
        return redirect(url_for('back.article'))
Exemple #14
0
def add_article():
    if request.method == 'GET':
        return render_template('back/add-article.html')
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        desc = request.form.get('describe')
        type = request.form.get('category')
        article = Article()
        article.title = title
        article.content = content
        article.desc = desc
        article.type = type
        db.session.add(article)
        db.session.commit()
        return redirect('/article/')
    else:
        return render_template('back/login.html')
Exemple #15
0
def article_add():
    if request.method == 'GET':
        types = ArticleType.query.all()
        return render_template('/back/article_detail.html', types=types)
    if request.method == 'POST':
        title = request.form.get('name')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        user_id = session['user_id']
        if title and desc and category and content:
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = category
            art.usertype = user_id
            print(art)
            db.session.add(art)
            db.session.commit()
            return redirect(url_for('back.article_list'))
        else:
            error = '请填写完整的文章信息'
            return render_template('/back/article_detail.html', error=error)
Exemple #16
0
def article_add():
    if request.method == 'GET':
        arts = ArticleType.query.all()
        return render_template('back/article_detail.html', arts=arts)
    if request.method == 'POST':
        title = request.form.get('name')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        if title and desc and category and content:
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = category
            db.session.add(art)
            db.session.commit()
            return redirect(url_for('first.a_list'))
        else:
            error = '请填充完整的信息'
            return render_template('back/article_detail.html', error=error)
Exemple #17
0
def add_artilce():
    if request.method == 'GET':
        types = ArticleType.query.all()
        return render_template('back/add-article.html', types=types)
    if request.method == 'POST':
        print('sdfsdfs')
        title = request.form.get('title')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        if title and desc and category and content:
            # 保存数据
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = category
            db.session.add(art)
            db.session.commit()
            return redirect(url_for('back.article'))
        else:
            error = '请填写完整文章信息'
            return render_template('back/add-article.html', error=error)
Exemple #18
0
def art_add():
    if request.method == "GET":
        types = db.session.query(ArticleType).all()
        return render_template('/back/art_add.html', types=types)
    if request.method == "POST":
        artname = request.form.get('name')
        type = request.form.get('type')
        content = request.form.get('content')
        desc = request.form.get('desc')
        # print(artname,arttype,content,desc)
        #查出文章类型对象
        arttype = ArticleType.query.filter(ArticleType.type == type).first()

        art = Article()
        art.title = artname
        art.desc = desc
        art.content = content
        # 反向引用文章类型对象
        art.tp = arttype

        db.session.add(art)
        db.session.commit()
        return redirect(url_for('back.art_list'))
Exemple #19
0
def article_change(id):
    if request.method == 'GET':
        types = ArticleType.query.all()
        article = Article.query.get(id)
        return render_template('back/article_change.html', article=article, types=types)
    if request.method == 'POST':
        title = request.form.get('name')
        desc = request.form.get('desc')
        category = request.form.get('category')
        content = request.form.get('content')
        if title and desc and category and content:
            # 保存
            art = Article()
            art.title = title
            art.desc = desc
            art.content = content
            art.type = category
            db.session.commit()
            return redirect(url_for('back.article_list'))
        else:
            article = Article.query.get(id)
            types = ArticleType.query.all()
            error = '请修改文章信息'
            return render_template('back/article_change.html', error=error, article=article, types=types)
Exemple #20
0
def add_article():
    # db.create_all()
    username = session.get("username")
    if request.method == "GET":
        category_list = Category.query.filter().order_by(Category.id).all()

        return render_template('back/add_article.html',
                               title="add_article",
                               category_list=category_list,
                               username=username)
    if request.method == "POST":
        if request.files.get("picture"):
            picture = request.files.get("picture")
            new_filename = str(int(time.time() * 1e10))[7::] + picture.filename
            picture_path = os.path.join('static/image/', new_filename)
            # print(picture_path)
            picture.save(picture_path)
            # print(type(picture_path))
            article = Article()
            article.title = request.form.get('title')
            article.describe = request.form.get('describe')
            article.content = request.form.get('content')
            article.keywords = request.form.get('keywords')
            article.category_id = request.form.get('category')

            article.img = '/' + picture_path
            db.session.add(article)
            db.session.commit()
            return redirect(url_for('back.Ajax_article'))
            # return redirect('/back/article/')
            # return render_template('back/article.html')
        else:
            article = Article()
            article.title = request.form.get('title')
            article.describe = request.form.get('describe')
            article.content = request.form.get('content')
            article.keywords = request.form.get('keywords')
            article.category_id = request.form.get('category')

            db.session.add(article)
            db.session.commit()
            return redirect(url_for('back.Ajax_article'))
Exemple #21
0
def add_article():
    if request.method == 'GET':
        db_user = User.query.get(session['id'])
        request.username = db_user.username
        request.id = session['id']
        request.password = db_user.password
        db_category = Category.query.filter(Category.user_id == session['id']).all()
        return render_template('back/add-article.html', db_category=db_category)

    if request.method == 'POST':
        article = Article()
        article.article_content = request.form.get('content')
        if article.article_content:
            article.article_title = request.form.get('title')
            article.article_keywords = request.form.get('keywords')
            article.article_description = request.form.get('describe')
            article.category_id = request.form.get('category')
            article.article_image = request.form.get('titlepic')
            article.article_label = request.form.get('tags')
            article.article_status = eval(request.form.get('visibility'))
            article.user_id = session['id']
            article.save_update()
            return redirect(url_for('back.article'))
        error = '文章内容不能为空'
        db_category = Category.query.filter(Category.user_id == session['id']).all()
        return render_template('back/add-article.html',
                               db_category=db_category,
                               error=error)