Esempio n. 1
0
class LabelData(db.Model):
    """
    This model holds information about the labeldata of a label to an image
    """
    __tablename__ = "labeldata"

    id = db.Column(db.Integer, primary_key=True)
    months_passed = db.Column(db.Integer)
    latitude = db.Column(db.Integer)
    longitude = db.Column(db.Integer)
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'), nullable=False)
    label_id = db.Column(db.Integer, db.ForeignKey('label.id'), nullable=False)

    def __init__(self, image_id, label_id):
        """
        Initializes the LabelData instance
        """
        self.image_id = image_id
        self.label_id = label_id

    def __repr__(self):
        """
        Returns the object reprensentation
        """
        return "<LabelData %r>" % self.id
Esempio n. 2
0
File: acl.py Progetto: 13052020/cmdb
class Permission(Model):
    __tablename__ = "acl_permissions"

    name = db.Column(db.String(64), nullable=False)
    resource_type_id = db.Column(db.Integer, db.ForeignKey("acl_resource_types.id"))

    app_id = db.Column(db.Integer, db.ForeignKey("acl_apps.id"))
Esempio n. 3
0
class PojectMember(db.Model):
    """
    This model holds information about a projectmember registered
    """
    __tablename__ = "projectmember"

    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id'),
                        primary_key=True,
                        nullable=False)
    team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=False)

    def __init__(self, user_id, project_id, team_id):
        """
        Initializes the projectMember instance
        """
        self.user_id = user_id
        self.project_id = project_id
        self.team_id = team_id

    def __repr__(self):
        """
        Returns the object reprensentation
        """
        return "<ProjectMember %r>" % self.user_id
Esempio n. 4
0
File: acl.py Progetto: 13052020/cmdb
class Resource(Model):
    __tablename__ = "acl_resources"

    name = db.Column(db.String(128), nullable=False)
    resource_type_id = db.Column(db.Integer, db.ForeignKey("acl_resource_types.id"))

    app_id = db.Column(db.Integer, db.ForeignKey("acl_apps.id"))
Esempio n. 5
0
File: acl.py Progetto: 13052020/cmdb
class ResourceGroup(Model):
    __tablename__ = "acl_resource_groups"

    name = db.Column(db.String(64), index=True, nullable=False)
    resource_type_id = db.Column(db.Integer, db.ForeignKey("acl_resource_types.id"))

    app_id = db.Column(db.Integer, db.ForeignKey('acl_apps.id'))
Esempio n. 6
0
File: acl.py Progetto: xmlgrg/cmdb-1
class Role(Model):
    __tablename__ = "acl_roles"

    name = db.Column(db.Text, nullable=False)
    is_app_admin = db.Column(db.Boolean, default=False)
    app_id = db.Column(db.Integer, db.ForeignKey("acl_apps.id"))
    uid = db.Column(db.Integer, db.ForeignKey("users.uid"))
Esempio n. 7
0
class DeployRequest(Model):
    '''
        deploy_requests表
    '''
    __tablename__ = 'deploy_requests'

    deploy = db.Column(db.Integer, db.ForeignKey('deploys.id'))
    name = db.Column(db.String(50))
    type = db.Column(db.Integer,
                     db.ForeignKey('deploy_request_types.id'),
                     default=1)
    extra = db.Column(db.Text)
    host_ids = db.Column(db.Text)
    desc = db.Column(db.String(255), nullable=True)
    status = db.Column(db.Integer, db.ForeignKey('deploy_request_status.id'))
    reason = db.Column(db.String(255), nullable=True)
    version = db.Column(db.String(50), nullable=True)

    create_at = db.Column(db.String(20), default=human_datetime)
    create_by = db.Column(db.Integer, db.ForeignKey('users.id'))
    approve_at = db.Column(db.String(20), nullable=True)
    approve_by = db.Column(db.Integer,
                           db.ForeignKey('users.id'),
                           nullable=True)

    def __str__(self):
        return '<DeployRequest name=%r>' % self.name
