コード例 #1
0
class Association(db.Model):
    __tablename__ = 'association'
    id = db.Column(db.Integer, primary_key=True)
    property_id = db.Column(db.Integer,
                            db.ForeignKey('property.id'),
                            nullable=False)
    value_id = db.Column(db.Integer, db.ForeignKey('value.id'), nullable=False)
コード例 #2
0
class Message(db.Model):
    """Messages for our website"""

    __table_args__ = (db.UniqueConstraint("version", "product_id",
                                          "template_id"), )
    pk = db.Column(db.Integer, primary_key=True)
    version = db.Column(db.String(5), nullable=False)

    product_id = db.Column(db.Integer,
                           db.ForeignKey("product.pk"),
                           nullable=False)
    product = db.relationship("Product", lazy=False)

    template_id = db.Column(db.Integer,
                            db.ForeignKey("template.pk"),
                            nullable=False)
    template = db.relationship("Template", lazy=False)

    def __init__(self, version, product_id, template_id):
        self.version = version
        self.product_id = product_id
        self.template_id = template_id

    @property
    def sms_body(self):
        return "{}: {!r}".format(self.template.body, self.product)

    def to_dict(self):
        return {
            "pk": self.pk,
            "version": self.version,
            "template_id": self.template_id,
            "product_id": self.product_id,
        }
コード例 #3
0
class CardItem(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    card_id = db.Column(db.Integer, db.ForeignKey('card.id'), nullable=False)
    item_id = db.Column(db.Integer, db.ForeignKey('item.id'), nullable=False)
    row = db.Column(db.Integer, nullable=False)
    col = db.Column(db.Integer, nullable=False)
    card = relationship('Card', back_populates='card_items')
    item = relationship('Item')
    __table_args__ = (
        UniqueConstraint(
            'card_id', 'item_id',
            name='_card_item_uc'),  # can only add an item once to a card
        UniqueConstraint(
            'card_id', 'row', 'col',
            name='_card_position_uc'),  # can only put one item in a position
    )

    def __repr__(self):
        return str(self)

    def __str__(self):
        return f'{self.__class__.__name__}: {self.card_id} ({self.row},{self.col})'

    def __lt__(self, other):
        # ordering for 2x2 should be (0,0),(0,1),(1,0),(1,1)
        return self.card.rows * self.row + self.col < other.card.rows * other.row + other.col
コード例 #4
0
class Property(db.Model):
    """
    Represent a property of a shelter.
    """
    id = db.Column(db.Integer, primary_key=True)

    # relationship
    shelter_id = db.Column(db.Integer,
                           db.ForeignKey('shelter.id'),
                           nullable=False)
    attribute_id = db.Column(db.Integer,
                             db.ForeignKey('attribute.id'),
                             nullable=False)
    attribute = db.relationship("Attribute", back_populates="properties")

    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
    category = db.relationship("Category", back_populates="properties")

    #values = db.relationship("Value", secondary=association_table,
    #backref="properties")
    values = db.relationship("Value", secondary="association")

    def get_values_as_string(self):
        return ", ".join([value.name for value in self.values])

    def __str__(self):
        """
        Required for administrative interface.
        """
        return str(self.id)
コード例 #5
0
ファイル: reserve.py プロジェクト: vinidotruan/python-api
class Reserve(db.Model):
    __tablename__ = "reserves"

    id = db.Column(db.Integer, primary_key=True)
    date_out = db.Column(db.Date, unique=False, nullable=False)
    date_back = db.Column(db.Date, unique=False, nullable=True)
    client_id = db.Column(db.Integer,
                          db.ForeignKey('clients.id'),
                          nullable=False)
    client = db.relationship('Client', backref=db.backref('reserves'))
    book_id = db.Column(db.Integer, db.ForeignKey('books.id'), nullable=False)
    book = db.relationship('Book', backref=db.backref('reserves'))

    def __repr__(self):
        return f'Reserve {self.id}'

    def response(reserve):
        return jsonify({
            'date_out': reserve.date_out,
            'date_back': reserve.date_back,
            'client_id': reserve.client_id,
            'book_id': reserve.book_id
        })

    def delayDay(reserve):
        calc = date.today() - reserve.date_out
        return calc.days
コード例 #6
0
ファイル: feed.py プロジェクト: pking74/newspipe
class Feed(db.Model, RightMixin):
    """
    Represent a feed.
    """
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="FR")
    link = db.Column(db.String(), nullable=False)
    site_link = db.Column(db.String(), default="")
    enabled = db.Column(db.Boolean(), default=True)
    created_date = db.Column(db.DateTime(), default=datetime.utcnow)
    filters = db.Column(db.PickleType, default=[])
    private = db.Column(db.Boolean(), default=False)

    # cache handling
    etag = db.Column(db.String(), default="")
    last_modified = db.Column(db.String(), default="")
    last_retrieved = db.Column(db.DateTime(), default=datetime(1970, 1, 1))

    # error logging
    last_error = db.Column(db.String(), default="")
    error_count = db.Column(db.Integer(), default=0)

    # relationship
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))
    articles = db.relationship(Article,
                               backref='source',
                               lazy='dynamic',
                               cascade='all,delete-orphan',
                               order_by=desc(Article.date))

    # index
    idx_feed_uid_cid = Index('user_id', 'category_id')
    idx_feed_uid = Index('user_id')

    # api whitelists
    @staticmethod
    def _fields_base_write():
        return {
            'title', 'description', 'link', 'site_link', 'enabled', 'filters',
            'last_error', 'error_count', 'category_id'
        }

    @staticmethod
    def _fields_base_read():
        return {'id', 'user_id', 'icon_url', 'last_retrieved'}

    @validates('title')
    def validates_title(self, key, value):
        return str(value).strip()

    @validates('description')
    def validates_description(self, key, value):
        return str(value).strip()

    def __repr__(self):
        return '<Feed %r>' % (self.title)
