Ejemplo n.º 1
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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
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,
        }
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)

    username = db.Column(db.String(50), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False, server_default='')
    reset_password_token = db.Column(db.String(100),
                                     nullable=False,
                                     server_default='')

    email = db.Column(db.String(255), nullable=False, unique=True)
    confirmed_at = db.Column(db.DateTime())

    active = db.Column('is_active',
                       db.Boolean(),
                       nullable=False,
                       server_default='0')
    first_name = db.Column(db.String(100), nullable=False, server_default='')
    last_name = db.Column(db.String(100), nullable=False, server_default='')

    # edugain /cyclone toggle
    logged_in_edugain = db.Column('is_edugain',
                                  db.Boolean(),
                                  nullable=False,
                                  server_default='0')

    # children of a user
    contacts = db.relationship('Contact',
                               backref='user',
                               cascade='all, delete-orphan',
                               lazy='joined')
    attributes = db.relationship('Attribute',
                                 backref='user',
                                 cascade='all, delete-orphan',
                                 lazy='joined')
    container = db.relationship('Container',
                                backref='user',
                                cascade='all, delete-orphan',
                                lazy='joined')
    fitfiles = db.relationship('FitFile',
                               backref='user',
                               cascade='all, delete-orphan',
                               lazy='joined')
    page_default = {
        'name': 'My Dashboard',
        'slug': 'my-dashboard',
        'widgets': list()
    }
    pages = db.Column(db.Text,
                      nullable=True,
                      server_default=json.dumps([page_default]))

    # access token to authenticate against kex exchange service
    kex_access_token = db.Column(db.Text, nullable=False, server_default='')
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
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')
Ejemplo n.º 7
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()
Ejemplo n.º 8
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 []
Ejemplo n.º 9
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
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
class TagDefinition(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    description = db.Column(db.Text)
    implementing_features = db.relationship('FeatureType',
                                            secondary=FeatureTypeTags,
                                            back_populates='tags')
Ejemplo n.º 15
0
class User(db.Model, UserMixin):
    """
    Represent a user.
    """
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(), unique=True)
    email = db.Column(db.String(254), index=True, unique=True)
    pwdhash = db.Column(db.String())
    roles = db.relationship('Role', backref='user', lazy='dynamic')
    activation_key = db.Column(db.String(128), default=hashlib.sha512(
            str(random.getrandbits(256)).encode("utf-8")).hexdigest()[:86])
    date_created = db.Column(db.DateTime(), default=datetime.now)
    last_seen = db.Column(db.DateTime(), default=datetime.now)
    feeds = db.relationship('Feed', backref='subscriber', lazy='dynamic',
                            cascade='all,delete-orphan')
    refresh_rate = db.Column(db.Integer, default=60)  # in minutes

    @staticmethod
    def make_valid_nickname(nickname):
        return re.sub('[^a-zA-Z0-9_\.]', '', nickname)

    def get_id(self):
        """
        Return the id of the user.
        """
        return self.id

    def check_password(self, password):
        """
        Check the password of the user.
        """
        return check_password_hash(self.pwdhash, password)

    def is_admin(self):
        """
        Return True if the user has administrator rights.
        """
        return "admin" in [role.name for role in self.roles]

    def __eq__(self, other):
        return self.id == other.id

    def __repr__(self):
        return '<User %r>' % (self.nickname)
Ejemplo n.º 16
0
class FeatureType(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    # schema = db.Column(db.String, length=32)
    description = db.Column(db.Text)
    table = db.Column(db.String)
    tags = db.relationship('TagDefinition',
                           secondary=FeatureTypeTags,
                           back_populates="implementing_features")
Ejemplo n.º 17
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)
Ejemplo n.º 18
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()
        }
Ejemplo n.º 19
0
class Category(db.Model, RightMixin):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String())

    # relationships
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    feeds = db.relationship('Feed', cascade='all,delete-orphan')
    articles = db.relationship('Article', cascade='all,delete-orphan')

    # index
    idx_category_uid = Index('user_id')

    # api whitelists
    @staticmethod
    def _fields_base_read():
        return {'id', 'user_id'}

    @staticmethod
    def _fields_base_write():
        return {'name'}
