<commit_before>"""CouchDB Models"""
import pylons
from datetime import datetime

from couchdb.schema import DateTimeField, DictField, Document, TextField, \
    ListField


class Human(Document):
    """Represents a human user"""
    type = TextField(default='Human')
    name = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    last_login = DateTimeField(default=datetime.now)
    blog = TextField()
    openid = ListField(TextField())


class Paste(Document):
    type = TextField(default='Paste')
    human_id = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    title = TextField()
    language = TextField()
    code = TextField()


class Snippet(Document):
    type = TextField(default='Snippet')
    human_id = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    title = TextField()
    description = TextField()
    content = TextField()
    
    @classmethod
    def exists(cls, title):
        rows    = pylons.c.db.view('snippets/by_title')[title]
        return len(rows) > 0
        
    @classmethod
    def by_date(cls, **options):
        rows    = pylons.c.db.view('snippets/by_date', **options)
        return rows
        
    @classmethod
    def by_author(cls):
        pass
        
    @classmethod
    def fetch_snippet(cls, id, **options):
        rows    = pylons.c.db.view('snippets/by_id', **options)[id]
        if len(rows) > 0:
            return list(rows)[0].value
        else:
            return False
        <commit_msg>added a slug column to snippet<commit_after>"""CouchDB Models"""
import pylons
from datetime import datetime

from couchdb.schema import DateTimeField, DictField, Document, TextField, \
    ListField


class Human(Document):
    """Represents a human user"""
    type = TextField(default='Human')
    name = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    last_login = DateTimeField(default=datetime.now)
    blog = TextField()
    openid = ListField(TextField())


class Paste(Document):
    type = TextField(default='Paste')
    human_id = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    title = TextField()
    language = TextField()
    code = TextField()


class Snippet(Document):
    type = TextField(default='Snippet')
    human_id = TextField()
    username = TextField()
    created = DateTimeField(default=datetime.now)
    title = TextField()
    description = TextField()
    content = TextField()
    slug    = TextField()
    
    @classmethod
    def exists(cls, title):
        rows    = pylons.c.db.view('snippets/by_title')[title]
        return len(rows) > 0
        
    @classmethod
    def by_date(cls, **options):
        rows    = pylons.c.db.view('snippets/by_date', **options)
        return rows
        
    @classmethod
    def by_author(cls):
        pass
        
    @classmethod
    def fetch_snippet(cls, id, **options):
        rows    = pylons.c.db.view('snippets/by_id', **options)[id]
        if len(rows) > 0:
            return list(rows)[0].value
        else:
            return False
        
{'fraction_non_alphanumeric': 0.11685883452789031, 'fraction_numerical': 0.001869741352446245, 'mean_word_length': 2.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2809963', 'n_tokens_mistral': 979, 'n_tokens_neox': 948, 'n_words': 219}