예제 #1
0
class Backup(db.Model):
    __tablename__ = 'backups'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    created = db.Column(db.DateTime, default=timezone.now)
    group_id = db.Column(db.Integer, db.ForeignKey('groups.id'))
    recoveries = db.relationship('Recovery', backref='backup', lazy='dynamic')
예제 #2
0
class PayloadScheme(db.Model):
    __tablename__ = 'payload_scheme'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    description = db.Column(db.String(512))
    payload = db.Column(JSONType, nullable=False, default={})
예제 #3
0
class ResultFormatter(db.Model):
    __tablename__ = 'formatters'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    template = db.Column(db.Text, nullable=False)
    action_id = db.Column(db.Integer, db.ForeignKey('actions.id'))
    enabled = db.Column(db.Boolean, nullable=False, default=True)
예제 #4
0
class GeoLocation(db.Model):
    __tablename__ = 'geo_locations'

    id = db.Column(db.Integer, primary_key=True)
    point = db.Column(Geometry(geometry_type='POINT', srid=4326))
    region_id = db.Column(db.Integer, db.ForeignKey('geo_location_regions.id'))
    servers = db.relationship('Server', backref='geo_location', lazy='dynamic')
    default = db.Column(db.Boolean, nullable=False, default=False)

    @classmethod
    async def get_nearest(cls, lat, lon):
        """
        Find the nearest point to the input coordinates.
        Convert the input coordinates to a WKT point and query for nearest point.
        """
        pt = WKTElement('POINT({0} {1})'.format(lon, lat), srid=4326)
        return cls.query.order_by(cls.point.distance_box(pt)).first()

    @classmethod
    async def get_default(cls):
        return cls.query.filter_by(default=True).order_by(cls.id).first()

    @staticmethod
    async def from_point_to_xy(pt):
        """Extract x and y coordinates from a point geometry."""
        # noinspection PyUnresolvedReferences
        point_json = json.loads(db.session.scalar(func.ST_AsGeoJSON(pt.point)))
        return point_json['coordinates']
예제 #5
0
class IntervalSchedule(Model):
    __tablename__ = "interval_schedule"

    PERIOD_CHOICES = (('days', _('Days')), ('hours', _('Hours')),
                      ('minutes', _('Minutes')), ('seconds', _('Seconds')),
                      ('microseconds', _('Microseconds')))

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    every = db.Column(db.Integer, nullable=False)
    period = db.Column(ChoiceType(PERIOD_CHOICES))
    periodic_tasks = db.relationship('PeriodicTask')

    @property
    def schedule(self):
        return schedules.schedule(
            datetime.timedelta(**{self.period.code: self.every}))

    @classmethod
    def from_schedule(cls, session, schedule, period='seconds'):
        every = max(schedule.run_every.total_seconds(), 0)
        obj = cls.filter_by(session, every=every, period=period).first()
        if obj is None:
            return cls(every=every, period=period)
        else:
            return obj

    def __str__(self):
        if self.every == 1:
            return _('every {0.period_singular}').format(self)
        return _('every {0.every} {0.period}').format(self)

    @property
    def period_singular(self):
        return self.period[:-1]
예제 #6
0
class PeriodicTask(Model):
    __tablename__ = "periodic_task"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(length=120), unique=True)
    task = db.Column(db.String(length=120))
    crontab_id = db.Column(db.Integer, db.ForeignKey('crontab_schedule.id'))
    crontab = db.relationship("CrontabSchedule",
                              back_populates="periodic_tasks")
    interval_id = db.Column(db.Integer, db.ForeignKey('interval_schedule.id'))
    interval = db.relationship("IntervalSchedule",
                               back_populates="periodic_tasks")
    args = db.Column(db.String(length=120))
    kwargs = db.Column(db.String(length=120))
    last_run_at = db.Column(db.DateTime, default=timezone.now)
    total_run_count = db.Column(db.Integer, default=0)
    enabled = db.Column(db.Boolean, default=True)
    no_changes = False

    def __str__(self):
        fmt = '{0.name}: {0.crontab}'
        return fmt.format(self)

    @property
    def schedule(self):
        if self.crontab:
            return self.crontab.schedule
        if self.interval:
            return self.interval.schedule
