Esempio n. 1
0
class Subscription(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(40), unique=False, nullable=False)
    channel_key = db.Column(db.String(120), unique=False, nullable=True)
    channel_name = db.Column(db.String(120), unique=False, nullable=True)
    last_viewed = db.Column(db.TIMESTAMP, default=datetime.utcnow)
    created_date = db.Column(db.TIMESTAMP, default=datetime.utcnow)

    def __init__(self, uuid, channel_key, channel_name):
        self.uuid = uuid
        self.channel_key = channel_key
        self.channel_name = channel_name
        self.last_viewed = datetime.utcnow()
        self.created_date = datetime.utcnow()

    def dict(self):
        sub = {
            "uuid":
            self.uuid,
            "channel_key":
            self.channel_key,
            "last_viewed":
            self.last_viewed,
            "created":
            int((self.created_date -
                 datetime.utcfromtimestamp(0)).total_seconds()),
        }

        return sub
Esempio n. 2
0
class User(db.Model):
    uid = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), unique=True)
    password_hash = db.Column(db.String(144))
    timelines = db.relationship('Timeline', backref='owner', lazy='joined')

    def __init__(self, username, password):
        self.username = username
        self.password_hash = generate_password_hash(password, method='sha512')

    @classmethod
    def authenticate(cls, username, password):
        """Authenticates details of a user

        Parameters
        ----------
        username : str
            The username of the user to authenticate
        password : str
            The password to authenticate with

        Returns
        -------
        User
            The authenticated user
        """
        if any(i is None for i in (username, password)):
            return dict(error='missing fields'), 400

        user = cls.query.filter_by(username=username).first()
        if user is None or not check_password_hash(user.password_hash, password):
            return dict(error='incorrect credentials or user doesn\'t exist'), 401
        else:
            token = create_access_token(identity=user)
            return dict(username=user.username, token=token), 200
Esempio n. 3
0
class Users(db.Model, UserMixin):
	__tablename__ = 'users'

	# Primary key
	id = db.Column(db.Integer, primary_key=True)
	
	# Columns
	email = db.Column(db.String(255), unique=True)
	password = db.Column(db.String(255))
	active = db.Column(db.Boolean())
	confirmed_at = db.Column(db.DateTime())
	roles = db.relationship('Roles', secondary=roles_users, 
		backref=db.backref('users', lazy='dynamic'))

	# Representation
	def __repr__(self):
		return '<id %r>' % self.id

	# Check if a user email exists
	@classmethod
	def check_user(class_, email):
		Users = class_

		# Query for the email
		user = Users.query.filter_by(email=email).first()

		# Return true if exists
		if user:
			return user
		else:
			return False
Esempio n. 4
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(150), nullable=False)
    email = db.Column(db.String(255), unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean())
    login_count = db.Column(db.Integer)
    current_login_ip = db.Column(db.String(255))
    current_login_at = db.Column(db.DateTime, default=datetime.utcnow)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow)

    posts = db.relationship('Post', backref='author', lazy='dynamic')
    comments = db.relationship('Comment', backref='author', lazy='dynamic')
    roles = db.relationship('Role', secondary=role_users, backref=db.backref('users', lazy="dynamic"),
                            cascade="save-update, merge, delete")

    def __init__(self, email, password=None, *args, **kwargs):
        super(User, self).__init__(email=email, password=password, *args, **kwargs)

        if not self.username:
            self.username = self.email.split("@")[0]

        if not self.roles:
            user_role = Role.query.filter(Role.name == 'user').first()
            self.roles.append(user_role)

    def __repr__(self):
        return f'<User #{self.id} {self.email}>'
Esempio n. 5
0
class ProfileModel(BaseModel):
    __tablename__ = 'Profile'
    id = db.Column("id", db.Integer, primary_key=True)
    host = db.Column(db.String(200), unique=False, nullable=False)
    port = db.Column(db.String(4), unique=False, nullable=True)
    username = db.Column(db.String(200), unique=False, nullable=True)
    password = db.Column(db.String(200), unique=False, nullable=True)
    name = db.Column(db.String(200), unique=True, nullable=False)
    userId = db.Column(db.Integer, ForeignKey("Users.id"))

    def __init__(self, name, host, port, username, password):
        self.name = name
        self.host = host
        self.port = port or 22
        self.username = username
        self.password = password

    @staticmethod
    def getById(id):
        return ProfileModel.query.filter_by(id=id).first()

    @staticmethod
    def getProfilesForUser(userId):
        return ProfileModel.query.filter_by(userId=userId).all()

    def connect(self):

        return Connection(self.host,
                          username=self.username,
                          password=self.password,
                          port=int(self.port))
