Download pool/shard001/Python/0009047_role.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009047_role.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/Python/0009047_role.py
-
curl -L -o 0009047_role.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009047_role.py
1.15 kB
| from . import db | |
| from sqlalchemy import Column, Integer, Unicode | |
| DEFAULT_ROLES = { | |
| 'system': 'system', | |
| 'admin': 'admin', | |
| 'staff': 'staff', | |
| 'user': 'user', | |
| } | |
| class Role(db.Model): | |
| __tablename__ = 'roles' | |
| id = Column(Integer, primary_key=True) | |
| name = Column(Unicode(length=50), unique=True) | |
| accounts = db.relationship('User', backref='role', lazy='dynamic') | |
| def get_role_by_name(name): | |
| return Role.query.filter_by(name=DEFAULT_ROLES.get(name)).first() | |
| def admin(): | |
| return Role.get_role_by_name('admin') | |
| def user(): | |
| return Role.get_role_by_name('user') | |
| def staff(): | |
| return Role.get_role_by_name('staff') | |
| def system(): | |
| return Role.get_role_by_name('system') | |
| def is_admin(self): | |
| return self == Role.admin() | |
| def is_user(self): | |
| return self == Role.user() | |
| def is_staff(self): | |
| return self == Role.staff() | |
| def is_system(self): | |
| return self == Role.system() | |