예제 #7
0
class ResultFormatter(db.Model):
    __tablename__ = 'formatters'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    template = db.Column(db.Text, nullable=False)
    action = db.relationship('Action', backref='formatter', lazy='dynamic')
    enabled = db.Column(db.Boolean, nullable=False, default=True)
예제 #8
0
class Post(db.Model):
    __tablename__ = 'posts'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    created = db.Column(db.DateTime, default=timezone.now)
    content = db.Column(db.Text, nullable=False)
    active = db.Column(db.Boolean, nullable=False, default=True)
    category_id = db.Column(db.Integer, db.ForeignKey('categories.id'))
예제 #9
0
class Category(db.Model):
    __tablename__ = 'category'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=True, unique=True)
    scheme = db.Column(JSONType, nullable=False, default={})
    items = db.relationship('Item', backref='category', lazy='dynamic')
    active = db.Column(db.Boolean, nullable=False, default=True)
예제 #10
0
class GeoLocationRegion(db.Model):
    __tablename__ = 'geo_location_regions'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    locations = db.relationship('GeoLocation',
                                backref='region',
                                lazy='dynamic')
예제 #11
0
class CredentialType(db.Model):
    __tablename__ = 'credential_type'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, nullable=False)

    def __repr__(self):
        return "CredentialType(title={0})".format(self.title)
예제 #12
0
class Role(db.Model):
    __tablename__ = 'role'

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100))

    def __repr__(self):
        return "Role(title={0})".format(self.title)
예제 #13
0
class Scope(db.Model):
    __tablename__ = 'scope'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), nullable=False)

    def __repr__(self):
        return "Scope(id={0}, name={1})".format(self.id, self.name)
예제 #14
0
class Group(db.Model):
    __tablename__ = 'groups'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    active = db.Column(db.Boolean, nullable=False, default=True)
    backups = db.relationship('Backup', backref='group', lazy='dynamic')
    recoveries = db.relationship('Recovery', backref='group',
                                 lazy='dynamic')  # TODO: ?
    color = db.Column(ColorType)
예제 #15
0
class ApplicationVersion(db.Model):
    __tablename__ = 'application_versions'
    __table_args__ = (db.UniqueConstraint('app_name', 'app_version'), )

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    app_name = db.Column(db.String(128), nullable=False)
    app_version = db.Column(db.String(128), nullable=False)
    build_id = db.Column(db.Integer, db.ForeignKey('builds.id'))
    build = db.relationship('Build')
예제 #16
0
class Market(db.Model):
    __tablename__ = 'markets'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=True)
    title = db.Column(db.String(512), nullable=True)
    enabled = db.Column(db.Boolean, nullable=False, default=True)
    sellers = db.relationship('Seller', backref='market', lazy='dynamic')
    items = db.relationship('Item', backref='market', lazy='dynamic')
예제 #17
0
class Store(db.Model):
    __tablename__ = 'stores'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=True, unique=True)
    payload = db.Column(JSONType, nullable=False, default={})
    orders = db.relationship('Order', backref='store', lazy='dynamic')
    items = db.relationship('Item', backref='store', lazy='dynamic')
    active = db.Column(db.Boolean, nullable=False, default=True)
예제 #18
0
class ApplicationVersion(db.Model):
    __tablename__ = 'application_versions'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    value = db.Column(db.String(128), nullable=False)
    application_id = db.Column(
        db.Integer, db.ForeignKey('applications.id'), nullable=False, index=True)
    groups = db.relationship(
        'BundlesGroup', backref=db.backref('application_version'), lazy='dynamic',
        cascade='all, delete-orphan')
예제 #19
0
class ApplicationVersion(db.Model):
    __tablename__ = 'application_versions'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    value = db.Column(db.String(128), nullable=False)
    commit = db.Column(db.String(128), nullable=False, unique=True)
    application_id = db.Column(db.Integer,
                               db.ForeignKey('applications.id'),
                               nullable=False,
                               index=True)
예제 #20
0
class Category(db.Model):
    __tablename__ = 'categories'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=False, unique=True)
    description = db.Column(db.String(512), nullable=False)
    posts = db.relationship('Post', backref='category', lazy='dynamic')

    def get_posts(self):
        return self.posts.filter_by(active=True).all()