コード例 #7
0
class Feed(db.Model):
    """
    Represent a feed.
    """
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="FR")
    link = db.Column(db.String())
    site_link = db.Column(db.String(), default="")
    enabled = db.Column(db.Boolean(), default=True)
    created_date = db.Column(db.DateTime(), default=datetime.now)
    filters = db.Column(db.PickleType, default=[])

    # cache handling
    etag = db.Column(db.String(), default="")
    last_modified = db.Column(db.String(), default="")
    last_retrieved = db.Column(db.DateTime(), default=datetime(1970, 1, 1))

    # error logging
    last_error = db.Column(db.String(), default="")
    error_count = db.Column(db.Integer(), default=0)

    # relationship
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))
    articles = db.relationship('Article',
                               backref='source',
                               lazy='dynamic',
                               cascade='all,delete-orphan',
                               order_by=desc("date"))

    def __repr__(self):
        return '<Feed %r>' % (self.title)

    def dump(self):
        return {
            "id": self.id,
            "user_id": self.user_id,
            "category_id": self.category_id,
            "title": self.title,
            "description": self.description,
            "link": self.link,
            "site_link": self.site_link,
            "etag": self.etag,
            "enabled": self.enabled,
            "filters": self.filters,
            "icon_url": self.icon_url,
            "error_count": self.error_count,
            "last_error": self.last_error,
            "created_date": self.created_date,
            "last_modified": self.last_modified,
            "last_retrieved": self.last_retrieved,
            "nb_articles": self.articles.count()
        }