class MessageQueue(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    channel_name = db.Column(db.String(120), unique=False, nullable=False)
    uuid = db.Column(db.String(40), unique=False, nullable=False)
    message_id = db.Column(db.Integer, unique=False, nullable=False)
    created_date = db.Column(db.TIMESTAMP, default=datetime.utcnow)

    def __init__(self, channel_name, uuid, message_id):
        self.channel_name = channel_name
        self.uuid = uuid
        self.message_id = message_id
        self.created_date = datetime.utcnow()

    def dict(self):
        sub = {
            "channel_name":
            self.channel_name,
            "uuid":
            self.uuid,
            "created":
            int((self.created_date -
                 datetime.utcfromtimestamp(0)).total_seconds()),
        }

        return sub
class SensorTypes(db.Model):
    sensor_type_id = db.Column(db.Integer, unique=True, nullable=False, primary_key=True)
    sensor_type_value = db.Column(db.String(80), unique=False, nullable=False, primary_key=False)
    sensor_type_title = db.Column(db.String(80), unique=False, nullable=False, primary_key=False)

    def __repr__(self):
        return"<Title>: {}>".format(self.sensor_type_title)
Esempio n. 8
0
class Goal(db.Model):
    __tablename__ = 'goal'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    name = db.Column(db.String(256), nullable=False)
    cat_id = db.Column(db.Integer, default=1)
    image_url = db.Column(db.String(130))
    no_added = db.Column(db.Integer, default=1)
    no_completed = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=datetime.now())
    updated_at = db.Column(db.DateTime, default=datetime.now())
    user_goals = db.relationship('UserGoal', backref="goal", cascade="all, delete-orphan", lazy='dynamic')
    g_likes = db.relationship('GoalLike', backref=db.backref('goal', lazy='joined'), lazy='dynamic',
                               cascade="all, delete, delete-orphan")

    @property
    def serialize(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'first_name': self.user.first_name,
            'last_name': self.user.last_name,
            'name': self.name,
            'cat_id': self.cat_id,
            'image_url': self.image_url,
            'no_added': self.no_added,
            'no_completed': self.no_completed,
            'created_at': self.created_at,
            'updated_at': self.updated_at
        }
Esempio n. 9
0
class Room(db.Model):
    __tablename__ = "rooms"
    id = db.Column("room_id", db.Integer, primary_key=True)

    info = db.Column("info", db.String(), nullable=True)

    name = db.Column("name", db.String(50), nullable=False)

    seats = db.relationship('Seat',
                            back_populates="room",
                            cascade="all, delete")

    def __init__(self, name, info):
        self.name = name
        self.info = info

    def get_seat_list(self):
        seat_list = list(map(lambda x: x.to_json(), self.seats))
        sorted_seat_list = sorted(seat_list, key=lambda x: x['id'])
        return sorted_seat_list

    def to_json(self):
        return {
            "id": self.id,
            "name": self.name,
            "info": self.info,
            "seats": {
                "count": len(self.seats),
                "seats": self.get_seat_list(),
            },
        }

    def __str__(self):
        return str(self.__class__) + ":" + str(self.__dict__)
Esempio n. 10
0
class Device(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(40), unique=True, nullable=False)
    public_key = db.Column(db.String(120), unique=True, nullable=True)
    name = db.Column(db.String(120), unique=False, nullable=False)
    message_type = db.Column(db.String(120), unique=False, nullable=False)
    created_date = db.Column(db.TIMESTAMP, default=datetime.utcnow)

    def __init__(self, uuid, public_key, name, message_type):
        self.uuid = uuid
        self.public_key = public_key
        self.name = name
        self.message_type = message_type
        self.created_date = datetime.utcnow()

    def __repr__(self):
        return '<Device %r>' % self.uuid

    def dict(self):
        device = {
            "name": self.name,
            "uuid": self.uuid,
            "public_key": self.public_key,
            "message_type": self.message_type,
            "created": int((self.created_date - datetime.utcfromtimestamp(0)).total_seconds()),
        }

        return device
Esempio n. 11
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column('id', db.Integer, primary_key=True)
    first_name = db.Column('first_name', db.String(255), nullable=False)
    last_name = db.Column('last_name', db.String(255), nullable=False)
    email = db.Column('email', db.String(255), unique=True)
    password = db.Column('password', db.String(128), nullable=False)
    # Buyer - B, Buyer & Farmer - C
    type = db.Column('type', db.String(1), default='B')

    def __init__(self, first_name, last_name, email, password):
        self.first_name = first_name
        self.last_name = last_name
        self.email = email
        self.set_password(password)

    def __repr__(self):
        return self.email

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)

    def set_user_farmer(self):
        self.type = 'C'
Esempio n. 12
0
class User(db.Model):
    INSPECTOR = 'inspector'
    MANAGER = 'manager'
    ADMIN = 'admin'

    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key = True)
    username = db.Column(db.String(32), index = True)
    password = db.Column(db.String(128))
    role = db.Column(db.String(32), default= INSPECTOR)
    car = db.Column(db.String(32), default=None)
    fio = db.Column(db.String(32), default=None)

    def to_dict(self):
        return {
            'username': self.username,
            'role': self.role,
            'fio': self.fio,
            'car': self.car,
        }


    def verify_password(self, password):
        # TODO: Hash password in future
        return password == self.password

    @classmethod
    def current(cls):
        username = get_jwt_identity()
        return User.query.filter_by(username=username).first()
Esempio n. 13
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(32), index=True)
    password = db.Column(db.String(128))
    fio = db.Column(db.String(32), default=None)

    def to_dict(self):
        return {
            'username': self.username,
            'fio': self.fio,
        }

    @staticmethod
    def current():
        idx = 1
        user = User.query.get(idx)
        if user is None:
            user = User(fio='ООО "Интернет магазин"', username='******')
            db.session.add(user)
            db.session.commit()

        return user

    def verify_password(self, password):
        # TODO: Hash password in future
        return password == self.password
Esempio n. 14
0
class Files(db.Model):
    id: int
    name: str
    filename: str
    created_date: datetime

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer)
    name = db.Column(db.String(256))
    filename = db.Column(db.String(256))
    filename_norm = db.Column(db.String(256), default=None)
    status = db.Column(db.String(20))
    processed = db.Column(db.Integer, default=0)
    failed = db.Column(db.Integer, default=0)

    created_date = db.Column(db.DateTime(timezone=True),
                             server_default=func.now())
    finish_date = db.Column(db.DateTime(timezone=True), default=None)

    def as_dict(self):
        d = {}
        for c in self.__table__.columns:
            d[c.name] = getattr(self, c.name)
            if c.name == 'created_date':
                d[c.name] = d[c.name].isoformat()
        return d
Esempio n. 15
0
class Booking(db.Model):
    __tablename__ = 'mimir_bookings'
    identifier = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), unique=False, nullable=False)
    start = db.Column(db.DateTime, nullable=False, default=datetime.now)
    end = db.Column(db.DateTime, nullable=False, default=datetime.now)
    cell_colour = db.Column(db.String(255), unique=False, nullable=False)
    timetable_id = db.Column(db.Integer,
                             db.ForeignKey('mimir_timetables.identifier'))
    timetable = db.relationship('Timetable', back_populates="bookings")
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    @property
    def duration(self):
        return abs(self.end - self.start).total_seconds() / 3600

    @property
    def timetable_name(self):
        if timetable is not None:
            return timetable.name
        return "Not Set"

    @property
    def serialize(self):
        return {
            'id': self.identifier,
            'booking': self.name,
            'timetable': self.timetable.name,
            'timetable_id': self.timetable_id,
            'start_time': self.start,
            'end_time': self.end,
            'duration': self.duration,
            'cell_colour': self.cell_colour
        }
Esempio n. 16
0
class Room(db.Model):
    __tablename__ = 'heimdall_rooms'
    identifier = db.Column(db.Integer, primary_key=True)
    room_name = db.Column(db.String(255), unique=False, nullable=False)
    subnets = db.Column(db.String(255), unique=False, nullable=False)
    capacity = db.Column(db.Integer, unique=False, nullable=False, default=0)
    has_availability_map = db.Column(db.Boolean,
                                     unique=False,
                                     nullable=False,
                                     default=False)
    desks = db.relationship(
        'Desk', back_populates='room')  ## Link the Room to the desks
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now)

    def __init__(self, **kwargs):
        ## Default constructor handling by SQLAlchemy ORM
        super(Room, self).__init__(**kwargs)

        ## Custom constructor code
        self.validateSubnets()

    @property
    def serialize(self):
        return {
            'id': self.identifier,
            'name': self.room_name,
            'subnets': self.subnets,
            'capacity': self.capacity,
            'number_of_desks': len(self.desks),
            'number_of_computers': self.computer_count,
            'has_availability_map': self.has_availability_map
        }

    @property
    def computer_count(self):
        ## Check the Room has desks
        if self.desks is None:
            return 0
        ## Count the computers
        computerCount = 0
        for desk in self.desks:
            if desk.computers is not None:
                computerCount += len(desk.computers)
        return computerCount

    def validateSubnets(self):
        ## Check the subnet is a valid format
        suppliedSubnets = self.subnets.split(
            ',')  ## Split into each of the supplied subnets
        for subnet in suppliedSubnets:
            subnetSections = subnet.split('.')
            ## Check the subnet was composed of 3 sections, e.g. 192.168.0. Subnets with trailing '.' will also be marked as invalid
            if len(subnetSections) != 3:
                self.subnets = "Invalid"
            for section in subnetSections:
                ## check the subnet section is not longer than 3 characters
                if len(section) > 3:
                    self.subnets = "Invalid"
Esempio n. 17
0
class Poster(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    hex_string = db.Column(db.String(4), nullable=False)
    ip_address = db.Column(db.String(15), nullable=False)
    thread = db.Column(db.Integer,
                       db.ForeignKey("thread.id", ondelete="CASCADE"),
                       nullable=False)
    slip = db.Column(db.Integer, db.ForeignKey("slip.id"), nullable=True)
Esempio n. 18
0
class Media(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ext = db.Column(db.String(4), nullable=False)
    mimetype = db.Column(db.String(255), nullable=False)
    is_animated = db.Column(db.Boolean, nullable=False)

    def delete_attachment(self):
        storage.delete_attachment(self.id, self.ext)
Esempio n. 19
0
File: post.py Progetto: aksenol/ggkp
class Post(db.Model):
    post_id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    message = db.Column(db.String(5000))
    url = db.Column(db.String(120))
    settings = db.Column(db.SmallInteger)
    publish_date = db.Column(db.DateTime)
    publisher_id = db.Column(db.Integer, db.ForeignKey('user.user_id'))
    group_id = db.Column(db.Integer, db.ForeignKey('group.group_id'))

    seen_by = db.relationship('User', secondary=seen)
    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    #backrefs
    #publisher -> submitted by
    #group -> submitted in

    def __init__(self, post):
        self.message = post.message
        self.url = post.url
        self.settings = post.settings
        self.publisher_id = post.publisher_id
        self.group_id = post.group_id
        self.publish_date = datetime.now()

    def __repr__(self):
        return '<Post %r>' % self.post_id

    def get_hot_feed(self, group_id, page=0):  # -> post_id[]
        group = Group.query.filter(Group.group_id == group_id).first()
        return [post.post_id for post in group.posts]

    def get_trending_feed(self, group_id, page=0):  # -> post_id[]
        group = Group.query.filter(Group.group_id == group_id).first()
        return [post.post_id for post in group.posts]

    def get_new_feed(self, group_id, page=0):  # -> post_id[]
        group = Group.query.filter(Group.group_id == group_id).first()
        return [post.post_id for post in group.posts]

    def get_post(self, post_id):  # -> post
        return Post.query.filter(Post.post_id == post_id).first()

    def create_post(self, post):  # -> post_id
        temp = Post(post)
        db.session.add(temp)
        db.commit()
        return temp.post_id

    def get_front_page(self, user_id):  # -> post_id []
        user = User.query.filter(User.user_id == user_id).first()
        result = []
        for group in user.subscribed_groups:
            result.append([post.post_id for post in group.posts])
        return result
Esempio n. 20
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(32), nullable=False)
    last_name = db.Column(db.String(32))
    password_hash = db.Column(db.String(120))
    token = db.Column(db.String(130), nullable=False)
    email = db.Column(db.String(130), nullable=False, unique=True)
    contact_number = db.Column(db.String(12))
    profile_url = db.Column(db.String(130))
    about_me = db.Column(db.Text)
    city = db.Column(db.String(32))
    country = db.Column(db.String(32))
    no_goals_added = db.Column(db.Integer)
    no_goals_completed = db.Column(db.Integer)
    created_at = db.Column(db.DateTime, default=datetime.now())
    updated_at = db.Column(db.DateTime, default=datetime.now())
    user_goals = db.relationship('UserGoal', backref="user", cascade="all, delete-orphan", lazy='dynamic')
    goal = db.relationship('Goal', backref="user", cascade="all, delete-orphan", uselist=False)
    ug_likes = db.relationship('UserGoalLike', backref=db.backref('user', lazy='joined'), lazy='dynamic',
                               cascade="all, delete, delete-orphan")
    g_likes = db.relationship('GoalLike', backref=db.backref('user', lazy='joined'), lazy='dynamic',
                              cascade="all, delete, delete-orphan")

    def hash_password(self, password):
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        return pwd_context.verify(password, self.password_hash)
Esempio n. 21
0
class Post(OutputMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(4096), nullable=False)
    subject = db.Column(db.String(64), nullable=True)
    thread = db.Column(db.Integer, db.ForeignKey("thread.id"), nullable=False)
    datetime = db.Column(db.DateTime,
                         nullable=False,
                         default=_datetime.datetime.utcnow)
    poster = db.Column(db.Integer, db.ForeignKey("poster.id"), nullable=False)
    media = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=True)
    spoiler = db.Column(db.Boolean, nullable=True)
