class Bucket(db.Model): __tablename__ = "bucket" id = db.Column(db.BigInteger, primary_key=True, autoincrement=True) user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), index=True) user = db.relationship("User", ) name = db.Column(db.Text, nullable=False) slug = db.Column(db.Text, nullable=False, index=True) created_at = db.Column(db.DateTime) follower_count = db.Column(db.Integer) projects = db.Column(postgresql.ARRAY(db.String)) def jsonable(self): return { 'id': unicode(self.id), 'name': unicode(self.name), 'slug': unicode(self.slug), 'created_at': unicode(format_date(self.created_at)), 'projects': unicode(self.projects), 'follower_count': unicode(self.follower_count) } def __repr__(self): return str(self.jsonable()) def __str__(self): return str(self.name)
class Tutorial(db.Model): __tablename__ = "tutorial" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), index=True) user = db.relationship("User", ) title = db.Column(db.Text, nullable=False) slug = db.Column(db.Text, nullable=False, index=True) keywords = db.Column(db.Text, nullable=False) meta_description = db.Column(db.Text, nullable=False) content = db.Column(db.Text, nullable=False) content_html = db.Column(db.Text, nullable=False) created_at = db.Column(db.DateTime) generated_at = db.Column(db.DateTime) publish = db.Column(db.Boolean, default=True) spam = db.Column(db.Boolean, default=False) upvote_count = db.Column(db.Integer, default=1) @staticmethod def to_dict(obj): assert isinstance(obj, Tutorial) return { 'id': unicode(obj.id), 'title': unicode(obj.name), 'slug': unicode(obj.slug), 'created_at': unicode(format_date(obj.created_at)), 'generated_at': unicode(format_date(obj.generated_at)), 'keywords': unicode(obj.keywords), 'content': unicode(obj.content), 'content_html': unicode(obj.content_html), 'meta_description': unicode(obj.meta_description), 'upvote_count': obj.upvote_count or 0, 'spam': obj.spam } def __repr__(self): return str(Tutorial.to_dict(self)) def __str__(self): return str(self.name)
class Message(db.Model): __tablename__ = "message" id = db.Column(BigInteger, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship(User) user_nick = db.Column(db.String) reply_to_id = db.Column(db.String) reply_to_uid = db.Column(db.String) reply_to_uname = db.Column(db.String) ext_id = db.Column(String) ext_reply_id = db.Column(String()) slug = db.Column(Text) content = db.Column(Text) content_html = db.Column(Text) lang = db.Column(String(length=3)) mentions = db.Column(postgresql.ARRAY(String)) urls = db.Column(postgresql.ARRAY(String)) tags = db.Column(postgresql.ARRAY(String)) media = db.Column(postgresql.ARRAY(String)) has_url = db.Column(db.Boolean) has_channel = db.Column(db.Boolean) karma = db.Column(db.Float) up_votes = db.Column(db.Integer) down_votes = db.Column(db.Integer) favorites = db.Column(db.Integer) published_at = db.Column(db.DateTime, default=dt.utcnow()) channel_id = db.Column( db.Integer, db.ForeignKey('channel.id'), index=True, ) channel = db.relationship(Channel) channels = db.Column(postgresql.ARRAY(String)) spam = db.Column(db.Boolean, default=False) flagged = db.Column(db.Boolean, default=False) deleted = db.Column(db.Boolean, default=False) def jsonable(self, date_converter=format_date): return { 'id': str(self.id), 'user_id': str(self.user_id), 'reply_to_id': str(self.reply_to_id), 'content': self.content, 'content_html': self.content_html, 'lang': self.lang, 'published_at': date_converter(self.published_at), 'media': self.media, 'channels': self.channels, 'mentions': self.mentions, "urls": self.urls, "tags": self.tags, } def __str__(self): return str(self.jsonable())