Exemplo n.º 1
0
import json as JSON
from slugify import slugify
from functools import reduce
from pprint import pprint
from application import mail_handler
from application import admin
from flask_admin.contrib.sqla import ModelView
from flask_admin import expose


class NewUserView(ModelView):
    column_exclude_list = ['password_hash']
    create_template = 'test.html'


admin.add_view(NewUserView(User, db.session))


@application.route('/api/universities', methods=["GET"])
def get_universities():
    return JSON.dumps(
        [univ.get_object() for univ in University.get_universities()])


@application.route('/api/programs_by_university/<int:univ_id>')
def get_programs(univ_id):
    programs = Program.get_programs_by_univ_id(univ_id)
    return JSON.dumps(
        sorted([program.get_meta_object() for program in programs],
               key=lambda x: x['program_name']))
Exemplo n.º 2
0
from application import app, admin, db
from application.models import Count, Router, Campus, RouterAlias
from flask_admin.contrib.geoa import ModelView

admin.add_view(ModelView(Count, db.session))
admin.add_view(ModelView(Router, db.session))
admin.add_view(ModelView(Campus, db.session))
admin.add_view(ModelView(RouterAlias, db.session))
Exemplo n.º 3
0
from flask_admin.contrib.sqla import ModelView
from application import db, admin
from application.models import Surname

SurnameAdmin = admin.add_view(ModelView(Surname, db.session))
Exemplo n.º 4
0
"""
Admin views.
"""

from flask_admin.contrib.sqla import ModelView
from flask_login import current_user

from application import admin, models, db


class SecureModelView(ModelView):
    """
    Secure Model View.
    Make view accessible only for admin.
    """
    # exclude password hash from admin view
    column_exclude_list = [
        'password_hash',
    ]

    def is_accessible(self):
        return current_user.is_authenticated and current_user.is_admin


admin.add_view(SecureModelView(models.Stop, db.session))
admin.add_view(SecureModelView(models.User, db.session))
Exemplo n.º 5
0
from flask import render_template, redirect, url_for, request
from application import app, admin
from flask_admin.contrib.peewee import ModelView
from models import User, Organisation, Role
from flask_login import login_required, current_user


@app.route('/pyinfo')
@login_required
def pyinfo():
    return render_template('pyinfo.html', **info)


class AppModelView(ModelView):
    def is_accessible(self):
        if not current_user.is_active or not current_user.is_authenticated:
            return False

        if current_user.has_role(Role.SUPERUSER):
            return True

        return False

    def inaccessible_callback(self, name, **kwargs):
        # redirect to login page if user doesn't have access
        return redirect(url_for('login', next=request.url))


admin.add_view(AppModelView(User))
admin.add_view(AppModelView(Organisation))
Exemplo n.º 6
0
    name = db.Column(db.String(30), unique=True, nullable=False)
    colour = db.Column(db.String(30), default="black")


class SubscribedUser(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20))
    email = db.Column(db.String(120), unique=True, nullable=False)


class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey("post.id"))
    name = db.Column(db.String(20))
    content = db.Column(db.Text, nullable=False)
    timestamp = db.Column(db.DateTime,
                          index=True,
                          default=datetime.now(get_localzone()))


class MyModelView(ModelView):
    def is_accessible(self):
        return current_user.is_authenticated and current_user.role == "Admin"


admin.add_view(MyModelView(User, db.session))
admin.add_view(MyModelView(Post, db.session))
admin.add_view(MyModelView(Tag, db.session))
admin.add_view(MyModelView(Like, db.session))
admin.add_view(MyModelView(Comment, db.session))
admin.add_view(MyModelView(SubscribedUser, db.session))
Exemplo n.º 7
0
from application import db, admin
from flask_admin.contrib.sqla import ModelView


