class GroupRole(db.Model): __tablename__ = "group_role" id = db.Column(db.Integer, primary_key=True) group = db.Column(db.Unicode(255), nullable=False) role = db.Column(db.Unicode(255), nullable=False) def __init__(self, group, role): self.group = group self.role = role
class UserRole(db.Model): __tablename__ = "user_role" id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User') role = db.Column(db.Unicode(255), nullable=False) def __init__(self, user_id, role): self.user_id = user_id self.role = role
class Category(db.Model): __tablename__ = "category" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(255), nullable=False) slug = db.Column(db.Unicode(255), nullable=False) published = db.Column(db.Boolean, default=False, nullable=False) def __init__(self, name, slug, published): self.name = name self.slug = slug self.published = published
class Page(db.Model): __tablename__ = "page" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(255), nullable=False) slug = db.Column(db.Unicode(255), nullable=False) menu = db.Column(db.Unicode(255)) content = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql'), nullable=False) html = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql')) published = db.Column(db.Boolean, default=True, nullable=False) def __init__(self, name, slug, content, published, menu=None): self.name = name self.slug = slug self.content = content self.published = published self.menu = menu self.html = markdown(content) def update_content(self, content): self.content = content self.html = markdown(content)
class UserSession(db.Model): __tablename__ = "user_session" id = db.Column(db.String(255), primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User') login_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) expires = db.Column(db.DateTime) user_agent = db.Column(db.Unicode(512)) remote_addr = db.Column(db.Unicode(100)) roles_list = db.Column(db.Unicode(1024)) def __init__(self, session_id, user_id, expires, user_agent, remote_addr, roles): self.id = session_id self.user_id = user_id self.expires = expires self.user_agent = user_agent self.remote_addr = remote_addr self.roles_list = ','.join(roles) @property def roles(self): return set(self.roles_list.split(','))
class PageRevision(db.Model): __tablename__ = "page_revision" id = db.Column(db.Integer, primary_key=True) page_id = db.Column(db.Integer, db.ForeignKey('page.id')) page = db.relationship('Page', backref=db.backref('page', lazy='dynamic')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('page_revision_author', lazy='dynamic')) datetime = db.Column(db.DateTime, default=datetime.datetime.utcnow) name = db.Column(db.Unicode(255), nullable=False) content = db.Column(db.UnicodeText().with_variant( db.UnicodeText(length=2**1), 'mysql'), nullable=False) html = db.Column(db.UnicodeText().with_variant(db.UnicodeText(length=2**1), 'mysql')) def __init__(self, page_id, author_id, name, content): self.page_id = page_id self.author_id = author_id self.name = name self.content = content self.html = markdown(content)
class User(db.Model, UserMixin): __tablename__ = "user" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.Unicode(255), nullable=False) name = db.Column(db.Unicode(255), nullable=False) pw_hash = db.Column(db.String(255)) email = db.Column(db.Unicode(255), nullable=False) enabled = db.Column(db.Boolean, default=True, nullable=False) def __init__(self, username, name, email): self.username = username self.name = name self.email = email def set_password(self, password): self.pw_hash = django_pbkdf2_sha256.encrypt(password) def check_password(self, password): if len(password) >= app.config['MIN_PASSWORD_LENGTH']: return django_pbkdf2_sha256.verify(password, self.pw_hash) else: return False
class Order(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(255)) email = db.Column(db.Unicode(255)) phone = db.Column(db.Unicode(12)) placed_date = db.Column(db.DateTime, default=datetime.datetime.utcnow) remote_addr = db.Column(db.Unicode(50)) user_agent = db.Column(db.Unicode(255)) dj = db.Column(db.UnicodeText) thank_on_air = db.Column(db.Boolean, default=False) first_time = db.Column(db.Boolean, default=True) donor_comment = db.Column(db.UnicodeText) premiums = db.Column(db.Unicode(255)) # mail, pickup, or none address1 = db.Column(db.Unicode(255)) address2 = db.Column(db.Unicode(255)) city = db.Column(db.Unicode(255)) state = db.Column(db.Unicode(255)) zipcode = db.Column(db.Integer) amount = db.Column(db.Integer) # amount charged (in US cents) recurring = db.Column(db.Boolean, unique=False, default=False) paid_date = db.Column(db.DateTime, default=None) shipped_date = db.Column(db.DateTime, default=None) tshirtsize = db.Column(db.Unicode(255)) tshirtcolor = db.Column(db.Unicode(255)) sweatshirtsize = db.Column(db.Unicode(255)) method = db.Column(db.Unicode(255)) custid = db.Column(db.Unicode(255)) # used for Stripe recurrence comments = db.Column( db.UnicodeText) # Internal use only. Staff can modify. def __init__(self, name, email, dj, thank_on_air, first_time, amount, recurring): self.name = name self.email = email self.dj = dj self.thank_on_air = thank_on_air self.first_time = first_time self.amount = amount self.recurring = recurring def set_user_agent(self, user_agent): self.user_agent = str(user_agent)[:255] def set_premiums(self, premiums, tshirtsize, tshirtcolor, sweatshirtsize): self.premiums = premiums self.tshirtsize = tshirtsize self.tshirtcolor = tshirtcolor self.sweatshirtsize = sweatshirtsize def set_address(self, address1, address2, city, state, zipcode): self.address1 = address1 self.address2 = address2 self.city = city self.state = state self.zipcode = zipcode def set_paid(self, method, paid_date=None): self.method = method if paid_date is not None: self.paid_date = paid_date else: self.paid_date = datetime.datetime.utcnow()
class Article(db.Model): __tablename__ = "article" id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Unicode(255), nullable=False) slug = db.Column(db.Unicode(255), nullable=False, unique=True) category_id = db.Column(db.Integer, db.ForeignKey('category.id')) category = db.relationship('Category', backref=db.backref('category', lazy='dynamic')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('author', lazy='dynamic')) datetime = db.Column(db.DateTime, default=datetime.datetime.utcnow) summary = db.Column(db.UnicodeText().with_variant( db.UnicodeText(length=2**1), 'mysql')) content = db.Column(db.UnicodeText().with_variant( db.UnicodeText(length=2**1), 'mysql')) html_summary = db.Column(db.UnicodeText().with_variant( db.UnicodeText(length=2**1), 'mysql')) html_content = db.Column(db.UnicodeText().with_variant( db.UnicodeText(length=2**1), 'mysql')) published = db.Column(db.Boolean, default=False, nullable=False) front_page = db.Column(db.Boolean, default=False, nullable=False) def __init__(self, title, slug, category_id, author_id, summary, content=None, published=False): self.title = title self.slug = slug self.category_id = category_id self.author_id = author_id self.summary = summary self.content = content self.published = published def render_html(self): if self.summary is not None: self.html_summary = markdown(self.summary) if app.config['SANITIZE_SUMMARY'] is True: self.html_summary = bleach.clean( self.html_summary, tags=SUMMARY_ALLOWED_TAGS, attributes=SUMMARY_ALLOWED_ATTRIBUTES, styles=SUMMARY_ALLOWED_STYLES, strip=True) if self.content is not None: self.html_content = markdown(self.content)