コード例 #1
0
ファイル: index.py プロジェクト: qisanstudio/qsapp-riitc
from studio.core.engines import db
from riitc.blueprints import blueprint_www
from riitc.models import (SlideModel, ChannelModel, ChannelSummaryModel,
                          ArticleModel, ArticleContentModel)


class IndexView(views.MethodView):
    '''
        首页
    '''

    def get(self):
        return redirect(url_for('views.index_lang', language='cn'))


blueprint_www.add_url_rule('/', view_func=IndexView.as_view(b'index'),
                           endpoint='index', methods=['GET'])


class LangIndexView(views.MethodView):
    '''
        语言首页
    '''

    def get(self, language):
        channels = ChannelModel.query.all()
        if language == 'en':
            channels = filter(lambda x: re.match(r'[a-zA-Z\b]+', x.name),
                              channels)
        else:
            channels = filter(lambda x: not re.match(r'[a-zA-Z\b]+', x.name),
                              channels)
コード例 #2
0
ファイル: channel.py プロジェクト: qisanstudio/qsapp-riitc
        if cid in STAFF_MAPPING.keys():
            return redirect(url_for('views.staff', cid=cid))
        channel = ChannelModel.query.get(cid)
        query = ChannelModel.get_channel_query(self.language)
        pager = Pagination(bs_version=3, page=self.page,
                           total=channel.articles.count())

        return render_template('www/channel.html',
                               channels=query.all(),
                               channel=channel,
                               language=channel.language,
                               pager=pager)


blueprint_www.add_url_rule('/channel/<int:cid>/',
                           view_func=ChannelView.as_view(b'channel'),
                           endpoint='channel', methods=['GET'])


class LevelView(views.MethodView):
    '''
        师资队伍
    '''

    @property
    def page(self):
        try:
            return int(request.args.get('page', 1))
        except ValueError:
            return 1
コード例 #3
0
ファイル: account.py プロジェクト: qisanstudio/qsapp-riitc
    def post(self):
        form = LoginForm()
        if form.validate_on_submit():
            account = AccountModel.query.filter_by(email=form.email.data).first_or_404()
            if account.is_correct_password(form.password.data):
                login_user(account)
                return redirect(url_for("admin.index"))
            else:
                flash("密码不正确")
        else:
            flash_errors(form)

        return render_template("www/login.html", form=form)


blueprint_www.add_url_rule("/login", view_func=LoginView.as_view(b"login"), endpoint="login", methods=["GET", "POST"])


class LogoutView(views.MethodView):
    """
        用户退出
    """

    @login_required
    def get(self):
        logout_user()
        return redirect(url_for("views.index"))


blueprint_www.add_url_rule("/logout", view_func=LogoutView.as_view(b"logout"), endpoint="logout", methods=["GET"])
コード例 #4
0
ファイル: article.py プロジェクト: qisanstudio/qsapp-riitc
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from flask import views, render_template
from riitc.blueprints import blueprint_www


from riitc.models import ArticleModel


class ArticleView(views.MethodView):
    '''
        文章页
    '''

    def get(self, aid):
        article = ArticleModel.query.get(aid)
        return render_template('www/article.html',
                               article=article,
                               language=article.language)


blueprint_www.add_url_rule('/article/<int:aid>/',
                           view_func=ArticleView.as_view(b'article'),
                           endpoint='article', methods=['GET'])