Esempio n. 22
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    password = db.Column(
        PasswordType(schemes=['pbkdf2_sha512', ])
    )
    documents = db.relationship('Document', backref="user", lazy=True)
    surveydata = db.Column(db.String(5000), nullable=True)
    current_experiment_index = db.Column(db.Integer, default=0)

    def __repr__(self):
        return '<User %r>' % self.username
Esempio n. 23
0
class Content(db.Model):
    ## The different fields of the model, these generate the table columns
    __tablename__ = 'yggdrasil_content'
    identifier = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    name = db.Column(db.String(255), unique=False, nullable=False)
    carousel_id = db.Column(db.Integer,
                            db.ForeignKey("yggdrasil_carousels.identifier"))
    carousel = db.relationship('Carousel', back_populates="content")
    content_type = db.Column(db.String(255), unique=False, nullable=False)
    content_location = db.Column(db.String(255), unique=False, nullable=False)
    slide_interval = db.Column(db.Integer, unique=False,
                               nullable=False)  # in milliseconds
    is_enabled = db.Column(db.Boolean,
                           unique=False,
                           nullable=False,
                           default=True)

    def __init__(self, **kwargs):
        ## Default constructor handling by SQLAlchemy ORM
        super(Content, self).__init__(**kwargs)

        ## Custom constructor code
        self.validateContentType()

    ## Serialise the model instance ready for jsonification
    @property
    def serialize(self):
        return {
            'id': self.identifier,
            'name': self.name,
            'carousel': self.carousel_name,
            'carousel_id': self.carousel_id,
            'type': self.content_type,
            'location': self.content_location,
            'interval': self.slide_interval,
            'is_enabled': self.is_enabled
        }

    ## Function for grabbing the name of the carousel this content item is attached to
    @property
    def carousel_name(self):
        if self.carousel is not None:
            if self.carousel.name is not None:
                return self.carousel.name
        return "Not Set"

    def validateContentType(self):
        validTypes = ['picture', 'video', 'webpage', 'heimdall', 'mimir']
        if self.content_type not in validTypes:
            self.content_type = 'invalid'
Esempio n. 24
0
class User(UserMixin, db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    full_name = db.Column(db.String(30))
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.Text, nullable=False)
    access_level = db.Column(db.Integer,
                             db.ForeignKey('access_levels.id'),
                             default=0)
    favorite_quotes = db.relationship('FavoriteQuote',
                                      backref='favorite_quotes')
    access_level_name = db.relationship('AccessLevel', backref='access_levels')