コード例 #8
0
class Article(db.Model):
    "Represent an article from a feed."
    id = db.Column(db.Integer(), primary_key=True)
    entry_id = db.Column(db.String())
    link = db.Column(db.String())
    title = db.Column(db.String())
    content = db.Column(db.String())
    readed = db.Column(db.Boolean(), default=False)
    like = db.Column(db.Boolean(), default=False)
    date = db.Column(db.DateTime(), default=datetime.now)
    updated_date = db.Column(db.DateTime(), default=datetime.now)
    retrieved_date = db.Column(db.DateTime(), default=datetime.now)

    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    feed_id = db.Column(db.Integer(), db.ForeignKey('feed.id'))
    category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))

    def previous_article(self):
        """
        Returns the previous article (older).
        """
        return Article.query.filter(Article.date < self.date,
                                    Article.feed_id == self.feed_id)\
                            .order_by(desc("date")).first()

    def next_article(self):
        """
        Returns the next article (newer).
        """
        return Article.query.filter(Article.date > self.date,
                                    Article.feed_id == self.feed_id)\
                            .order_by(asc("date")).first()

    def __repr__(self):
        return "<Article(id=%d, entry_id=%s, title=%r, " \
               "date=%r, retrieved_date=%r)>" % (self.id, self.entry_id,
                       self.title, self.date, self.retrieved_date)

    def dump(self):
        return {
            "id": self.id,
            "user_id": self.user_id,
            "entry_id": self.entry_id,
            "title": self.title,
            "link": self.link,
            "content": self.content,
            "readed": self.readed,
            "like": self.like,
            "date": self.date,
            "updated_date": self.updated_date,
            "retrieved_date": self.retrieved_date,
            "feed_id": self.feed_id,
            "category_id": self.category_id
        }
