class Tag(db.Model): """ A post tag. """ __tablename__ = 'articles_tag' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) def __init__(self, tagname=None): self.name = tagname def __unicode__(self): return self.name
class Category(db.Model): """ A Category for a Post """ __tablename__ = 'articles_category' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(120)) slug = db.Column(db.String) def __init__(self, title=None, slug=None): self.title = title self.slug = slug def __unicode__(self): return self.title
class Post(db.Model): """ A Post or article with a category, tags, and an author. Stored content is github flavored markdown'd. """ __tablename__ = 'articles_posts' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(60)) gfm_content = db.Column(db.String) created = db.Column(db.DateTime, default=datetime.utcnow()) tags = db.relationship('Tag', secondary=tags, primaryjoin=(id == tags.c.post_id), secondaryjoin=(Tag.id == tags.c.tag_id), backref=db.backref('tags', lazy='dynamic')) slug = db.Column(db.String) category_id = db.Column(db.Integer, db.ForeignKey('articles_category.id')) category = db.relationship('Category', primaryjoin=(category_id == Category.id), backref=db.backref('cats', lazy='dynamic'), order_by=Category.slug) author_id = db.Column(db.Integer, db.ForeignKey('users_user.id')) author = db.relationship('User', primaryjoin=(author_id == User.id), backref=db.backref('posters', lazy='dynamic'), order_by=User.name) def __init__(self, title=None, gfm_content=None, created=None, tags=None, slug=None, category=None, author=None): title = title gfm_content = gfm_content created = datetime.now() tags = tags slug = slug category = category author = author def __unicode__(self): return self.slug
class User(db.Model): """ Defines the User object. """ __tablename__ = 'users_user' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) netid = db.Column(db.String(30), unique=True) email = db.Column(db.String(120), unique=True) role = db.Column(db.SmallInteger, default=USER.USER) member = db.Column(db.Boolean, default=False) member_since = db.Column(db.DateTime) membership_status = db.Column(db.SmallInteger, default=USER.UNREGISTERED) membership_paid_on = db.Column(db.DateTime) description = db.Column(db.Text) standing = db.Column(db.String(15)) major = db.Column(db.String(50)) shirt_size = db.Column(db.String(5)) wepay_verification = db.Column(db.String(255)) wepay_checkout_id = db.Column(db.Integer) signature = db.Column(db.LargeBinary) def __init__(self, name=None, netid=None, email=None, standing=None, major=None, shirt_size=None, description=None, signature=None): self.name = name self.email = email self.netid = netid self.standing = standing self.major = major self.shirt_size = shirt_size self.description = description self.member_since = datetime.now() self.membership_status = USER.IN_PROGRESS self.signature = signature def getRole(self): """ Get this user's role as a string. """ return USER.ROLE[self.role] def getMemberStatus(self): """ Get this user's membership status as a string. """ return USER.MEMBER_STATUS[self.membership_status] def __repr__(self): """ Represent User as Name (email) """ return '%s (%s)' % (self.name, self.email) def __unicode__(self): """ Only full name for unicode representation """ return self.name def isAdmin(self): """ True if User is an administrator """ return self.role == USER.ADMIN def isPublisher(self): """ True if User is at least a publisher """ return self.role <= USER.PUBLISHER
""" __tablename__ = 'articles_category' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(120)) slug = db.Column(db.String) def __init__(self, title=None, slug=None): self.title = title self.slug = slug def __unicode__(self): return self.title # M2M Relationship between tags and posts tags = db.Table('tags', db.Column('tag_id', db.Integer, db.ForeignKey('articles_tag.id')), db.Column('post_id', db.Integer, db.ForeignKey('articles_posts.id')) ) class Tag(db.Model): """ A post tag. """ __tablename__ = 'articles_tag' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) def __init__(self, tagname=None): self.name = tagname def __unicode__(self):