Esempio n. 8
0
class Notify(Model):
    """"""
    __tablename__ = 'notify'

    title = db.Column(db.String(255))
    source = db.Column(db.Integer,
                       db.ForeignKey('notify_source.id'),
                       nullable=True)
    type = db.Column(db.Integer,
                     db.ForeignKey('notify_type.id'),
                     nullable=True)
    content = db.Column(db.String(255), nullable=True)
    unread = db.Column(db.Boolean, default=True)
    link = db.Column(db.Boolean, nullable=True)

    created_at = db.Column(db.String(20), default=human_datetime)

    @classmethod
    def make_notify(cls, source, type, title, content=None, with_quiet=True):
        if not with_quiet or time.time() - NotifyCache.get_by_time() > 3600:
            NotifyCache.set_by_time(time.time())
            self.create(source=source, title=title, type=type, content=content)

    def __str__(self):
        return '<Notify %r>' % self.title
Esempio n. 9
0
class RoleRelation(Model):
    __tablename__ = "acl_role_relations"

    parent_id = db.Column(db.Integer, db.ForeignKey('acl_roles.id'))
    child_id = db.Column(db.Integer, db.ForeignKey('acl_roles.id'))

    __table_args__ = (
        db.UniqueConstraint("parent_id", "child_id", name="role_relation_unique"),)
Esempio n. 10
0
class CIValueJson(Model):
    __tablename__ = "c_value_json"

    ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
    attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
    value = db.Column(db.JSON, nullable=False)

    ci = db.relationship("CI", backref="c_value_json.ci_id")
    attr = db.relationship("Attribute", backref="c_value_json.attr_id")
Esempio n. 11
0
File: acl.py Progetto: xmlgrg/cmdb-1
class ResourceGroupItems(Model):
    __tablename__ = "acl_resource_group_items"

    group_id = db.Column(db.Integer,
                         db.ForeignKey('acl_resource_groups.id'),
                         nullable=False)
    resource_id = db.Column(db.Integer,
                            db.ForeignKey('acl_resources.id'),
                            nullable=False)
Esempio n. 12
0
class ResourceGroup(Model):
    __tablename__ = "acl_resource_groups"

    name = db.Column(db.String(64), index=True, nullable=False)
    resource_type_id = db.Column(db.Integer, db.ForeignKey("acl_resource_types.id"))

    app_id = db.Column(db.Integer, db.ForeignKey('acl_apps.id'))

    __table_args__ = (db.UniqueConstraint("name", "resource_type_id", "app_id", name="resource_group_app_unique"),)
Esempio n. 13
0
class Permission(Model):
    __tablename__ = "acl_permissions"

    name = db.Column(db.String(64), nullable=False)
    resource_type_id = db.Column(db.Integer, db.ForeignKey("acl_resource_types.id"))

    app_id = db.Column(db.Integer, db.ForeignKey("acl_apps.id"))

    __table_args__ = (db.UniqueConstraint("name", "resource_type_id", "app_id", name="perm_name_app_unique"),)
Esempio n. 14
0
File: acl.py Progetto: 13052020/cmdb
class RolePermission(Model):
    __tablename__ = "acl_role_permissions"

    rid = db.Column(db.Integer, db.ForeignKey('acl_roles.id'))
    resource_id = db.Column(db.Integer, db.ForeignKey('acl_resources.id'))
    group_id = db.Column(db.Integer, db.ForeignKey('acl_resource_groups.id'))
    perm_id = db.Column(db.Integer, db.ForeignKey('acl_permissions.id'))

    perm = db.relationship("Permission", backref='acl_role_permissions.perm_id')
Esempio n. 15
0
class CIRelationHistory(Model):
    __tablename__ = "c_relation_histories"

    operate_type = db.Column(db.Enum(OperateType.ADD, OperateType.DELETE, name="operate_type"))
    record_id = db.Column(db.Integer, db.ForeignKey("c_records.id"), nullable=False)
    first_ci_id = db.Column(db.Integer)
    second_ci_id = db.Column(db.Integer)
    relation_type_id = db.Column(db.Integer, db.ForeignKey("c_relation_types.id"))
    relation_id = db.Column(db.Integer, nullable=False)
Esempio n. 16
0
class CIValueDateTime(Model):
    __tablename__ = "c_value_datetime"

    ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
    attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
    value = db.Column(db.DateTime, nullable=False)

    ci = db.relationship("CI", backref="c_value_datetime.ci_id")
    attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
Esempio n. 17
0
class PreferenceRelationView(Model):
    __tablename__ = "c_preference_relation_views"

    name = db.Column(db.String(8), index=True, nullable=False)
    parent_id = db.Column(db.Integer,
                          db.ForeignKey("c_ci_types.id"),
                          nullable=False)
    child_id = db.Column(db.Integer,
                         db.ForeignKey("c_ci_types.id"),
                         nullable=False)
