Created
April 26, 2016 09:26
-
-
Save mnrozhkov/3658bbea6b8f6cf93d5fafb0713c0aba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
from __future__ import unicode_literals | |
from sqlalchemy import ( | |
Column, Integer, String, ForeignKey, Text, Boolean, DateTime, Date, | |
Table, create_engine, MetaData, desc, select, and_, func) | |
from sqlalchemy.engine import reflection | |
from sqlalchemy.ext.declarative import declared_attr | |
from sqlalchemy.orm import relationship | |
from sqlalchemy.sql import table, literal_column, text, column | |
from sqlalchemy.sql.elements import ColumnClause | |
from sqlalchemy_utils import EncryptedType | |
from flask.ext.appbuilder.security.sqla.models import User | |
from flask_appbuilder.security.views import UserDBModelView | |
from flask_appbuilder.security.sqla.manager import SecurityManager | |
from flask_babelpkg import lazy_gettext | |
class MyUser(User): | |
""" | |
Model of the customized User | |
""" | |
__tablename__ = 'ab_user' | |
app_access = Column(String(256), nullable=True) | |
class MyUserDBModelView(UserDBModelView): | |
""" | |
Custom view that add DB specifics of MyUser view | |
""" | |
show_fieldsets = [ | |
(lazy_gettext('User info'), | |
{'fields': ['username', 'active', 'roles', 'login_count', 'app_access']}), | |
(lazy_gettext('Personal Info'), | |
{'fields': ['first_name', 'last_name', 'email'], 'expanded': True}), | |
(lazy_gettext('Audit Info'), | |
{'fields': ['last_login', 'fail_login_count', 'created_on', | |
'created_by', 'changed_on', 'changed_by'], 'expanded': False}), | |
] | |
user_show_fieldsets = [ | |
(lazy_gettext('User info'), | |
{'fields': ['username', 'active', 'roles', 'login_count', 'app_access']}), | |
(lazy_gettext('Personal Info'), | |
{'fields': ['first_name', 'last_name', 'email'], 'expanded': True}), | |
] | |
add_columns = ['first_name', 'last_name', 'username', 'active', 'email', 'roles', 'app_access', 'password', 'conf_password'] | |
list_columns = ['first_name', 'last_name', 'username', 'email', 'active', 'roles'] | |
edit_columns = ['first_name', 'last_name', 'username', 'active', 'email', 'roles', 'app_access'] | |
class MySecurityManager(SecurityManager): | |
""" | |
Custom security manager for my App | |
""" | |
user_model = MyUser | |
userdbmodelview = MyUserDBModelView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment