class EventManager(PkModel): __tablename__ = "event_managers" user_id = Column(db.Integer, db.ForeignKey('users.id', ondelete="CASCADE"), nullable=True, default=None) event_id = Column(db.Integer, db.ForeignKey('events.id', ondelete="CASCADE"), nullable=True, default=None) user = db.relationship("User", backref=db.backref("managements")) event = db.relationship("Event", backref=db.backref("managers"))
class Programme(PkModel): __tablename__ = "event_programmes" event_id = Column(db.Integer, db.ForeignKey('events.id', ondelete="CASCADE"), nullable=True, default=None) name = Column(db.String(80), nullable=False) description = Column(db.String(256), nullable=False) start_time = Column(db.DateTime, server_default=db.text('current_timestamp'), default=db.func.now(), nullable=False) end_time = Column(db.DateTime, server_default=db.text('current_timestamp'), default=db.func.now(), nullable=False) programme_type = Column(db.String(80), nullable=False) job_id = Column(db.String(100), nullable=True) event = db.relationship("Event", backref=db.backref("programmes", lazy="dynamic")) @property def videos(self): return self.files.filter_by(file_type='video').order_by( ProgrammeFile.view_order).all() @property def banners(self): return self.files.filter_by(file_type='banner').order_by( ProgrammeFile.view_order).all()
class Role(PkModel): """A role for a user.""" __tablename__ = "roles" name = Column(db.String(80), unique=True, nullable=False) user_id = reference_col("users", nullable=True) user = relationship("User", backref="roles") def __init__(self, name, **kwargs): """Create instance.""" super().__init__(name=name, **kwargs) def __repr__(self): """Represent instance as a unique string.""" return f"<Role({self.name})>"
class User(UserMixin, PkModel): """A user of the app.""" __tablename__ = "users" username = Column(db.String(80), unique=True, nullable=False) email = Column(db.String(80), unique=True, nullable=False) #: The hashed password password = Column(db.LargeBinary(128), nullable=True) created_at = Column(db.DateTime, nullable=False, default=dt.datetime.utcnow) first_name = Column(db.String(30), nullable=True) last_name = Column(db.String(30), nullable=True) active = Column(db.Boolean(), default=False) is_admin = Column(db.Boolean(), default=False) def __init__(self, username, email, password=None, **kwargs): """Create instance.""" super().__init__(username=username, email=email, **kwargs) if password: self.set_password(password) else: self.password = None def set_password(self, password): """Set password.""" self.password = bcrypt.generate_password_hash(password) def check_password(self, value): """Check password.""" return bcrypt.check_password_hash(self.password, value) @property def full_name(self): """Full user name.""" return f"{self.first_name} {self.last_name}" def __repr__(self): """Represent instance as a unique string.""" return f"<User({self.username!r})>"
class Event(PkModel): __tablename__ = "events" name = Column(db.String(80), nullable=False) description = Column(db.String(256), nullable=False) slug = Column(db.String(256), nullable=False, unique=True) start_time = Column(db.DateTime, server_default=db.text('current_timestamp'), default=db.func.now(), nullable=False) end_time = Column(db.DateTime, server_default=db.text('current_timestamp'), default=db.func.now(), nullable=True) user_id = Column(db.Integer, db.ForeignKey('users.id', ondelete="CASCADE"), nullable=True, default=None) user = db.relationship("User", backref=db.backref("events", lazy='dynamic'))
class ProgrammeFile(PkModel): __tablename__ = "programme_files" programme_id = Column(db.Integer, db.ForeignKey('event_programmes.id', ondelete="CASCADE"), nullable=True, default=None) file_type = Column(db.String(80), nullable=False) file_status = Column(db.String(80), nullable=False, default='in queue', server_default=db.text('in queue')) file_details = Column(db.Text, nullable=True) file_name = Column(db.String(256), nullable=False) view_order = Column(db.Integer, default=0, server_default=db.text('0')) programme = db.relationship("Programme", backref=db.backref("files", lazy='dynamic')) @property def file_url(self): return os.path.join( 'programmes', str(self.programme_id), 'images' if self.file_type == 'banner' else 'videos', self.file_name) @property def file_path(self): from libs.sweet_apps import get_sweet_app from flask import current_app eventy_app = get_sweet_app('Eventy') return os.path.join(eventy_app.app_path, current_app.config['EVENTY_UPLOADS_DIR'], self.file_url) @property def video_duration(self): import json try: return float(json.loads(self.file_details)['format']['duration']) except: return None
class Setting(PkModel): __tablename__ = "settings" name = Column(db.String(80), nullable=False) display_name = Column(db.String(80), nullable=False) value = Column(db.String(512), nullable=True)
class Seo(PkModel): __tablename__ = "seo" meta_tag = Column(db.String(80), nullable=False) title = Column(db.String(80), nullable=False) content = Column(db.String(256), nullable=False)