Esempio n. 18
0
class CITypeGroupItem(Model):
    __tablename__ = "c_ci_type_group_items"

    group_id = db.Column(db.Integer,
                         db.ForeignKey("c_ci_type_groups.id"),
                         nullable=False)
    type_id = db.Column(db.Integer,
                        db.ForeignKey("c_ci_types.id"),
                        nullable=False)
    order = db.Column(db.SmallInteger, default=0)
Esempio n. 19
0
class CITypeAttribute(Model):
    __tablename__ = "c_ci_type_attributes"

    type_id = db.Column(db.Integer, db.ForeignKey("c_ci_types.id"), nullable=False)
    attr_id = db.Column(db.Integer, db.ForeignKey("c_attributes.id"), nullable=False)
    order = db.Column(db.Integer, default=0)
    is_required = db.Column(db.Boolean, default=False)
    default_show = db.Column(db.Boolean, default=True)

    attr = db.relationship("Attribute", backref="c_ci_type_attributes.attr_id")
Esempio n. 20
0
class CITypeRelation(Model):
    __tablename__ = "c_ci_type_relations"

    parent_id = db.Column(db.Integer, db.ForeignKey("c_ci_types.id"), nullable=False)
    child_id = db.Column(db.Integer, db.ForeignKey("c_ci_types.id"), nullable=False)
    relation_type_id = db.Column(db.Integer, db.ForeignKey("c_relation_types.id"), nullable=False)

    parent = db.relationship("CIType", primaryjoin="CIType.id==CITypeRelation.parent_id")
    child = db.relationship("CIType", primaryjoin="CIType.id==CITypeRelation.child_id")
    relation_type = db.relationship("RelationType", backref="c_ci_type_relations.relation_type_id")
Esempio n. 21
0
class PreferenceShowAttributes(Model):
    __tablename__ = "c_preference_show_attributes"

    uid = db.Column(db.Integer, index=True, nullable=False)
    type_id = db.Column(db.Integer, db.ForeignKey("c_ci_types.id"), nullable=False)
    attr_id = db.Column(db.Integer, db.ForeignKey("c_attributes.id"))
    order = db.Column(db.SmallInteger, default=0)

    ci_type = db.relationship("CIType", backref="c_preference_show_attributes.type_id")
    attr = db.relationship("Attribute", backref="c_preference_show_attributes.attr_id")
Esempio n. 22
0
class CIRelation(Model):
    __tablename__ = "c_ci_relations"

    first_ci_id = db.Column(db.Integer, db.ForeignKey("c_cis.id"), nullable=False)
    second_ci_id = db.Column(db.Integer, db.ForeignKey("c_cis.id"), nullable=False)
    relation_type_id = db.Column(db.Integer, db.ForeignKey("c_relation_types.id"), nullable=False)
    more = db.Column(db.Integer, db.ForeignKey("c_cis.id"))

    first_ci = db.relationship("CI", primaryjoin="CI.id==CIRelation.first_ci_id")
    second_ci = db.relationship("CI", primaryjoin="CI.id==CIRelation.second_ci_id")
    relation_type = db.relationship("RelationType", backref="c_ci_relations.relation_type_id")
Esempio n. 23
0
class CIIndexValueText(Model):
    __tablename__ = "c_value_index_texts"

    ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
    attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
    value = db.Column(db.String(128), nullable=False)

    ci = db.relationship("CI", backref="c_value_index_texts.ci_id")
    attr = db.relationship("Attribute", backref="c_value_index_texts.attr_id")

    __table_args__ = (db.Index("text_attr_value_index", "attr_id", "value"),)
Esempio n. 24
0
class CartItem(db.Model):
    __tablename__ = 'cart_items'

    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'), nullable=False)
    cart_id = db.Column(db.Integer, db.ForeignKey('cart.id'), nullable=False)
    book = db.relationship(
        'Book',
        backref=db.backref('cart_items', uselist=False))
    created_at = db.Column(db.DateTime, default=datetime.now(pytz.utc))

    def __repr__(self):
        return '<CartItem {}>'.format(self.id)
