Example #1
0
def article_x(unique_domain, article_id):
    try:
        m_article = models.Article.query.filter_by(id=int(article_id)).first()
        try:
            m_article_comment_list = models.ArticleComment.query.filter_by(article_id=m_article.id).all()
            return render_template('default/page_article_view.html',
                                   strs=strings(),
                                   article=m_article,
                                   tag_list=json.loads(m_article.tag_list),
                                   comment_list=m_article_comment_list)
        except:
            return render_template('default/page_article_view.html',
                                   strs=strings(),
                                   article=m_article,
                                   tag_list=json.loads(m_article.tag_list))
    except Exception, e:
        logger.debug("main.article_x - unique_domain=%s, article_id=%s, err=%s" % (unique_domain, article_id, e))
        return render_template('default/page_article_view.html', strs=strings())
Example #2
0
def search():
    # print('main.search - 1')
    keywords = ('%s' % request.args.get('keywords', '')).strip()
    session['keywords'] = ('%s' % keywords)
    # print('main.search - keywords = %s' % keywords)
    if keywords is not None and '' != keywords:
        # print('main.search - 2')
        keywords = '%' + ('%s' % keywords).strip() + '%'
        # print('main.search - keywords = %s' % keywords)
        try:
            articleList = models.Article.query.filter(db.or_(
                models.Article.tag_list.like(keywords), models.Article.title.like(keywords))).all()
            return render_template('default/page_search_result.html',
                                   strs=strings(),
                                   keywords=session.get('keywords', ''), articleList=articleList)
        except Exception, e:
            logger.fatal("main.search - keywords=%s, err=%s" % (keywords, e))
Example #3
0
def article_comment(option):
    if values.UserOption.add == option or values.UserOption.quote == option:
        try:
            to_article_id = request.form.get('to_article_id', -1, type=int)
            m_article = models.Article.query.filter_by(id=to_article_id).first()
            try:
                sequence_of_article = models.ArticleComment.query.filter_by(
                    article_id=int(m_article.id)).order_by(
                    models.ArticleComment.sequence_of_article.desc()
                ).first().sequence_of_article + 1
            except:
                sequence_of_article = 1
            to_comment_id = request.form.get('to_comment_id', -1, type=int)
            editor_code = request.form.get('editor_code', values.EditorCode.UEditor)
            body_source = request.form.get('comment_body', '')
            body_default = request.form.get('comment_body', '')
            body_simple = request.form.get('comment_body', '')
            # logger.debug('main.article_comment: 2, to_comment_id=%s, body_source=%s' % (to_comment_id, body_source))
            if to_comment_id > 0:
                # logger.debug('main.article_comment: 3')
                to_comment = models.ArticleComment.query.filter_by(id=int(to_comment_id)).first()
                art_comment = models.ArticleComment(
                    article_id=m_article.id,
                    sequence_of_article=sequence_of_article,
                    to_comment_id=to_comment.id,
                    to_sequence_of_article=to_comment.sequence_of_article,
                    to_comment_body=to_comment.body_default,
                    from_user_id=ctl_current_user.user_id,
                    from_user_domain=ctl_current_user.unique_domain,
                    from_user_name=ctl_current_user.nikename,
                    to_user_id=to_comment.from_user_id,
                    to_user_domain=to_comment.from_user_domain,
                    to_user_name=to_comment.from_user_name,
                    editor_code=editor_code,
                    body_source=body_source,
                    body_default=body_default,
                    body_simple=body_simple
                )
                if values.UserOption.add == option:
                    art_comment.to_comment_body = ''
                db.session.add(art_comment)
                db.session.commit()
                logger.debug('main.article_comment: 4')
            else:
                # logger.debug('main.article_comment: 5, m_article.id = %s' % m_article.id)
                art_comment = models.ArticleComment(
                    article_id=m_article.id,
                    sequence_of_article=sequence_of_article,
                    from_user_id=ctl_current_user.user_id,
                    from_user_domain=ctl_current_user.unique_domain,
                    from_user_name=ctl_current_user.nikename,
                    to_user_id=m_article.author_id,
                    to_user_domain=m_article.author_domain,
                    to_user_name=m_article.author_name,
                    editor_code=editor_code,
                    body_source=body_source,
                    body_default=body_default,
                    body_simple=body_simple
                )
                db.session.add(art_comment)
                db.session.commit()
                logger.debug('main.article_comment: 6')
            return render_template('default/article_comment_item.html', strs=strings(),
                                   article=m_article, comment=art_comment)
        except Exception, e:
            db.session.rollback()
            logger.debug('main.view: article_comment: add comment fail. err = %s' % e)
            return e
Example #4
0
def admin_nav():
    # global nav
    return render_template('default/admin_globalnav.html', strs=strings())
Example #5
0
def admin_tag():
    return render_template('default/admin_tags.html', strs=strings())
Example #6
0
def admin_doc():
    return render_template('default/admin_document.html', strs=strings())
Example #7
0
def index():
    # nav_list = ('Android', 'Linux', 'Web', 'Cloud Computing')
    return render_template('index.html', strs=strings())