Esempio n. 25
0
class Roles(db.Model, RoleMixin):
	__tablename__ = "roles"

	# Primary key
	id = db.Column(db.Integer(), primary_key=True)

	# Columns
	name = db.Column(db.String(80), unique=True)
	description = db.Column(db.String(255))

	# Representation
	def __repr__(self):
		return '<id %r>' % self.id
Esempio n. 26
0
class TimelineNode(db.Model):
    uid = db.Column(db.Integer, primary_key=True)
    timeline_id = db.Column(db.Integer, db.ForeignKey('timeline.uid'))
    position = db.Column(db.Integer)
    title = db.Column(db.String(32))
    content = db.Column(db.Text)
    attachment = db.Column(db.String(512))

    def __init__(self, timeline, title, content, attachment):
        self.timeline = timeline
        self.title = title
        self.content = content
        self.attachment = attachment
        self.position = len(timeline.nodes)
Esempio n. 27
0
class Produce(db.Model):
    __tablename__ = 'produces'
    id = db.Column('id', db.Integer, primary_key=True)
    name = db.Column('name', db.String(255), nullable=False)
    # Vegetables, Fruits, Grains, meats, diary
    category = db.Column('category', db.String(40), nullable=False)
    description = db.Column('description', db.String(255))
    image_id = db.Column('image_id', db.Integer, db.ForeignKey("images.id"))

    def __init__(self, name, description, category, image_id):
        self.name = name
        self.description = description
        self.category = category
        self.image_id = image_id
Esempio n. 28
0
class Venue(db.Model):
    __tablename__ = 'venues'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(), nullable=False)
    city = db.Column(db.String(120))
    state = db.Column(db.String(10))
    address = db.Column(db.String(120))
    phone = db.Column(db.String(30))
    image_link = db.Column(db.String(500))
    facebook_link = db.Column(db.String(120))
    website = db.Column(db.String(120))
    seeking_talent = db.Column(db.Boolean, default=False)
    seeking_description = db.Column(db.String())
    genres = db.relationship('Genre',
                             secondary=venue_genre,
                             backref='venues',
                             lazy=True)
    shows = db.relationship('Show',
                            backref='venue',
                            cascade=['all'],
                            lazy=True)

    def __repr__(self):
        return f"<Venue id={self.id} name={self.name}>"

    def venue_to_dictionary(self):
        data = {
            "id":
            self.id,
            "name":
            self.name,
            "address":
            self.address,
            "city":
            self.city,
            "state":
            self.state,
            "phone":
            self.phone,
            "website":
            self.website,
            "facebook_link":
            self.facebook_link,
            "seeking_talent":
            self.seeking_talent,
            "seeking_description":
            self.seeking_description,
            "image_link":
            self.image_link,
            "genres":
            [g.description for g in sorted(self.genres, key=lambda a: a.id)]
        }
        return data
Esempio n. 29
0
class Category(db.Model):
    __tablename__ = 'categories'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    slug = db.Column(db.String(100), nullable=False, unique=True)

    posts = db.relationship('Post', backref='category', lazy='dynamic')

    def __init__(self, *args, **kwargs):
        super(Category, self).__init__(*args, **kwargs)
        self.slug = slugify(self.name)

    def __repr__(self):
        return f'<Category #{self.id} {self.name}>'
Esempio n. 30
0
class SuccessStory(db.Model):
    __tablename__ = "successstory"
    id = db.Column(db.Integer, primary_key=True)
    user_goal_id = db.Column(db.ForeignKey('usergoal.id'))
    story = db.Column(db.Text)
    lat = db.Column(db.Float)
    long = db.Column(db.Float)
    date_completed = db.Column(db.DateTime)
    likes = db.Column(db.Integer, default=0)
    image_url = db.Column(db.String(130))
    video_url = db.Column(db.String(130))
    created_at = db.Column(db.DateTime, default=datetime.now())
    updated_at = db.Column(db.DateTime, default=datetime.now())
    ss_likes = db.relationship('SuccessStoryLike', backref=db.backref('successstory', lazy='joined'), lazy='dynamic',
                               cascade="all, delete, delete-orphan")