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

    form = PasswordForm()

    if form.validate_on_submit():
        if user.password_validate(form.data['password_old']):
            user.password = form.data['password_new']

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

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

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

    else:
        pass  #!!!

    return render_template('rp/profiles_admin/change_password.html', form=form)
Esempio n. 2
0
def settings():
    """"""
    content = {
        'site': get_current_request_site_info(),
    }

    return render_template('rp/site_admin/settings.html', content=content)
Esempio n. 3
0
def import_wordpress_xml():
    """导入 wordpress xml 文件"""
    site = get_current_request_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. 4
0
def term_list(type):
    """"""
    if type not in ['category', 'tag']:
        return  #!!!

    site = get_current_request_site()

    terms = Term.query.filter_by(site=site, type=type).order_by(desc('name')).all()
    return render_template('rp/site_admin/term_list.html', terms=terms)
Esempio n. 5
0
def post_list(type):
    """"""
    if not is_valid_post_type(type):
        return  #!!!

    site = get_current_request_site()

    posts = Post.query.filter_by(site=site, type=type).order_by(desc('publish_date')).all()

    return render_template("rp/site_admin/post_list.html", posts=posts, post_type=type)
Esempio n. 6
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('rp/profiles_admin/index.html', form=form)
Esempio n. 7
0
def edit(site_id):
    """"""
    site = Site.query.filter_by(id=site_id).first()
    if site is None:
        return

    form = SiteForm(obj=site)

    if form.validate_on_submit():
        form.populate_obj(site)
        db.session.add(site)
        db.session.commit()
    else:
        pass  #!!!

    return render_template('rp/mulit_site_admin/edit.html', site_id=site_id, form=form)
Esempio n. 8
0
def _render_post(post):
    """render one post"""
    content = {
        'post': _make_post_info(post),
    }

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

    return render_template('post.html', content=content)
Esempio n. 9
0
def setting_edit(key):
    """"""
    site = get_current_request_site()
    site_setting = SiteSetting.query.filter_by(site=site, key=key).first()
    if site_setting is None:
        site_setting = SiteSetting(site, key, None)

    form = SettingsForm(obj=site_setting)

    if form.validate_on_submit():
        form.populate_obj(site_setting)

        db.session.add(site_setting)
        db.session.commit()

        flash("setting updated", "success")
    else:
        flash('setting edit error')

    return render_template("rp/site_admin/setting_edit.html", form=form, site_setting=site_setting)
Esempio n. 10
0
def term_edit(name):
    """"""
    site = get_current_request_site()

    term = Term.query.filter_by(site=site, name=name).first_or_404()  #!!!
    form = TermEditFrom(obj=term)

    if form.validate_on_submit():
        form.populate_obj(term)

        db.session.add(term)
        db.session.commit()

        flash("term updated", "success")
        #return redirect(url_for('.blog'))
    else:
        flash('term edit error')
        pass

    return render_template("rp/site_admin/term_edit.html", form=form, term=term)
Esempio n. 11
0
def post_edit(uuid):
    """"""
    post = Post.query.filter_by(uuid=str(uuid)).first_or_404()  #!!!
    form = PostEditForm(obj=post)

    if form.validate_on_submit():
        form.populate_obj(post)
        post.content = re.sub(r'\r', '\n', re.sub(r'\r\n', '\n', form.data['content']))

        db.session.add(post)
        db.session.commit()

        flash("post updated", "success")
        #return redirect(url_for('.blog'))
    else:
        flash('post edit error')
        pass

    post_publish_fsm = PublishFSM(init_state=post.publish_state)
    return render_template("rp/site_admin/post_edit.html", form=form, post=post, publish_triggers=post_publish_fsm.possible_triggers)
Esempio n. 12
0
def _render_post_paginate(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(_make_post_info(post))
    paginate['posts'] = paginate_posts

    widgets = _sidebar()

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

    return render_template('post_paginate.html', content=content)
Esempio n. 13
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 login_user(form.username.data, form.password.data):
            flash('login fail.')
            abort(401)
            #return redirect(url_for('.index'))

        flash('Logged in successfully.')

        next = 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 or url_for('site_admin.index'))

    return render_template('/common/login.html', form=form)
Esempio n. 14
0
def index():
    """"""
    return render_template("rp/site_tools/index.html")
Esempio n. 15
0
 def page_not_found(e):
     return render_template('/common/404.html'), 404
Esempio n. 16
0
def index():
    """"""
    return render_template("rp/site_admin/index.html")
Esempio n. 17
0
def internal_server_error(e):
    """"""
    return render_template('/common/500.html'), 500
Esempio n. 18
0
def index():
    """mulit-site home page"""
    sites = Site.query.all()

    return render_template('rp/mulit_site_admin/index.html', sites=sites)