Example #8
0
def admin_article():
    action = request.args.get('action', '')
    option = request.args.get('option', '')
    if action is None or '' == action:
        page = request.args.get('page', 1, type=int)
        pagination = models.Article.query.filter_by(
            author_id=ctl_current_user.user_id).order_by(
            models.Article.update_time.desc()).paginate(page, per_page=values.page_size, error_out=False)
        return render_template('default/admin_article.html',
                               strs=strings(),
                               articleList=pagination.items, pagination=pagination)
    elif 'new' == action:
        edit_article_form = ArticleEditForm()
        print(1)
        if edit_article_form.validate_on_submit():
            print(2)
            try:
                first_img_src = ''
                if values.EditorCode.UEditor == edit_article_form.editor_code.data:
                    soup = BeautifulSoup(edit_article_form.body.data)
                    first_img = soup.find(name='img')
                    if first_img:
                        first_img_src = first_img.get('src', '')
                    img_list = soup.find_all(name='img')
                    for img in img_list:
                        noscript_tag = soup.new_tag(name='noscript')
                        noscript_tag.append(soup.new_tag(name='img',
                                                         src=img.get('src', ''),
                                                         alt=img.get('alt', ''),
                                                         title=img.get('title', ''),
                                                         width=img.get('width', 'auto'),
                                                         height=img.get('height', 'auto'),
                                                         style=img.get('style', '')
                                                         ))
                        img.insert_after(noscript_tag)
                        img['class'] = 'lazy'
                        img['data-original'] = img.get('src', '')
                        if '' == img.get('width', ''):
                            img['width'] = 'auto'
                        if '' == img.get('height', ''):
                            img['height'] = 'auto'
                        if '' != img.get('src', ''):
                            del img['src']
                    body_default = '<%s>' % str(soup.html.body).lstrip('<body>').rstrip('</body>')
                new_article = models.Article(
                    title=edit_article_form.title.data,
                    author_id=ctl_current_user.user_id,
                    author_domain=ctl_current_user.unique_domain,
                    author_name=ctl_current_user.nikename,
                    img=first_img_src,
                    tag_list=edit_article_form.tag_list.data,
                    editor_code=edit_article_form.editor_code.data,
                    body_source=edit_article_form.body.data,
                    body_default=body_default,
                    body_simple=soup.get_text(),
                    access_level=edit_article_form.access_level.data,
                    access_passwd=edit_article_form.access_pw.data
                )
                db.session.add(new_article)
                db.session.commit()
                # print('main.admin_article - new_article.id=%s' % new_article.id)
                # update the attachment file info
                print(3)
                un_released_file_list = models.StorageFileKey.query.filter_by(
                    owner_id=new_article.author_id, for_what_status='draft')
                for file_key in un_released_file_list:
                    if file_key.download_url in new_article.body_source:
                        file_key.for_what = 'article'
                        file_key.for_what_id = new_article.id
                        file_key.for_what_status = 'released'
                        db.session.add(file_key)
                db.session.commit()
                # print('main.admin_article - file_key.id')
                try:
                    # storage and update globaltag.json
                    ctl_tags = controller.CtlTags(current_user_id=new_article.author_id, db=db, models=models)
                    add_result, has_new_tag = ctl_tags.add_tag_list(tag_list=new_article.tag_list)
                    if has_new_tag:
                        ctl_tags.update_tag_file()
                    # print('main.admin_article - ctl_tags finish')
                except Exception, e:
                    logger.debug('main.admin_article - update globaltag.json fail. err=%s' % e)
                if values.UserOption.save_draft == option:
                    print('new ajax')
                    return jsonify(form_url=url_for('main.admin_article', action='update', articleId=new_article.id))
                return redirect(url_for('main.article_x',
                                        unique_domain=ctl_current_user.unique_domain,
                                        article_id=new_article.id))
            except Exception, e:
                db.session.rollback()
                logger.debug('main.admin_article - article: new article error. err=%s' % e)
Example #9
0
def ueditor():
    return render_template('default/moudle_ueditor.html', strs=strings())
Example #10
0
    keywords = ('%s' % request.args.get('keywords', '')).strip()
    session['keywords'] = ('%s' % keywords)
    # print('main.search - keywords = %s' % keywords)
    if keywords is not None and '' != keywords:
        # print('main.search - 2')
        keywords = '%' + ('%s' % keywords).strip() + '%'
        # print('main.search - keywords = %s' % keywords)
        try:
            articleList = models.Article.query.filter(db.or_(
                models.Article.tag_list.like(keywords), models.Article.title.like(keywords))).all()
            return render_template('default/page_search_result.html',
                                   strs=strings(),
                                   keywords=session.get('keywords', ''), articleList=articleList)
        except Exception, e:
            logger.fatal("main.search - keywords=%s, err=%s" % (keywords, e))
    return render_template('default/page_search_result.html', strs=strings())

@main.route('/tag/', methods=['GET', 'POST', 'OPTIONS'])
def tag_search():
    tag_name = ('%s' % request.args.get('tag_name', '')).strip()
    # print('main.search - keywords = %s' % keywords)
    if tag_name is not None and '' != tag_name:
        return redirect(url_for('main.search', keywords=tag_name))
    return redirect('#')

@main.route('/upload', methods=['GET', 'POST', 'OPTIONS'])
def upload():
    """UEditor文件上传接口
    config 配置文件
    result 返回结果
    """