<commit_before>from couchdb.schema import Document, DateTimeField, TextField, DictField, Schema
from couchdb.client import Database
import markup

from datetime import datetime

class Page(Document):
    slug = TextField()
    Type = TextField(default='page')
    content_type = TextField(default='inline-text/x-rst')
    datetime = DictField(Schema.build(
        created = DateTimeField(default=datetime.now),
        modified = DateTimeField(default=datetime.now)
    ))
    content = TextField()
 
    def store(self, db, **kwargs):
        self.datetime['modified'] = datetime.now()
        super(Page, self).store(db, **kwargs)

    @property 
    def meta(self):
        if not hasattr(self, '_meta'):
            self.get_parsed_content()
        return self._meta

    @property 
    def html(self):
        if not hasattr(self, '_body'):
            self.get_parsed_content()
        return self._body

    def get_parsed_content(self):
        engine = markup.get_engine(self['content_type'])
        self._body, self._meta = engine(self['content'])
        return self._body, self._meta



class Database(Database):
 
    def by_slug(self, slug):
        x = self.first('_design/pages/_view/by_slug', key=slug)
        if x is not None:
            return Page.load(self, x.id)
        else:
            return None

    def first(self, name, **options):
        v = self.view(name, **options)
        if len(v) > 0:
            return v.rows[0]
        else:
            return None

    @property
    def all_pages(self):
        return self.view('_design/pages/_view/all')

    @property
    def all_comments(self):
        return self.view('_design/comments/_view/all')

<commit_msg>Update the model functions for CouchDB 0.9 and CouchDB-Python 0.6<commit_after>from couchdb.schema import Document, DateTimeField, TextField, DictField, Schema
from couchdb.client import Database
import markup

from datetime import datetime

class Page(Document):
    slug = TextField()
    Type = TextField(default='page')
    content_type = TextField(default='inline-text/x-rst')
    datetime = DictField(Schema.build(
        created = DateTimeField(default=datetime.now),
        modified = DateTimeField(default=datetime.now)
    ))
    content = TextField()
 
    def store(self, db, **kwargs):
        self.datetime['modified'] = datetime.now()
        super(Page, self).store(db, **kwargs)

    @property 
    def meta(self):
        if not hasattr(self, '_meta'):
            self.get_parsed_content()
        return self._meta

    @property 
    def html(self):
        if not hasattr(self, '_body'):
            self.get_parsed_content()
        return self._body

    def get_parsed_content(self):
        engine = markup.get_engine(self['content_type'])
        self._body, self._meta = engine(self['content'])
        return self._body, self._meta



class Database(Database):
 
    def by_slug(self, slug):
        x = self.first('pages/by_slug', key=slug)
        if x is not None:
            return Page.load(self, x.id)
        else:
            return None

    def first(self, name, **options):
        v = self.view(name, **options)
        if len(v) > 0:
            return v.rows[0]
        else:
            return None

    @property
    def all_pages(self):
        return self.view('pages/all')

    @property
    def all_comments(self):
        return self.view('comments/all')


{'fraction_non_alphanumeric': 0.1153169014084507, 'fraction_numerical': 0.002347417840375587, 'mean_word_length': 2.5180598555211557, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3484282', 'n_tokens_mistral': 1026, 'n_tokens_neox': 995, 'n_words': 243}