コード例 #9
0
ファイル: project.py プロジェクト: massimiliano76/Freshermeat
class Project(db.Model):
    """Represent a project.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    short_description = db.Column(db.String(300), unique=True)
    description = db.Column(db.String(), unique=True)
    website = db.Column(db.String())
    enabled = db.Column(db.Boolean(), default=True)
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow())

    # if cve_vendor is the empty string use the parent property
    # (organization.cve_vendor)
    cve_vendor = db.Column(db.String(), default='')
    cve_product = db.Column(db.String(), unique=True, nullable=False)

    automatic_release_tracking = db.Column(db.String())

    notification_email = db.Column(db.String(), default='')
    required_informations = db.Column(JSON, default=None)

    # foreign keys
    organization_id = db.Column(db.Integer(), db.ForeignKey('organization.id'))
    manager_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)

    # relationships
    tag_objs = db.relationship('Tag',
                               back_populates='project',
                               cascade='all,delete-orphan',
                               lazy=False,
                               foreign_keys='[Tag.project_id]')
    tags = association_proxy('tag_objs', 'text')
    licenses = db.relationship("License",
                               secondary=lambda: association_table,
                               backref="projects")
    cves = db.relationship('CVE',
                           backref='project',
                           lazy='dynamic',
                           cascade='all,delete-orphan')
    releases = db.relationship('Release',
                               backref='project',
                               lazy='dynamic',
                               cascade='all,delete-orphan')

    @validates('name')
    def validates_name(self, key, value):
        assert len(value) <= 100, \
            AssertionError("maximum length for name: 100")
        return value.replace(' ', '').strip()

    def __repr__(self):
        return '<Name %r>' % (self.name)
コード例 #10
0
ファイル: article.py プロジェクト: v-khdumi/JARR
class Article(db.Model, RightMixin):
    "Represent an article from a feed."
    id = db.Column(db.Integer(), primary_key=True)
    entry_id = db.Column(db.String())
    link = db.Column(db.String())
    title = db.Column(db.String())
    content = db.Column(db.String())
    readed = db.Column(db.Boolean(), default=False)
    like = db.Column(db.Boolean(), default=False)
    date = db.Column(db.DateTime(), default=datetime.utcnow)
    retrieved_date = db.Column(db.DateTime(), default=datetime.utcnow)
    readability_parsed = db.Column(db.Boolean(), default=False)

    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    feed_id = db.Column(db.Integer(), db.ForeignKey('feed.id'))
    category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))

    idx_article_uid = Index('user_id')
    idx_article_uid_cid = Index('user_id', 'category_id')
    idx_article_uid_fid = Index('user_id', 'feed_id')

    # api whitelists
    @staticmethod
    def _fields_base_write():
        return {'readed', 'like', 'readability_parsed',
                'feed_id', 'category_id'}

    @staticmethod
    def _fields_base_read():
        return {'id', 'entry_id', 'link', 'title', 'content', 'date',
                'retrieved_date', 'user_id'}

    def previous_article(self):
        """
        Returns the previous article (older).
        """
        return Article.query.filter(Article.date < self.date,
                                    Article.feed_id == self.feed_id)\
                            .order_by(desc("date")).first()

    def next_article(self):
        """
        Returns the next article (newer).
        """
        return Article.query.filter(Article.date > self.date,
                                    Article.feed_id == self.feed_id)\
                            .order_by(asc("date")).first()

    def __repr__(self):
        return "<Article(id=%d, entry_id=%s, title=%r, " \
               "date=%r, retrieved_date=%r)>" % (self.id, self.entry_id,
                       self.title, self.date, self.retrieved_date)
コード例 #11
0
class Article(db.Model, RightMixin):
    "Represent an article from a feed."
    id = db.Column(db.Integer(), primary_key=True)
    entry_id = db.Column(db.String(), nullable=False)
    link = db.Column(db.String())
    title = db.Column(db.String())
    content = db.Column(db.String())
    readed = db.Column(db.Boolean(), default=False)
    like = db.Column(db.Boolean(), default=False)
    date = db.Column(db.DateTime(), default=datetime.utcnow)
    updated_date = db.Column(db.DateTime(), default=datetime.utcnow)
    retrieved_date = db.Column(db.DateTime(), default=datetime.utcnow)

    # foreign keys
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    feed_id = db.Column(db.Integer(), db.ForeignKey('feed.id'))
    category_id = db.Column(db.Integer(), db.ForeignKey('category.id'))

    # relationships
    tag_objs = db.relationship('ArticleTag',
                               back_populates='article',
                               cascade='all,delete-orphan',
                               lazy=False,
                               foreign_keys='[ArticleTag.article_id]')
    tags = association_proxy('tag_objs', 'text')

    # indexes
    __table_args__ = (Index('user_id'), Index('user_id', 'category_id'),
                      Index('user_id', 'feed_id'),
                      Index('ix_article_uid_fid_eid', user_id, feed_id,
                            entry_id))

    # api whitelists
    @staticmethod
    def _fields_base_write():
        return {'readed', 'like', 'feed_id', 'category_id'}

    @staticmethod
    def _fields_base_read():
        return {
            'id', 'entry_id', 'link', 'title', 'content', 'date',
            'retrieved_date', 'user_id', 'tags'
        }

    @staticmethod
    def _fields_api_write():
        return {'tags'}

    def __repr__(self):
        return "<Article(id=%d, entry_id=%s, title=%r, " \
               "date=%r, retrieved_date=%r)>" % (self.id, self.entry_id,
                       self.title, self.date, self.retrieved_date)
コード例 #12
0
    class ChangeSet(db.Model):

        __table_args__ = {'schema': schema}

        id = db.Column(db.Integer, primary_key=True)
        timestamp = db.Column(db.TIMESTAMP)
        contributor_id = db.Column(db.Integer, db.ForeignKey('user.id'))
        contributor = db.relationship('User')
        feature_id = db.Column(db.Integer,
                               db.ForeignKey(schema + '.feature.id'))
        feature = db.relationship('Feature', backref=db.backref('changes'))
        json_values = db.Column(db.Text)
        values = JsonProperty('json_values')
コード例 #13
0
class ShelterPicture(db.Model):
    """
    Represent a picture for a shelter.
    """
    id = db.Column(db.Integer, primary_key=True)
    file_name = db.Column(db.String(), default='')
    is_main_picture = db.Column(db.Boolean(), default=False)

    # relationship
    shelter_id = db.Column(db.Integer, db.ForeignKey('shelter.id'),
                            nullable=False)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'),
                            nullable=False)
コード例 #14
0
class ShelterDocument(db.Model):
    """
    Represent a document for a shelter.
    """
    id = db.Column(db.Integer, primary_key=True)
    file_name = db.Column(db.String(), default='')

    # relationship
    shelter_id = db.Column(db.Integer,
                           db.ForeignKey('shelter.id'),
                           nullable=False)
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id'),
                            nullable=False)
コード例 #15
0
ファイル: tag.py プロジェクト: sabite/newspipe
class BookmarkTag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String, unique=False)

    # foreign keys
    user_id = db.Column(db.Integer, db.ForeignKey('user.id',
                                                  ondelete='CASCADE'))
    bookmark_id = db.Column(db.Integer,
                            db.ForeignKey('bookmark.id', ondelete='CASCADE'))

    # relationships
    bookmark = db.relationship('Bookmark',
                               back_populates='tags',
                               cascade="all,delete",
                               foreign_keys=[bookmark_id])
コード例 #16
0
class Organization(db.Model):
    """Represent an organization.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    description = db.Column(db.String())
    website = db.Column(db.String())
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow())

    cve_vendor = db.Column(db.String(), default='')

    # foreign keys
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)

    # relationship
    projects = db.relationship(Project,
                               backref='organization',
                               lazy='dynamic',
                               cascade='all,delete-orphan')

    @validates('name')
    def validates_bio(self, key, value):
        assert len(value) <= 100, \
            AssertionError("maximum length for name: 100")
        return value.replace(' ', '').strip()
