Example #1
0
class Tags(Model):
    __tablename__ = 'tags'

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

    def __init__(self, tagname):
        db.Model.__init__(self, tagname=tagname)

    def __repr__(self):
        return self.tagname
Example #2
0
class Field(SurrogatePK, Model):

    __tablename__ = 'field'

    # id is needed for primary join, it does work with SurrogatePK class
    id = db.Column(db.Integer, primary_key=True)
    label = Column(db.String(100))
    type = Column(db.String(50))
    space_id = reference_col('space', nullable=True)
    space = relationship('Space', back_populates='fields')
    author_id = reference_col('userprofile', nullable=False)
    author = relationship("UserProfile", backref="fields")

    # https://docs.sqlalchemy.org/en/latest/_modules/examples/adjacency_list/adjacency_list.html
    parent_id = reference_col('field', nullable=True)
    children = relationship(
        "Field",
        # cascade deletions
        cascade="all, delete-orphan",
        # many to one + adjacency list - remote_side
        # is required to reference the 'remote'
        # column in the join condition.
        backref=db.backref("parent", remote_side=id),
        # children will be represented as a dictionary
        # on the "id" attribute.
        # collection_class=attribute_mapped_collection("id"),
    )

    # https://docs.sqlalchemy.org/en/latest/orm/inheritance.html#joined-table-inheritance
    # https://docs.sqlalchemy.org/en/13/_modules/examples/inheritance/joined.html
    __mapper_args__ = {
        "polymorphic_identity": "field",
        "polymorphic_on": type,
    }
Example #3
0
class UserProfile(Model, SurrogatePK):
    __tablename__ = 'userprofile'

    # id is needed for primary join, it does work with SurrogatePK class
    id = db.Column(db.Integer, primary_key=True)

    user_id = reference_col('users', nullable=False, unique=True)
    user = relationship('User', backref=db.backref('profile', uselist=False))
    follows = relationship('UserProfile',
                           secondary=followers_assoc,
                           primaryjoin=id == followers_assoc.c.follower,
                           secondaryjoin=id == followers_assoc.c.followed_by,
                           backref='followed_by',
                           lazy='dynamic')

    def __init__(self, user, **kwargs):
        db.Model.__init__(self, user=user, **kwargs)

    def is_following(self, profile):
        return bool(
            self.follows.filter(
                followers_assoc.c.followed_by == profile.id).count())

    def follow(self, profile):
        if self is not profile and not self.is_following(profile):
            self.follows.append(profile)
            return True
        return False

    def unfollow(self, profile):
        if self is not profile and self.is_following(profile):
            self.follows.remove(profile)
            return True
        return False

    @property
    def following(self):
        if current_user:
            return current_user.profile.is_following(self)
        return False

    @property
    def username(self):
        return self.user.username

    @property
    def bio(self):
        return self.user.bio

    @property
    def image(self):
        return self.user.image

    @property
    def email(self):
        return self.user.email
Example #4
0
class Position(Field):

    __tablename__ = 'position'
    id = db.Column(db.ForeignKey("field.id"), primary_key=True)
    x = Column(db.Numeric(), default=0)
    y = Column(db.Numeric(), default=0)
    z = Column(db.Numeric(), default=0)
    w = Column(db.Numeric(), default=1)

    __mapper_args__ = {"polymorphic_identity": "position"}
Example #5
0
from flask_jwt_extended import current_user

from remixvr.database import (Model, SurrogatePK, db, reference_col,
                              relationship)

followers_assoc = db.Table(
    "followers_assoc",
    db.Column("follower", db.Integer, db.ForeignKey("userprofile.user_id")),
    db.Column("followed_by", db.Integer, db.ForeignKey("userprofile.user_id")))


class UserProfile(Model, SurrogatePK):
    __tablename__ = 'userprofile'

    # id is needed for primary join, it does work with SurrogatePK class
    id = db.Column(db.Integer, primary_key=True)

    user_id = reference_col('users', nullable=False, unique=True)
    user = relationship('User', backref=db.backref('profile', uselist=False))
    follows = relationship('UserProfile',
                           secondary=followers_assoc,
                           primaryjoin=id == followers_assoc.c.follower,
                           secondaryjoin=id == followers_assoc.c.followed_by,
                           backref='followed_by',
                           lazy='dynamic')

    def __init__(self, user, **kwargs):
        db.Model.__init__(self, user=user, **kwargs)

    def is_following(self, profile):
        return bool(
Example #6
0
"""Project models."""

import datetime as dt
import uuid

from flask_jwt_extended import current_user
from slugify import slugify

from remixvr.database import (Model, SurrogatePK, relationship, reference_col,
                              Column, db)

from remixvr.profile.models import UserProfile

favoriter_assoc = db.Table(
    "favoritor_assoc",
    db.Column("favoriter", db.Integer, db.ForeignKey("userprofile.id")),
    db.Column("favorited_project", db.Integer, db.ForeignKey("project.id")))

tag_assoc = db.Table(
    "tag_assoc", db.Column("tag", db.Integer, db.ForeignKey("tags.id")),
    db.Column("project", db.Integer, db.ForeignKey("project.id")))


class Tags(Model):
    __tablename__ = 'tags'

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

    def __init__(self, tagname):
        db.Model.__init__(self, tagname=tagname)