Ejemplo n.º 20
0
class User(db.Model, UserMixin):
    """
    Represent a user.
    """
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(), unique=True, nullable=False)
    name = db.Column(db.String(), default='')
    pwdhash = db.Column(db.String(), nullable=False)
    created_at = db.Column(db.DateTime(), default=datetime.now)
    last_seen = db.Column(db.DateTime(), default=datetime.now)
    is_admin = db.Column(db.Boolean(), default=False)
    is_active = db.Column(db.Boolean(), default=False)
    preferred_language = db.Column(db.String(), default='en')

    # relationships
    shelters = db.relationship('Shelter', backref='responsible', lazy='dynamic',
                           cascade='all, delete-orphan',
                           order_by=desc('Shelter.id'))

    @staticmethod
    def make_valid_name(name):
        return re.sub('[^a-zA-Z0-9_\.]', '', name)

    def get_id(self):
        """
        Return the id of the user.
        """
        return self.id

    def set_password(self, password):
        """
        Hash the password of the user.
        """
        self.pwdhash = generate_password_hash(password)

    def check_password(self, password):
        """
        Check the password of the user.
        """
        return check_password_hash(self.pwdhash, password)

    # def __eq__(self, other):
    #     return self.id == other.id

    def __str__(self):
        """
        Required for administrative interface.
        """
        return self.name

    def __repr__(self):
        return '<User %r>' % (self.name)
class Container(db.Model, Ext):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.Text, nullable=False)  # name of the container
    path = db.Column(db.Text, nullable=False)  # path to the container file
    type = db.Column(
        db.Integer,
        nullable=False)  # used by the policy enforcement strategies
    files = db.relationship('File',
                            backref='container',
                            cascade='all, delete-orphan',
                            lazy='joined')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __init__(self, name, path, type, user_id):
        self.name = name
        self.path = path
        self.type = type
        self.user_id = user_id

    # reencrypts a container considering the new attributes sets of contacts
    # called whenever a contact is modified
    def reencrypt(self, user):
        container = Container(self.name, self.path, self.type, user.id)
        container.files = self.files
        for f in container.files:
            f.policy = Policy.generate(f.policy_text, user)
            db.session.add(f)
        db.session.delete(self)
        db.session.add(container)
        db.session.commit()

        out = container.dict()
        out['files'] = list()
        for f in container.files:
            out['files'].append(f.dict())

        aa_param = dict()
        aa_param['files'] = list()
        for f in out['files']:
            aa_param['files'].append({
                "path": f['path'],
                "type": f['type'],
                "policy": f['policy']
            })
        aa_param['outfile'] = container.path
        aa_param['overwriteOutfile'] = True

        aa_response = AttrAuth.encrypt_container(container, aa_param)
        if aa_response is None:
            return None

        return True
Ejemplo n.º 22
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)
Ejemplo n.º 23
0
class Attribute(db.Model):
    """
    Represent an attribute.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), nullable=False)
    uniqueid = db.Column(db.String(), nullable=False)
    multiple = db.Column(db.Boolean(), default=True)
    free_text = db.Column(db.Boolean(), default=False)
    is_editable = db.Column(db.Boolean(), default=True)
    is_mandatory = db.Column(db.Boolean(), default=False)
    user_can_add_values = db.Column(db.Boolean(), default=False)
    type = db.Column(db.String(), default='')
    display_position = db.Column(db.Integer, default=0)

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

    associated_values = db.relationship('Value',
                                        backref='attribute',
                                        lazy='dynamic',
                                        cascade='all, delete-orphan',
                                        order_by=asc(Value.name))

    properties = db.relationship("Property", back_populates="attribute")

    pictures = db.relationship('AttributePicture',
                               backref='attribute',
                               lazy='dynamic',
                               cascade='all, delete-orphan')

    def __str__(self):
        """
        Required for administrative interface.
        """
        return self.name
Ejemplo n.º 24
0
class FeedSet(db.Model):
    """Represents a set of feeds.
    """
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(), default="")
    description = db.Column(db.String(), default="")
    date_created = db.Column(db.DateTime(), default=datetime.utcnow())
    ui_position = db.Column(db.Integer(), default=0)

    # relationships
    feeds = db.relationship(Feed,
                            backref='set',
                            cascade='all, delete-orphan',
                            foreign_keys=[Feed.set_id])
Ejemplo n.º 25
0
    class Tag(db.Model):

        __table_args__ = {'schema': schema}

        id = db.Column(db.Integer, primary_key=True)
        name = db.Column(db.String)
        value = db.Column(db.Text)
        feature_id = db.Column(db.Integer,
                               db.ForeignKey(schema + '.feature.id'))
        feature = db.relationship('Feature', backref=db.backref('tags'))

        def __repr__(self):
            return u"Tag <%s:%s>" % (self.name.encode('utf-8'),
                                     self.value.encode('utf-8'))
Ejemplo n.º 26
0
class Campaign(db.Model):

    # QeBWZ8BZBozoT8y
    id = db.Column(db.String(length=8), primary_key=True)
    title = db.Column(db.String(length=100))
    description = db.Column(db.Text)
    schema = db.Column(db.String(length=32))
    # feature_type_id = db.Column(db.Integer, db.ForeignKey('feature_type.id'))
    # feature_type = db.relationship('FeatureType')
    admin_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    admin = db.relationship('User')
    admin_token = db.Column(db.String(length=16))
    created_at = db.Column(db.Date)
    closing_at = db.Column(db.Date)
    closed = db.Column(db.Boolean)
Ejemplo n.º 27
0
class Grant(db.Model, Ext):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id',
                                                  ondelete='CASCADE'))
    user = db.relationship('User')
    client_id = db.Column(db.String(40),
                          db.ForeignKey('client.client_id'),
                          nullable=False)
    client = db.relationship('Client')
    code = db.Column(db.String(255), index=True, nullable=False)
    redirect_uri = db.Column(db.String(255))
    expires = db.Column(db.DateTime)
    _scopes = db.Column(db.Text)

    def delete(self):
        db.session.delete(self)
        db.session.commit()
        return self

    @property
    def scopes(self):
        if self._scopes:
            return self._scopes.split()
        return []
Ejemplo n.º 28
0
class Token(db.Model, Ext):
    id = db.Column(db.Integer, primary_key=True)
    client_id = db.Column(db.String(40),
                          db.ForeignKey('client.client_id'),
                          nullable=False)
    client = db.relationship('Client')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User')
    token_type = db.Column(db.String(40))
    access_token = db.Column(db.String(255), unique=True)
    refresh_token = db.Column(db.String(255), unique=True)
    expires = db.Column(db.DateTime)
    _scopes = db.Column(db.Text)

    def delete(self):
        db.session.delete(self)
        db.session.commit()
        return self

    @property
    def scopes(self):
        if self._scopes:
            return self._scopes.split()
        return []
class Contact(db.Model, Ext):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.Text, nullable=False)
    email = db.Column(db.Text, nullable=False, unique=True)
    secret_key = db.Column(
        db.BLOB, nullable=True
    )  # currently not used to cache the secret key of a contact
    identity = db.Column(db.Text, nullable=False,
                         unique=True)  # unique identity attribute
    # children of a contact
    properties = db.relationship('Property',
                                 backref='owner',
                                 cascade='all, delete-orphan',
                                 lazy='joined')
    attributes = db.relationship('Attribute',
                                 secondary=contacts_attributes,
                                 backref=db.backref('owner', lazy='joined'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __init__(self, name, email, user_id):
        self.name = name
        self.email = email
        self.identity = 'AAAAA' + str(uuid.uuid4()).replace('-', '')
        self.user_id = user_id
Ejemplo n.º 30
0
class ArticleTag(db.Model):
    text = db.Column(db.String, primary_key=True, unique=False)

    # foreign keys
    article_id = db.Column(db.Integer,
                           db.ForeignKey("article.id", ondelete="CASCADE"),
                           primary_key=True)

    # relationships
    article = db.relationship("Article",
                              back_populates="tag_objs",
                              foreign_keys=[article_id])

    def __init__(self, text):
        self.text = text