Esempio n. 1
0
def import_wordpress_xml():
    """导入 wordpress xml 文件"""
    site = get_current_site()
    if site is None:
        return 'site binding error'

    if request.method != 'POST':
        return render_template('rp/site_tools/upload_wordpress_xml.html')

    file = request.files['file']
    if file is None or not allowed_file(file.filename):
        return 'upload file error!'

    filename = os.path.join(UPLOAD_FOLDER, secure_filename(file.filename))
    file.save(filename)

    response_msg = import_data_from_wordpress_xml(
        db_session=db.session,
        site=site,
        disable_convert_code_tag=False,
        filename=filename,
        is_cli_mode=False,
        is_skip_unknow_author=False
    )
    db.session.commit()

    return response_msg
Esempio n. 2
0
def change_password():
    """"""
    user = User.query.filter_by(id=current_user.id).first()
    if user is None:
        return  # TODO

    form = PasswordForm()

    if form.validate_on_submit():
        if user.check_password(form.data['password_old']):
            user.change_password(form.data['password_new'])

            db.session.add(user)
            db.session.commit()

            flash('password is changed!')
            return redirect(url_for('rpadmin_profile.edit'))

        else:
            flash("old password is NOT correct")

    else:
        pass

    return render_template('rpadmin/profile/change_password.html', form=form)
Esempio n. 3
0
def edit():
    """"""
    user = User.query.filter_by(id=current_user.id).first()
    if user is None:
        return
    form = ProfilesForm(obj=user)

    if form.validate_on_submit():
        form.populate_obj(user)
        db.session.add(user)
        db.session.commit()
    else:
        pass

    return render_template('rpadmin/profile/edit.html', form=form)
Esempio n. 4
0
def _render_one_post(post):
    """render one post"""
    content = {
        'post': _post_info(post),
    }

    comment_list = []
    comments = Comment.query.filter_by(post=post).order_by(
        desc('created_time')).all()
    for comment in comments:
        comment_list.append({
            'commenter_name': comment.commenter_name,
            'created_time': comment.created_time,
            'content': comment.content,
        })
    content['comments'] = comment_list

    return render_template('post.html', content=content)
Esempio n. 5
0
def _render_paginate_post_page(query, paginate):
    post_paginate = query.paginate(paginate['curr_num'], per_page=10)

    paginate['has_prev'] = post_paginate.has_prev
    paginate['has_next'] = post_paginate.has_next
    paginate['prev_num'] = post_paginate.prev_num
    paginate['next_num'] = post_paginate.next_num

    paginate_posts = []
    for post in post_paginate.items:
        paginate_posts.append(_post_info(post))
    paginate['posts'] = paginate_posts

    widgets = _sidebar()

    content = {
        'paginate': paginate,
        'widgets': widgets,
    }

    return render_template('post_paginate.html', content=content)
Esempio n. 6
0
def login():
    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    form = LoginForm()
    if form.validate_on_submit():
        # Login and validate the user.
        # user should be an instance of your `User` class
        if not user_login(form.username.data, form.password.data):
            flash('login fail.')
            abort(401)
            # return redirect(url_for('.index'))

        flash('Logged in successfully.')

        next_location = request.args.get('next')
        # next_is_valid should check if the user has valid
        # permission to access the `next` url
        # if not next_is_valid(next):
        #    return flaskabort(400)
        return redirect(next_location
                        or url_for('rpadmin_dashboard.dashboard'))

    return render_template('/common/login.html', form=form)
Esempio n. 7
0
def internal_server_error(e):
    return render_template('/common/500.html'), 500
Esempio n. 8
0
def page_not_found(e):
    return render_template('/common/404.html'), 404
Esempio n. 9
0
def permission_not_match(e):
    return render_template('/common/403.html'), 403
Esempio n. 10
0
def index():
    return render_template("rp/site_tools/list.html")