Esempio n. 1
0
class WikiComment(db.EmbeddedDocument):
    # id = <epoch time>-<author id>
    id = db.StringField(required=True)
    timestamp = db.DateTimeField(default=datetime.now)
    author = db.StringField()
    md = db.StringField()
    html = db.StringField()
Esempio n. 2
0
class WikiLoginRecord(db.Document):
    username = db.StringField()
    timestamp = db.DateTimeField(default=datetime.now)
    browser = db.StringField()
    platform = db.StringField()
    details = db.StringField()
    ip = db.StringField()

    meta = {'collection': 'wiki_login_record', 'ordering': ['-timestamp']}
Esempio n. 3
0
class WikiFile(db.Document):
    id = db.SequenceField(primary_key=True)
    name = db.StringField(required=True)
    mime_type = db.StringField()
    size = db.IntField()  # in bytes
    uploaded_on = db.DateTimeField(default=datetime.now)
    uploaded_by = db.StringField()

    meta = {'collection': 'wiki_file'}
Esempio n. 4
0
class WikiPageVersion(db.Document):
    diff = db.StringField()
    version = db.IntField(required=True)
    modified_on = db.DateTimeField()
    modified_by = db.StringField()

    meta = {
        'collection': 'wiki_page_version',
        'indexes': [{
            'fields': ['$diff'],
            'default_language': 'english'
        }]
    }
Esempio n. 5
0
class WikiPage(db.Document):
    title = db.StringField(required=True, unique=True)
    md = db.StringField(default='')
    html = db.StringField()
    toc = db.StringField()
    modified_on = db.DateTimeField(default=datetime.now)
    modified_by = db.StringField(default='system')
    comments = db.ListField(db.EmbeddedDocumentField(WikiComment))
    current_version = db.IntField(default=1)
    versions = db.ListField(db.ReferenceField(WikiPageVersion))
    refs = db.ListField(db.ReferenceField('self'))
    keypage = db.IntField()

    meta = {
        'collection':
        'wiki_page',
        'indexes': [
            '#title', {
                'fields': ['$title', '$md', '$comments.md'],
                'default_language': 'english',
                'weights': {
                    'title': 10,
                    'md': 2,
                    'comments.md': 1
                }
            }
        ]
    }

    def update_db(self, diff, md, html, toc=None, update_refs=True):
        wiki_page_version = WikiPageVersion(
            diff=diff,
            version=self.current_version,
            modified_on=self.modified_on,
            modified_by=self.modified_by).save()

        updates = {
            'set__md': md,
            'set__html': html,
            'inc__current_version': 1,
            'set__modified_on': datetime.now(),
            'set__modified_by': current_user.name,
            'push__versions': wiki_page_version
        }
        if toc is not None:
            updates['set__toc'] = toc
        if update_refs:
            updates['set__refs'] = self.refs

        self.__class__.objects(id=self.id).update_one(**updates)