예제 #21
0
class Category(db.Model):
    __tablename__ = 'categories'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=False, unique=True)
    description = db.Column(db.String(512), nullable=False)
    posts = db.relationship('Post', backref='category', lazy='dynamic')

    def __repr__(self):
        return '<Category(name=%s)>' % self.name
예제 #22
0
class URLMessage(Message):
    __tablename__ = 'url_messages'

    id = db.Column(db.Integer, db.ForeignKey('messages.id'), primary_key=True)
    content_type = db.Column(db.String(128), nullable=False)
    value = db.Column(URLType, nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': 'url_message',
    }
예제 #23
0
class ModerationWarningThreshold(db.Model):
    __tablename__ = 'warning_thresholds'
    __table_args__ = ()

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    action_type = db.Column(ChoiceType(ACTION_TYPES),
                            unique=True,
                            nullable=False)
    value = db.Column(db.Integer,
                      nullable=False,
                      default=DEFAULT_MODERATION_WARNING_THRESHOLD)
예제 #24
0
class Application(db.Model):
    __tablename__ = 'applications'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(256), nullable=False)
    deployment_method_id = db.Column(
        db.Integer, db.ForeignKey('deployment_methods.id'), nullable=False, index=True)
    filters_scheme = db.Column(JSONType, nullable=False)
    payload_scheme = db.Column(JSONType, nullable=False)
    versions = db.relationship(
        'ApplicationVersion', backref=db.backref('application'), lazy='dynamic',
        cascade='all, delete-orphan')
예제 #25
0
class Group(db.Model):
    __tablename__ = 'groups'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(128), nullable=False)
    description = db.Column(db.String(512), nullable=False)

    recoveries = db.relationship('Recovery', backref='group', lazy='dynamic')
    backups = db.relationship('Backup', backref='group', lazy='dynamic')

    def __repr__(self):
        return '<Group(name=%s)>' % self.name
예제 #26
0
class TextMessage(Message):
    __tablename__ = 'text_messages'

    id = db.Column(db.Integer, db.ForeignKey('messages.id'), primary_key=True)
    content_type = db.Column(db.String(128),
                             nullable=False,
                             default='text/plain')
    value = db.Column(db.Text, nullable=False)

    __mapper_args__ = {
        'polymorphic_identity': 'text_message',
    }
예제 #27
0
class Application(db.Model):
    __tablename__ = 'applications'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(256), nullable=False)
    repo_url = db.Column(db.String(512), nullable=False)
    repo_branch = db.Column(db.String(128), default='master')
    repo_ssh_key = db.Column(db.Text)
    versions = db.relationship('ApplicationVersion',
                               backref='application',
                               lazy='dynamic',
                               cascade='all, delete-orphan')
예제 #28
0
class Seller(InternalAPIMixin, db.Model):
    __tablename__ = 'sellers'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, nullable=False, unique=True)
    market_id = db.Column(db.Integer, db.ForeignKey('markets.id'))
    enabled = db.Column(db.Boolean, nullable=False, default=True)

    async def get_user(self) -> RemoteUser:
        data = await self.internal_request('login',
                                           'get_user',
                                           user_id=self.user_id)
        return RemoteUser(**data)
예제 #29
0
class Order(InternalAPIMixin, db.Model):
    __tablename__ = 'orders'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, nullable=False)
    item_id = db.Column(db.Integer, db.ForeignKey('items.id'))
    created = db.Column(db.DateTime, default=timezone.now)

    async def get_user(self) -> RemoteUser:
        data = await self.internal_request('login',
                                           'get_user',
                                           user_id=self.user_id)
        return RemoteUser(**data)
예제 #30
0
class Player(InternalAPIMixin, db.Model):
    __tablename__ = 'players'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, nullable=False)
    room_id = db.Column(db.Integer, db.ForeignKey('rooms.id'))
    payload = db.Column(JSONType, nullable=False, default={})

    async def get_user(self) -> RemoteUser:
        data = await self.internal_request('login',
                                           'get_user',
                                           user_id=self.user_id)
        return RemoteUser(**data)