Esempio n. 25
0
class SavedFeedItem(BaseModel):

    __table_args__ = (db.UniqueConstraint('feed_item_id', 'user_id'), )

    feed_item_id = db.Column(db.Integer,
                             db.ForeignKey('feeditem.id', ondelete='CASCADE'),
                             nullable=False)

    user_id = db.Column(
        db.Integer,
        db.ForeignKey('user.id', ondelete='CASCADE'),
        nullable=False,
    )
Esempio n. 26
0
class Rental(db.Model):
    __tablename__ = "rentals"

    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'), nullable=False)
    customer_id = db.Column(db.Integer,
                            db.ForeignKey('customers.id'),
                            nullable=False)
    due_at = db.Column(db.DateTime, nullable=True)
    status = db.Column(db.String(80), default=PENDING, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.now(pytz.utc))

    def __repr__(self):
        return '<Rental {}>'.format(self.id)
Esempio n. 27
0
class Config(Model):
    __tablename__ = 'configs'

    type = db.Column(db.Integer, db.ForeignKey('config_types.id'))
    o_id = db.Column(db.Integer)
    key = db.Column(db.String(50))
    env = db.Column(db.Integer, db.ForeignKey('environments.id'))
    value = db.Column(db.Text, nullable=True)
    desc = db.Column(db.String(255), nullable=True)
    is_public = db.Column(db.Boolean)
    updated_at = db.Column(db.String(20))
    updated_by = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __str__(self):
        return '<Config %r>' % self.key
Esempio n. 28
0
class AcmeDns(Model):
    __tablename__ = 'acme_dns'
    
    user = db.Column(db.String(50),nullable=True)
    key  = db.Column(db.String(50),nullable=True)
    acme_dns_type_id = db.Column(db.Integer, db.ForeignKey('acme_dns_type.id'))
    acme_dns_type = db.relationship('AcmeDnsType', backref=db.backref('acme_dns'), lazy='subquery', foreign_keys=[acme_dns_type_id])

    created_at = db.Column(db.String(20), default=human_datetime)
    created_by = db.Column(db.Integer, db.ForeignKey('users.id'))
    deleted_at = db.Column(db.String(20), nullable=True)
    deleted_by = db.Column(db.Integer, db.ForeignKey('users.id'))

    def __str__(self):
        return '<Dns %r>' % self.user
Esempio n. 29
0
class Forecast(db.Model):
    __tablename__ = 'forecast'
    id = db.Column(db.Integer, primary_key=True)
    city_id = db.Column(db.Integer, db.ForeignKey('city.id'), nullable=False)
    date = db.Column(db.Date, nullable=False)
    rain_probability = db.Column(db.Integer, nullable=False)
    rain_precipitation = db.Column(db.Integer, nullable=False)
    min_temperature = db.Column(db.Integer, nullable=False)
    max_temperature = db.Column(db.Integer, nullable=False)

    __table_args__ = (db.UniqueConstraint('city_id',
                                          'date',
                                          name='_forecast_city_id_date_uc'), )

    @staticmethod
    def update_or_create(city_id, date, rain_probability, rain_precipitation,
                         min_temperature, max_temperature):
        forecast = Forecast.query.filter_by(city_id=city_id, date=date).first()
        forecast = forecast if forecast else Forecast()
        forecast.city_id = city_id
        forecast.date = date
        forecast.rain_probability = rain_probability
        forecast.rain_precipitation = rain_precipitation
        forecast.min_temperature = min_temperature
        forecast.max_temperature = max_temperature
        db.session.add(forecast)
        db.session.flush()
        return forecast
Esempio n. 30
0
class State(db.Model):
    __tablename__ = 'state'
    id = db.Column(db.Integer, primary_key=True)
    abbreviation = db.Column(db.String(10), nullable=False)
    country_id = db.Column(db.Integer,
                           db.ForeignKey('country.id'),
                           nullable=False)

    __table_args__ = (db.UniqueConstraint('abbreviation',
                                          'country_id',
                                          name='_state_country_id_uc'), )

    @staticmethod
    def get_or_create(abbreviation, country):
        state = State.query.filter_by(abbreviation=abbreviation) \
            .join(Country) \
            .filter(Country.abbreviation == country) \
            .first()
        if state:
            return state
        country = Country.get_or_create(country)
        state = State()
        state.abbreviation = abbreviation
        state.country_id = country.id
        db.session.add(state)
        db.session.flush()
        return state