コード例 #17
0
ファイル: bookmark.py プロジェクト: feitianyiren/newspipe
class Bookmark(db.Model, RightMixin):
    """
    Represent a bookmark.
    """
    id = db.Column(db.Integer(), primary_key=True)
    href = db.Column(db.String(), default="")
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="")
    shared = db.Column(db.Boolean(), default=False)
    to_read = db.Column(db.Boolean(), default=False)
    time = db.Column(db.DateTime(), default=datetime.utcnow)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id'))

    # relationships
    tags = db.relationship(BookmarkTag, backref='of_bookmark', lazy='dynamic',
                               cascade='all,delete-orphan',
                               order_by=desc(BookmarkTag.text))
    tags_proxy = association_proxy('tags', 'text')


    @validates('description')
    def validates_title(self, key, value):
        return str(value).strip()

    @validates('extended')
    def validates_description(self, key, value):
        return str(value).strip()

    def __repr__(self):
        return '<Bookmark %r>' % (self.href)
コード例 #18
0
class Client(db.Model, Ext):
    name = db.Column(db.String(40))
    description = db.Column(db.String(400))
    user_id = db.Column(db.ForeignKey('user.id'))
    user = db.relationship('User')
    client_id = db.Column(db.String(40), primary_key=True)
    client_secret = db.Column(db.String(55),
                              unique=True,
                              index=True,
                              nullable=False)
    is_confidential = db.Column(db.Boolean)
    _redirect_uris = db.Column(db.Text)
    _default_scopes = db.Column(db.Text)

    @property
    def client_type(self):
        if self.is_confidential:
            return 'confidential'
        return 'public'

    @property
    def redirect_uris(self):
        if self._redirect_uris:
            return self._redirect_uris.split()
        return []

    @property
    def default_redirect_uri(self):
        return self.redirect_uris[0]

    @property
    def default_scopes(self):
        if self._default_scopes:
            return self._default_scopes.split()
        return []
コード例 #19
0
ファイル: bookmark.py プロジェクト: mdheller/newspipe
class Bookmark(db.Model, RightMixin):
    """
    Represent a bookmark.
    """

    id = db.Column(db.Integer(), primary_key=True)
    href = db.Column(db.String(), default="")
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="")
    shared = db.Column(db.Boolean(), default=False)
    to_read = db.Column(db.Boolean(), default=False)
    time = db.Column(db.DateTime(), default=datetime.utcnow)
    user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))

    # relationships
    tags = db.relationship(
        BookmarkTag,
        backref="of_bookmark",
        lazy="dynamic",
        cascade="all,delete-orphan",
        order_by=desc(BookmarkTag.text),
    )
    tags_proxy = association_proxy("tags", "text")

    @validates("description")
    def validates_title(self, key, value):
        return str(value).strip()

    @validates("extended")
    def validates_description(self, key, value):
        return str(value).strip()

    def __repr__(self):
        return "<Bookmark %r>" % (self.href)
