class OAuthModel(db.Model): """ DB model class for storing OAuth configuration into postgresql. """ id = db.Column(db.Integer, primary_key=True) # Twitter twitter_app_id = db.Column(db.String(255), nullable=False, default='') twitter_app_secret = db.Column(db.String(255), nullable=False, default='') # GitHub github_app_id = db.Column(db.String(255), nullable=False, default='') github_app_secret = db.Column(db.String(255), nullable=False, default='') # Google google_app_id = db.Column(db.String(255), nullable=False, default='') google_app_secret = db.Column(db.String(255), nullable=False, default='') @staticmethod def first(): try: return OAuthModel.query.filter_by(id=FIRST_DOCUMENT_ID).one() except: x = OAuthModel() db.session.add(x) db.session.commit() return OAuthModel.first() @staticmethod def get_settings(): that = OAuthModel.first() return { 'twitter': (that.twitter_app_id, that.twitter_app_secret), 'github': (that.github_app_id, that.github_app_secret), 'google': (that.google_app_id, that.google_app_secret) }
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) # User authentication information username = db.Column(db.String(50), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False, server_default='') is_enabled = db.Column(db.Boolean(), nullable=False, default=True) apikey = db.Column(db.String(100), nullable=False, index=True, server_default='') # Relationships roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic')) def is_active(self): return self.is_enabled
class NEEMHubSettings(db.Model): """ DB model class for storing neem-hub configuration into postgresql. """ id = db.Column(db.Integer, primary_key=True) mongo_host = db.Column(db.String(255), nullable=False, default='134.102.137.85') mongo_port = db.Column(db.Integer(), default=28015) mongo_db = db.Column(db.String(255), nullable=False, default='neems') mongo_user = db.Column(db.String(255), nullable=False, default='') mongo_pass = db.Column(db.String(255), nullable=False, default='') urdf_server = db.Column( db.String(255), nullable=False, default='http://neem-1.informatik.uni-bremen.de/data/kinematics/') mesh_server = db.Column( db.String(255), nullable=False, default='http://neem-1.informatik.uni-bremen.de/data/') visibility_flag = db.Column(db.Boolean(), nullable=False, default=False)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) active = db.Column(db.Boolean(), nullable=False, default=False) username = db.Column(db.String(50), nullable=False, unique=True) displayname = db.Column(db.String(50), nullable=False, default='') remoteapp = db.Column(db.String(50), nullable=False, default='') # TODO(daniel): unused email = db.Column(db.String(255), nullable=False, unique=True) confirmed_at = db.Column(db.DateTime()) password = db.Column(db.String(255), nullable=False, default='') reset_password_token = db.Column(db.String(100), nullable=False, default='') api_token = db.Column(db.String(64), nullable=False, default='') container_id = db.Column(db.String(255), nullable=False, default='') # Relationships roles = db.relationship('Role', secondary=user_roles, backref=db.backref('users', lazy='dynamic')) liked = db.relationship('NEEMLike', foreign_keys='NEEMLike.user_id', backref='user', lazy='dynamic') def first_role(self): if len(self.roles) == 0: return None else: return self.roles[0].name def like_neem(self, neem_id): if not self.has_liked_neem(neem_id): like = NEEMLike(user_id=self.id, neem_id=neem_id) db.session.add(like) def unlike_neem(self, neem_id): if self.has_liked_neem(neem_id): NEEMLike.query.filter_by( user_id=self.id, neem_id=neem_id).delete() def has_liked_neem(self, neem_id): return NEEMLike.query.filter( NEEMLike.user_id == self.id, NEEMLike.neem_id == neem_id).count() > 0
class NEEMLike(db.Model): __tablename__ = 'neem_like' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) neem_id = db.Column(db.String(50), nullable=False)
class Role(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True)
import datetime from flask_user import UserMixin from app_and_db import app, db # Define the User-Roles pivot table user_roles = db.Table('user_roles', db.Column('id', db.Integer(), primary_key=True), db.Column('user_id', db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))) class Role(db.Model): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True) class NEEMLike(db.Model): __tablename__ = 'neem_like' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) neem_id = db.Column(db.String(50), nullable=False) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) active = db.Column(db.Boolean(), nullable=False, default=False) username = db.Column(db.String(50), nullable=False, unique=True) displayname = db.Column(db.String(50), nullable=False, default='') remoteapp = db.Column(db.String(50), nullable=False, default='') # TODO(daniel): unused
class UserRoles(db.Model): id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE')) role_id = db.Column(db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))