hydra / hydra / models / __init__.py

# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Alexander Shorin
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#

from .base import Document, Meta


def make_resolver(db, system):
    def resolve(doctype=None, idx=None, **kwargs):
        if doctype and idx:
            key = [system, doctype, idx]
            view = db.view('externals/by_type_and_id', key=key, reduce=False,
                           include_docs=True, limit=2)
            rows = list(view)
            if not rows:
                raise LookupError('missed %s @ %s' % (doctype, idx))
            assert len(rows) == 1, ('duplicate docs found for key: %s'
                                    % rows[0].key)
            return rows[0].doc
        if 'docid' in kwargs:
            return db[kwargs['docid']]
        if 'view' in kwargs:
            key = kwargs['key']
            view = db.view(kwargs['view'], key=key, reduce=False,
                           include_docs=True, limit=2)
            rows = list(view)
            if not rows:
                raise LookupError('missed %s @ %s' % (doctype, idx))
            assert len(rows) == 1, ('duplicate docs found for key: %s'
                                    % rows[0].key)
            return rows[0].doc
        raise NotImplementedError('no idea how to resolve that')
    return resolve
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 ProjectModifiedEvent.java.
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.