コード例 #20
0
    class Feature(db.Model):

        __table_args__ = {'schema': schema}

        id = db.Column(db.Integer, primary_key=True)
        gid = db.Column(db.Integer)
        name = db.Column(db.String)
        label = db.Column(db.Text)
        # rendering = db.Column(db.String)
        geom = db.Column(Geometry('POINT', srid=4326))
        shape = ShapeProperty()
        version = db.Column(db.Integer,
                            db.Sequence('feature_version_seq', schema=schema))
        timestamp = db.Column(db.TIMESTAMP)
        last_contributor_id = db.Column(db.Integer, db.ForeignKey('user.id'))
        last_contributor = db.relationship('User')

        def tag(self, tag_name, value):
            tags = dict([(tag.name, tag) for tag in self.tags])
            tag = tags.get(tag_name, None)
            if tag:
                tag.value = value
            else:
                tag = Tag()
                tag.feature = self
                tag.name = tag_name
                tag.value = value
                db.session.add(tag)

        def annotate(self, annotation):
            self.tag('annotation', annotation)

        def stamp(self):
            self.version = db.engine.execute(
                "SELECT nextval('%s.feature_version_seq')" % schema).scalar()
            self.timestamp = datetime.now()
            return self

        def __repr__(self):
            return 'Feature <%d> %s' % (self.id, self.name.encode('utf-8'))

        @property
        def properties(self):
            data = dict({
                'name':
                self.name,
                'label':
                self.label,
                'version':
                self.version,
                'timestamp':
                self.timestamp.isoformat(),
                'user_id':
                self.last_contributor_id,
                'user_email':
                self.last_contributor and self.last_contributor.email or None
            })
            tags = dict([(tag.name, tag.value) for tag in self.tags])
            data['tags'] = tags
            return data
コード例 #21
0
class TagValue(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    tag_definition_id = db.Column(db.Integer,
                                  db.ForeignKey('tag_definition.id'))
    tag_definition = db.relationship('TagDefinition',
                                     backref=db.backref('values'))
    value = db.Column(db.Text)
コード例 #22
0
class UserInvitation(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    invited_by_user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    email = db.Column(db.String(255), nullable=False)
    token =  db.Column(db.String(100), nullable=False, default='')

    # invited_by_user = db.relationship('User')
コード例 #23
0
class Category(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String())

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))

    def dump(self):
        return {key: getattr(self, key) for key in ('id', 'name', 'user_id')}
