Example #1
0
class Show(db.Model):
    __tablename__ = 'show'

    id = db.Column(db.Integer, primary_key=True)
    start_time = db.Column(db.DateTime, nullable=False)
    venue_id = db.Column(db.Integer, nullable=False)
    artist_id = db.Column(db.Integer, nullable=False)
    venue = db.relationship('Venue',
                            secondary=venue_show,
                            backref=db.backref('show', lazy=True))
    artist = db.relationship('Artist',
                             secondary=artist_show,
                             backref=db.backref('show', lazy=True))

    def __repr__(self):
        return f'<Show {self.id} (Artist {self.artist_id} at Venue {self.venue_id})>'
class User(db.Model):
    __tablename__ = 'user'

    id = db.Column(db.Integer, primary_key=True)
    email_hash = db.Column(db.String(80), unique=True)

    mal_user = db.relationship("MalUser", uselist=False, back_populates="user",
                               cascade="all, delete-orphan")
    """:type: models.mal.MalUser"""

    def __init__(self, email):
        # TODO: Make hashing stronger
        self.email_hash = hashlib.sha256(email).hexdigest()

    def __repr__(self):
        return '<User %r>' % self.id
Example #3
0
class AuthPrincipal(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    role_id = db.Column(db.Integer)
    operation_principal = db.Column(db.String(2048))
    resource_principal = db.Column(db.String(2048))
    role_principal = db.Column(db.String(2048))
    principal_status = db.Column(db.Integer, default=0)
Example #4
0
class Artist(db.Model):
    __tablename__ = 'artist'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(), nullable=False)
    city = db.Column(db.String(120), nullable=False)
    state = db.Column(db.String(120), nullable=False)
    phone = db.Column(db.String(120), nullable=False)
    genres = db.Column(db.String(120), nullable=False)
    image_link = db.Column(db.String(500), nullable=False)
    website = db.Column(db.String(), nullable=True)
    facebook_link = db.Column(db.String(120), nullable=True)
    seeking_venue = db.Column(db.Boolean, nullable=False, default=True)
    seeking_description = db.Column(db.String(), nullable=True)

    def __repr__(self):
        return f'<Artist {self.id} ({self.name})>'
Example #5
0
from commons import app, db, migrate

#----------------------------------------------------------------------------#
# Models.
#----------------------------------------------------------------------------#

# Show - Artist: Many to many
artist_show = db.Table(
    'artist_show',
    db.Column('artist_id',
              db.Integer,
              db.ForeignKey('artist.id'),
              primary_key=True),
    db.Column('show_id',
              db.Integer,
              db.ForeignKey('show.id'),
              primary_key=True))
# Show - Venue: Many to many
venue_show = db.Table(
    'venue_show',
    db.Column('venue_id',
              db.Integer,
              db.ForeignKey('venue.id'),
              primary_key=True),
    db.Column('show_id',
              db.Integer,
              db.ForeignKey('show.id'),
              primary_key=True))


class Venue(db.Model):
Example #6
0
class Event(db.Model):
    """Calendar Event and methods."""
    __tablename__ = "event"
    id = db.Column(db.Integer, primary_key=True)
    start_time = db.Column(db.DateTime)
    end_time = db.Column(db.DateTime)
    location = db.Column(db.String(300))
    description = db.Column(db.String(5000), nullable=False)
    title = db.Column(db.String(300))
    sync = db.Column(db.Boolean, default='false')

    def __init__(self):
        self.start_time = datetime.datetime.utcnow()
        self.sync = False

    @classmethod
    def get_by_id(cls, id):
        """Get Event if Present"""
        oEvent = cls.query.get(id)
        if oEvent:
            return oEvent, None
        return None, "Event not Present"

    @classmethod
    def create(cls, data):
        """Creating Event."""
        oEvent = cls()
        oEvent.start_time = data["start_time"]
        oEvent.end_time = data["end_time"]
        oEvent.location = data["location"]
        oEvent.description = data["description"]
        oEvent.title = data["title"]
        if "sync" in data:
            oEvent.sync = data["sync"]
        db.session.add(oEvent)
        db.session.commit()
        return oEvent

    def delete(self):
        """Delete Event."""
        db.session.delete(self)
        db.session.commit()

    def update(self, data):
        """Updating Event."""
        self.start_time = data["start_time"].replace(tzinfo=None)
        self.end_time = data["end_time"].replace(tzinfo=None)
        self.location = data["location"]
        self.description = data["description"]
        self.title = data["title"]
        self.sync = data['sync']
        db.session.commit()
        return self

    @classmethod
    def get_list(cls, start_time, end_time):
        """
        Return list of all calendar event in a peroid.

        @param start_time
        @param end_time
        """
        return cls.query.filter(cls.start_time > start_time)\
                .filter(cls.end_time < end_time).all()

    def as_dict(self):
        """Convert Event as dict."""
        return {
            "start_time": self.start_time,
            "end_time": self.end_time,
            "location": self.location,
            "description": self.description,
            "id": self.id,
            "start": self.start_time,
            "end": self.end_time,
            "title": self.title,
            "sync": self.sync
        }

    @classmethod
    def get_events(cls, time_range):
        """
        Get all event between time_range.

        @param time_range keys present start_time, end_time.
        """
        now = datetime.datetime.utcnow()
        month = now.month + 1
        if month == 13:
            month = 1
        start_time = time_range.get('start_time',
                                    datetime.datetime(now.year, now.month, 1))
        end_time = time_range.get('end_time',
                                  datetime.datetime(now.year, month, 1))
        print start_time, end_time
        lEvent = cls.get_list(start_time, end_time)
        return [oEvent.as_dict() for oEvent in lEvent]
Example #7
0
class AuthRole(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    role_type = db.Column(db.Integer) 
    role_name = db.Column(db.String(256)) 
    parent_id = db.Column(db.Integer) 
Example #8
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    password = db.Column(db.String(256))
    role = db.Column(db.String(64), default='normal')