示例#1
0
class User(db.Document):
    meta = {
        'collection': 'user',
        'allow_inheritance': True,
        'indexes': ['email', 'username'],
        'ordering': ['email', 'username']
    }

    username = db.StringField(max_Length=100, unique=True)
    firstname = db.StringField(max_Length=100)
    lastname = db.StringField(max_Length=100)
    email = db.StringField(max_Length=120, unique=True)
    pwdhash = db.StringField(max_Length=54)

    def __init__(self, username, email, password):
        self.username = username
        self.email = email.lower()
        self.set_password(password)

    @property
    def login(self):
        return self.username

    @login.setter
    def login(self, value):
        self.username = value

    def set_password(self, password):
        self.pwdhash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.pwdhash, password)

    # Flask-Login integration
    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_id(self):
        return self.uid

    # Required for administrative interface
    def __unicode__(self):
        return self.username
示例#2
0
class Post(db.DynamicDocument):
    meta = {
        'collection': 'post',
        'allow_inheritance': True,
        'indexes': ['-created', 'permalink'],
        'ordering': ['-created', 'permalink']
    }

    title = db.StringField(max_length=255, unique=True)
    permalink = db.StringField(max_length=255,
                               unique=True,
                               default=make_permalink)
    body = db.StringField(required=True)

    author = db.StringField(verbose_name="Name", max_length=255, required=True)
    created = db.DateTimeField(default=datetime.now, required=True)

    comments = db.ListField(db.EmbeddedDocumentField(Comment))
    tags = db.ListField(db.EmbeddedDocumentField(Tag))

    @property
    def post_type(self):
        return self.__class__.__name__

    #@property
    #def __class__(self):
    #    return db.DynamicDocument

    #def __init__(self, *ag, **kw):
    #    for key in kw.keys():
    #        setattr(self, key, kw[key])

    def __repr__(self):
        return u'<Post %r>' % self.title

    def __unicode__(self):
        return u'<Post %r>' % self.title

    def get_absolute_url(self):
        return url_for('post', kwargs={"permalink": self.permalink})
示例#3
0
class Quote(Post):
    body = db.StringField(required=True)
    author = db.StringField(verbose_name="Author Name",
                            required=True,
                            max_length=255)
示例#4
0
class Image(Post):
    image_url = db.StringField(required=True, max_length=255)
示例#5
0
class Video(Post):
    embed_code = db.StringField(required=True)
示例#6
0
class BlogPost(Post):
    body = db.StringField(required=True)
示例#7
0
class Tag(db.EmbeddedDocument):
    title = db.StringField(verbose_name="Title", required=True)
示例#8
0
class Comment(db.EmbeddedDocument):
    created = db.DateTimeField(default=datetime.now, required=True)
    body = db.StringField(verbose_name="Comment", required=True)
    author = db.StringField(verbose_name="Name", max_length=255, required=True)