コード例 #24
0
ファイル: role.py プロジェクト: samael/newspipe
class Role(db.Model):
    """
    Represent a role.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), unique=True)

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
コード例 #25
0
class BookmarkTag(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String, unique=False)

    # foreign keys
    user_id = db.Column(db.Integer, db.ForeignKey("user.id",
                                                  ondelete="CASCADE"))
    bookmark_id = db.Column(db.Integer,
                            db.ForeignKey("bookmark.id", ondelete="CASCADE"))

    # relationships
    bookmark = db.relationship(
        "Bookmark",
        back_populates="tags",
        cascade="all,delete",
        foreign_keys=[bookmark_id],
    )
コード例 #26
0
class Card(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)
    rows = db.Column(db.Integer, nullable=False)
    cols = db.Column(db.Integer, nullable=False)
    card_items = relationship('CardItem', back_populates='card')
    project = relationship('Project', back_populates='cards')

    def __repr__(self):
        return str(self)

    def __str__(self):
        return f'{self.__class__.__name__}: {self.id} ({self.rows} x {self.cols})'

    @classmethod
    def generate(cls, project_id, rows, cols):
        card = cls()
        card.project_id = project_id
        card.rows = rows
        card.cols = cols
        db.session.add(card)
        db.session.commit()

        # now generate all the items on this card
        all_items = Item.query.filter_by(project_id=project_id,
                                         free_space=False).all()
        free_spaces = Item.query.filter_by(project_id=project_id,
                                           free_space=True).all()
        items = []
        if (rows == cols) and (rows % 2 == 1) and free_spaces:
            free_space = int((rows - 1) / 2)
        else:
            free_space = False

        for i in range(0, rows * cols):
            ci = CardItem()
            ci.card_id = card.id
            ci.row = i % rows
            ci.col = floor(i / cols)
            if free_space and ci.row == ci.col and ci.row == free_space:
                selection = choice(free_spaces)
                free_spaces.remove(selection)
            else:
                selection = choice(all_items)
                all_items.remove(selection)
            ci.item_id = selection.id
            items.append(ci)
        db.session.add_all(items)
        db.session.commit()
        return card

    @classmethod
    def random(cls, project_id):
        return cls.query.filter_by(project_id=project_id).order_by(
            func.random()).limit(1).one()
コード例 #27
0
class Property(db.Model, Ext):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    key = db.Column(db.Text, nullable=False)
    value = db.Column(db.Text, nullable=False)
    contact_id = db.Column(db.Integer, db.ForeignKey('contact.id'))

    def __init__(self, key, value, contact_id):
        self.key = key
        self.value = value
        self.contact_id = contact_id
コード例 #28
0
class Shelter(db.Model):
    """
    Represent a shelter.
    """
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime(), default=datetime.now)
    updated_at = db.Column(db.DateTime(), default=datetime.now)
    is_published = db.Column(db.Boolean(), default=False)
    is_commercial = db.Column(db.Boolean(), default=False)

    # relationship
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    properties = db.relationship('Property', backref='shelter', lazy='noload',
                                cascade='all, delete-orphan',
                                order_by=desc('Property.id'))


    def get_values_of_attribute(self, attribute_id=None, attribute_name=None):
        """
        """
        if attribute_id:
            props = Property.query.filter(
                            Property.shelter_id==self.id,
                            Property.attribute_id==attribute_id)
        else:
            props = Property.query.filter(
                            Property.shelter_id==self.id,
                            Property.attribute.has(name=attribute_name))

        for property_elem in props:
            if property_elem.attribute.id == attribute_id or \
                property_elem.attribute.name == attribute_name:
                return property_elem.values
        else:
            empty_value = Value(name="")
            return [empty_value]

    def get_idvalues_of_attribute(self, attribute_id):
        return [value.id for value in self.get_values_of_attribute(attribute_id)]

    def get_property_of_attribute(self, attribute_id):
        prop = Property.query.filter(
                            Property.shelter_id==self.id,
                            Property.attribute_id==attribute_id)
        if prop:
            return prop.first()
        else:
            return 0

    def __str__(self):
        """
        Required for administrative interface.
        """
        return str(self.id)
コード例 #29
0
class CVE(db.Model):
    """Represent a CVE.
    """
    id = db.Column(db.Integer, primary_key=True)
    cve_id = db.Column(db.String(), nullable=False)
    summary = db.Column(db.String(), default='')
    published_at = db.Column(db.DateTime(), default=datetime.utcnow())

    # foreign keys
    project_id = db.Column(db.Integer(),
                           db.ForeignKey('project.id'),
                           default=None)
コード例 #30
0
class AttributePicture(db.Model):
    """
    Represent a picture for an attribute.
    """
    id = db.Column(db.Integer, primary_key=True)
    file_name = db.Column(db.String(), default='')
    language_code = db.Column(db.String(), default='')

    # relationship
    attribute_id = db.Column(db.Integer,
                             db.ForeignKey('attribute.id'),
                             nullable=False)