コード例 #1
0
class UserRoles(db.Model):
    __tablename__ = 'user_roles'
    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'))
コード例 #2
0
class Query(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        nullable=False,
                        default=0)
    query_name = db.Column(db.String(120))
    db_name = db.Column(db.String(20))
    date_uploaded = db.Column(db.DateTime,
                              nullable=False,
                              default=datetime.datetime.now)
    last_update_time = db.Column(db.DateTime,
                                 nullable=False,
                                 default=datetime.datetime.now)
    query_text = db.Column(db.Text, nullable=False, default='')
    only_user = db.Column(db.Boolean, default=False)
    only_team = db.Column(db.Boolean, default=False)
    public = db.Column(db.Boolean, default=True)
    parameters = db.relationship('QueryTextParameters',
                                 backref='query',
                                 lazy=True)
    polygon_parameters = db.relationship('QueryPolygonParameters',
                                         backref='query',
                                         lazy=True)

    def __repr__(self):
        return self.query_name

    @staticmethod
    def get_user(user_id):
        return User.query.get(user_id)

    @property
    def pretty_last_update_time(self):
        return self.last_update_time.strftime('%Y-%m-%d %H:%M')
コード例 #3
0
class Polygon(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    layer_id = db.Column(db.Integer, db.ForeignKey('layer.id'))
    coordinates = db.relationship('PolygonCoordinate',
                                  order_by='PolygonCoordinate.index',
                                  backref='layer',
                                  lazy=True)
    description = db.Column(db.Text, default='')
    color = db.Column(db.String(20), default='blue')
コード例 #4
0
class QueryTextParameters(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    query_id = db.Column(db.Integer, db.ForeignKey('query.id'), nullable=False)
    parameter_name = db.Column(db.String(100), nullable=False)
    parameter_type = db.Column(db.String(100), nullable=False)

    def serialize(self):
        return {
            c: getattr(self, c)
            for c in inspect(self).attrs.keys() if c != 'query'
        }
コード例 #5
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    first_name = db.Column(db.String(20), nullable=False, default='')
    last_name = db.Column(db.String(20), nullable=False, default='')
    password = db.Column(db.String(60), nullable=False)
    team_id = db.Column(db.Integer, db.ForeignKey('team.id'))
    roles = db.relationship('Role', secondary='user_roles')
    layers = db.relationship('Layer', backref='user', lazy=True)
    queries = db.relationship('Query', backref='user', lazy=True)
    preferences = db.relationship('UserPreferences', backref='user', lazy=True)

    def __repr__(self):
        return f"'{self.username}', '{self.email}'"

    @property
    def full_name(self):
        return f'{self.first_name} {self.last_name}'

    def has_role(self, role_name):
        for role in self.roles:
            if role.name == role_name:
                return True
        return False
コード例 #6
0
class Layer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    default_color = db.Column(db.String(20), default='blue')
    only_user = db.Column(db.Boolean, default=True)
    only_team = db.Column(db.Boolean, default=False)
    public = db.Column(db.Boolean, default=False)
    points = db.relationship('Point', backref='layer', lazy=True)
    polygons = db.relationship('Polygon', backref='layer', lazy=True)

    def __repr__(self):
        return self.name
コード例 #7
0
class Point(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    layer_id = db.Column(db.Integer, db.ForeignKey('layer.id'))
    lon = db.Column(db.Float, nullable=False)
    lat = db.Column(db.Float, nullable=False)
    description = db.Column(db.Text, default='')
    color = db.Column(db.String(20), default='blue')

    def __repr__(self):
        return f'{self.lon}, {self.lat}: {self.description}'
コード例 #8
0
class Role(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(50), unique=True)
コード例 #9
0
class UserPreferences(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    starting_lon = db.Column(db.Float, default=37.485509)
    starting_lat = db.Column(db.Float, default=33.247876)
    starting_zoom = db.Column(db.Integer, default=6)
コード例 #10
0
class UserMarkedLayer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    layer_id = db.Column(db.Integer, db.ForeignKey('layer.id'))
コード例 #11
0
class UserMarkedQuery(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    query_id = db.Column(db.Integer, db.ForeignKey('query.id'))
コード例 #12
0
class Team(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    users = db.relationship('User', backref='team', lazy=True)
コード例 #13
0
class PolygonCoordinate(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    polygon_id = db.Column(db.Integer, db.ForeignKey('polygon.id'))
    index = db.Column(db.Integer, nullable=False)
    lon = db.Column(db.Float, nullable=False)
    lat = db.Column(db.Float, nullable=False)
コード例 #14
0
class QueryPolygonParameters(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    query_id = db.Column(db.Integer, db.ForeignKey('query.id'), nullable=False)
    lon_column = db.Column(db.String(100), nullable=False)
    lat_column = db.Column(db.String(100), nullable=False)