kai / kai / model /

"""CouchDB Models"""
import pylons
from datetime import datetime

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

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

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

class Snippet(Document):
    type = TextField(default='Snippet')
    human_id = TextField()
    username = TextField()
    created = DateTimeField(
    title = TextField()
    description = TextField()
    content = TextField()
    slug = TextField()
    tags = ListField(TextField())
    all_ratings = DictField(
            username = TextField(),
            rating = IntegerField()
    computed_rating = FloatField()
    def exists(cls, title):
        rows    = pylons.c.db.view('snippets/by_title')[title]
        return len(rows) > 0
    def by_date(cls, **options):
        rows    = pylons.c.db.view('snippets/by_date', **options)
        return rows
    def by_author(cls):
    def fetch_snippet(cls, slug, **options):
        snip = pylons.c.db.view('snippets/by_slug', **options)[slug]
        if snip.total_rows > 0:
            return snip.rows[0].value
            return false

class Comment(Document):
    type = TextField(default='Comment')
    human_id = TextField()
    doc_id = TextField()
    username = TextField()
    content = TextField(default='')
    markup = TextField(default='')
    time = DateTimeField()

class Documentation(object):
    def fetch_doc(cls, project, version, path):
        rows = pylons.c.db.view('documentation/by_path')[[project, version, path]]
        if len(rows) > 0:
            return list(rows)[0].value
            return False
    def delete_revision(cls, project, rev):
        rows = pylons.c.db.view('documentation/ids_for_version')[[project, rev]]
        for row in rows:
            del db[]
    def exists(cls, doc):
        key = [doc['filename'], doc['version'], doc['project']]
        rows = pylons.c.db.view('documentation/doc_key', group=True)[key]
        return len(rows) > 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.