class Device(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    organization_id = db.Column(db.Integer, db.ForeignKey('organization.id'))

    def __repr__(self):
        return '<Id: %r, Name: %s>' % (self.id, self.name)


admin.add_view(ModelView(Device, db.session))


class Organization(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    public_id = db.Column(db.String(50), unique=True)
    name = db.Column(db.String(50))
    device = db.relationship('Device', backref='organization', lazy='dynamic')
    password = db.Column(db.String(80))
    admin = db.Column(db.Boolean)

    def __repr__(self):
        return '<Id: %r, Name: %s>' % (self.id, self.name)


admin.add_view(ModelView(Organization, db.session))
Exemplo n.º 8
0
from application import application, db, admin
from application.models import User, Administrator, Books
from application.views.admin import UserModelView, AdminModelView, BooksModelView


@application.route('/')
@application.route('/index')
def root():
    return application.send_static_file('index.html')

admin.add_view(UserModelView(User, db.session))
admin.add_view(AdminModelView(Administrator, db.session))
admin.add_view(BooksModelView(Books, db.session))
Exemplo n.º 9
0
        }

    def encode_token(self, user_id, token_type):
        
        if token_type == "access":
            seconds = current_app.config.get('ACCESS_TOKEN_EXPIRATION')
        else:
            seconds = current_app.config.get('REFRESH_TOKEN_EXPIRATION')
        
        payload = {
            'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds),
            'iat': datetime.datetime.utcnow(),
            'sub': user_id
        }
        return jwt.encode(
            payload,
            current_app.config.get('SECRET_KEY'),
            algorithm='HS256'
        )

    @staticmethod
    def decode_token(token):
        payload = jwt.decode(token, current_app.config.get("SECRET_KEY"))
        return payload["sub"]

if os.getenv("FLASK_ENV") == "development":
    from application import admin
    from application.api.users.admin import UsersAdminView

    admin.add_view(UsersAdminView(User, db.session))
Exemplo n.º 10
0
# 根据模型自动生成页面
from .models import Goods
from flask_admin.contrib.sqla import ModelView
from application import admin, db


class GoodsAdminModel(ModelView):
    # 列表页显示字段列表
    column_list = ["id", "name", "price"]
    # 列表页可以直接编辑的字段列表
    column_editable_list = ["price"]
    # 是否允许查看详情
    can_view_details = True
    # 列表页显示直接可以搜索数据的字典
    column_searchable_list = ['name', 'price']
    # 过滤器
    column_filters = ['name']
    # 单页显示数据量
    page_size = 10


admin.add_view(GoodsAdminModel(Goods, db.session, name="商品", category="种植园"))
Exemplo n.º 11
0
from .models import User
from flask_admin.contrib.sqla import ModelView


class UserAdminModel(ModelView):
    # 列表页显示字段列表
    column_list = ["id", "name", "nickname"]
    # 列表页显示排除字段列表
    # column_exclude_list = ["is_delete"]
    # 列表页可以直接编辑的字段列表
    column_editable_list = ["nickname"]
    # 是否允许查看详情
    can_view_details = True
    # 列表页显示直接可以搜索数据的字典
    column_searchable_list = ['nickname', 'name', 'email']
    # 过滤器
    column_filters = ['sex']
    # 单页显示数据量
    page_size = 10


# admin.add_view(UserAdminModel(User,db.session,name="用户")) # 把当前页面作为顶级导航进行显示
admin.add_view(
    UserAdminModel(User, db.session, name="用户",
                   category="用户管理"))  # 把当前页面添加到顶级导航下,category来设置,如果导航不存在,则自动创建

# 添加子导航还有种方式: 添加超链接作为导航
from flask_admin.menu import MenuLink
admin.add_link(
    MenuLink(name='老男孩', url='http://www.oldboyedu.com',
             category='用户管理'))  # 把超链接作为子导航加载到顶级导航中
Exemplo n.º 12
0
    def __str__(self):
        return self.email


# define UserView
class UserView(ModelView):

    can_view_details = True
    column_exclude_list = [
        'password',
    ]
    column_searchable_list = [
        'email',
    ]


admin.add_view(UserView(User, db.session))


# define RoleView
class RoleView(ModelView):

    can_view_details = True
    column_searchable_list = [
        'name',
    ]


admin.add_view(RoleView(Role, db.session))
Exemplo n.º 13
0
#from application import app as app
#from application import db as db
#from application import admin as admin
from application import app, db, admin
#from flask import Blueprint, render_template, abort
#from jinja2 import TemplateNotFound
from flask_admin.contrib.sqla import ModelView
from application.models import Auth, Classe, Educ, Experiencia, Cert, Horario, Prestador, Subclasse, Sugestao, Suporte, User

admin.add_view(ModelView(Auth, db.session))
admin.add_view(ModelView(Classe, db.session))
admin.add_view(ModelView(Educ, db.session))
admin.add_view(ModelView(Experiencia, db.session))
admin.add_view(ModelView(Cert, db.session))
admin.add_view(ModelView(Horario, db.session))
admin.add_view(ModelView(Prestador, db.session))
admin.add_view(ModelView(Subclasse, db.session))
admin.add_view(ModelView(Sugestao, db.session))
admin.add_view(ModelView(Suporte, db.session))
admin.add_view(ModelView(User, db.session))
#@admin.route('/', defaults={'page': 'index'})
#@admin.route('/<page>')
#def show(page):
#    return render_template('index.html')
Exemplo n.º 14
0
            problem['sample_input'] = problem['sample_input'].replace('\r\n', '<br/>')
            problem['sample_output'] = problem['sample_output'].replace('\r\n', '<br/>')
            for item in problem:
                if type(problem[item]) != str: continue
                match = re.compile('<img\s*?src\s*?=\s*?\'?\"?(.*?)\'?\"?\s*?>', re.M | re.S)
                links = match.findall(problem[item])
                for link in links:
                    newUrl = urljoin("http://poj.org/", link)
                    problem[item] = problem[item].replace(link, newUrl)
            return self.render('admin/problem_form.html', problem=problem, contests=conts)
        except Exception, e:
            return self.render('exception.html', message=str(e))

    def is_accessible(self):
        if flask_login.current_user.get_id() is None:
            return False
        return ('manage problem' in flask_login.current_user.group.split('|'))
        



admin.add_view(MyUserModelView(models.User, db.session))
admin.add_view(MyProblemModelView(models.Problem, db.session, category='Problem'))
admin.add_view(MyNewsModelView(models.News, db.session))
admin.add_view(MyForumModelView(models.Forum, db.session))
admin.add_view(MyContestModelView(models.Contest, db.session))
admin.add_view(MySubmissionModelView(models.Submission, db.session))
admin.add_view(Add_HDOJ_Problem_View(name='Add HDOJ Problem', category='Problem'))
admin.add_view(Add_PKUOJ_Problem_View(name='Add PKU OJ Problem', category='Problem'))