• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python connection._get_db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mongoengine.connection._get_db函数的典型用法代码示例。如果您正苦于以下问题:Python _get_db函数的具体用法?Python _get_db怎么用?Python _get_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_get_db函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: touch

 def touch(cls, contrib):
     """updates all envelopes with new modification date
     """
     _get_db().envelope.update(
         {"contribution": unicode(contrib[contrib._meta["id_field"]])},
         {"$set": {"updated_date": datetime.now(), "title": contrib.title}},
     )
开发者ID:ctoscano,项目名称:pluma,代码行数:7,代码来源:__init__.py


示例2: remove

 def remove(cls, user=False, contrib=False, draft=False):
     if hasattr(contrib, '_id'):
         _get_db().draft.remove({'a':unicode(user._id),
                                 'c':unicode(contrib._id)})
     elif hasattr(draft, '_id'):
         _get_db().draft.remove({'a':unicode(user._id),
                                 '_id':pymongo.objectid.ObjectId(draft._id)})
开发者ID:ntoscano,项目名称:pluma,代码行数:7,代码来源:__init__.py


示例3: save_draft

    def save_draft(cls, user, contrib):
        """ @param user: required
            @param contrib: ignoring id if blank; always use text
        """
        main_vars = {"a": unicode(user._id)}

        # Only set contribution ID if ID not blank
        if hasattr(contrib, "_id") and contrib._id != "":
            main_vars["c"] = unicode(contrib._id)

        _get_db().draft.update(main_vars, {"$set": {"txt": contrib.get_text(), "t": contrib.title}}, upsert=True)
开发者ID:ctoscano,项目名称:pluma,代码行数:11,代码来源:__init__.py


示例4: save_draft

 def save_draft(cls, user, contrib):
     ''' @param user: required
         @param contrib: ignoring id if blank; always use text
     '''
     main_vars = {'a':unicode(user._id)}
     
     # Only set contribution ID if ID not blank
     if hasattr(contrib, '_id') and contrib._id != '': 
         main_vars['c'] = unicode(contrib._id)
     
     _get_db().draft.update(main_vars, 
                            {'$set':{'txt':contrib.get_text(),
                                     't':contrib.title}}, 
                            upsert=True)
开发者ID:ntoscano,项目名称:pluma,代码行数:14,代码来源:__init__.py


示例5: factory

    def factory(cls, id=None, type=None, domain=None, uri=None):
        if id is None and type is None and (domain is None and uri is None):
            return None

        if id or (domain and uri):
            query = {"_id": ObjectId(id)}
            if domain:
                query["D"] = domain
            if domain and uri:
                query["U"] = uri
                del query["_id"]

            values = _get_db().contribution.find_one(query)

            if values is None:
                return None
            values.setdefault("type")
            type = values["type"]
        elif type:
            values = {}

        if type == "html":
            return HtmlContribution._from_son(values)
        elif type == "markdown":
            return MarkdownContribution._from_son(values)
        else:
            return Contribution._from_son(values)
开发者ID:ctoscano,项目名称:pluma,代码行数:27,代码来源:__init__.py


示例6: get_app

def get_app():
    #app = Flask(__name__)
    app = Flask('pyfem')
    app.config.from_object(Config)

    # set environment PYFEM_SETTINGS=testing_settings to automatically use a -test version of db
    if os.environ.get('PYFEM_SETTINGS'):
        if os.environ['PYFEM_SETTINGS'] == 'testing_settings':
            app.config['MONGODB_SETTINGS'] = dict(db=app.config['MONGO_DBNAME'] + '-test')

    app.secret_key = app.config['SECRET_KEY']

    app.me = MongoEngine(app)
    app.pymongo = _get_db()

    # app.jinja_env.add_extension('util.Markdown2Extension')
    # app.jinja_env.filters['slugify'] = slugify
    # app.jinja_env.filters['timesince'] = timesince
    # app.jinja_env.filters['timeuntil'] = timeuntil
    # app.jinja_env.filters['jsonencode'] = jsonencode
    # app.jinja_env.globals['newrelic_head'] = newrelic_head
    # app.jinja_env.globals['newrelic_foot'] = newrelic_foot

    # if not app.config.get('TEMPLATE_DEBUG', True):
    #     compiled_templates = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'compiled_templates')
    #     compiled_files = path.path(compiled_templates).files()
    #     if len(compiled_files) <= 1:
    #         app.jinja_env.compile_templates(compiled_templates, zip=None, py_compile=True)
    #     app.jinja_env.loader = ModuleLoader(compiled_templates)

    configure_logging(app)
    return app
开发者ID:LarryEitel,项目名称:pyfem,代码行数:32,代码来源:app.py


示例7: _flush_db

 def _flush_db(self):
     from mongoengine.connection import _get_db
     me = _get_db()
     #Truncate/wipe the test database
     names = [name for name in me.collection_names() \
         if 'system.' not in name]
     [me.drop_collection(name) for name in names]
开发者ID:LarryEitel,项目名称:pyfem,代码行数:7,代码来源:core.py


示例8: mongodb

def mongodb(collection=None):
    from mongoengine.connection import _get_db
    db = _get_db()
    if collection is not None:
        return getattr(db, collection)
    else:
        return db
开发者ID:matehat,项目名称:python-neurolab,代码行数:7,代码来源:__init__.py


示例9: test_document_history

def test_document_history():

    @save_history
    class Book(Document):
        title = StringField()
        caption = StringField()

    establish_mongo_connection()

    book = Book()
    title_string = "Mother Night"
    book.title = title_string
    book.save()

    history = book.history
    eq_(len(history), 1)
    eq_(history[0]["changes"]["title"], title_string)


    caption_string = "We must be careful about what we pretend to be."

    book.caption = caption_string
    book.save()

    history = book.history

    eq_(len(history), 2)
    eq_(history[1]["changes"]["caption"], caption_string)


    # Clear database
    db = _get_db()
    collection_names = [c for c in db.collection_names() if not c.startswith("system.")]
    for collection in collection_names:
        db.drop_collection(collection)
开发者ID:Martikos,项目名称:document_history,代码行数:35,代码来源:tests.py


示例10: get_jobs_vs_programming_languages

def get_jobs_vs_programming_languages():
    pipeline = [
        {"$redact": {
            "$cond": {
                "if": {"$eq": ["$deprecated", False]},
                "then": "$$KEEP",
                "else": "$$PRUNE"
            }
        }},
        {"$project": {
            "_id": 0,
            "keywords": 1,
            "deprecated": 1
        }},
        {"$unwind": "$keywords"},
        {"$match": {"keywords.types": {"$in": [keyword_type.types["PROGRAMMING_LANG"]]}}},
        {"$group": {
            "_id": {
                "keyword": "$keywords.keyword",
                "types": "$keywords.types"
            },
            "count": {
                "$sum": 1
            }
        }}
    ]

    db = connection._get_db(reconnect=False)

    return db.job.aggregate(pipeline)
开发者ID:Mo-Talha,项目名称:Nomad,代码行数:30,代码来源:statistics.py


示例11: setUp

 def setUp(self):
     connect(db='mongoenginetest')
     self.db = _get_db()
     class Person(Document):
         name = StringField()
         age = IntField()
     self.Person = Person
开发者ID:aparo,项目名称:mongoengine,代码行数:7,代码来源:django_shortcuts.py


示例12: factory

 def factory(cls, id=None, type=None, domain=None, uri=None):
     if id is None and type is None and (domain is None and uri is None):
         return None
     
     if id or (domain and uri):
         query = {'_id': pymongo.objectid.ObjectId(id)}
         if domain: 
             query['D'] = domain
         if domain and uri:
             query['U'] = uri
             del query['_id']
         
         values = _get_db().contribution.find_one(query)
         
         if values is None:
             return None
         values.setdefault('type')
         type = values['type']
     elif type:
         values = {}
     
     
     if type == 'html':
         return HtmlContribution._from_son(values)
     elif type == 'markdown':
         return MarkdownContribution._from_son(values)
     else:
         return Contribution._from_son(values)
开发者ID:ntoscano,项目名称:pluma,代码行数:28,代码来源:__init__.py


示例13: get_jobs_vs_javascript_libraries

def get_jobs_vs_javascript_libraries():
    pipeline = [
        {"$redact": {
            "$cond": {
                "if": {"$eq": ["$deprecated", False]},
                "then": "$$KEEP",
                "else": "$$PRUNE"
            }
        }},
        {"$project": {
            "_id": 0,
            "keywords": 1,
            "deprecated": 1
        }},
        {"$unwind": "$keywords"},
        {"$match": {"keywords.types": {"$in": [keyword_type.types["JS_LIB"]]}}},
        {"$group": {
            "_id": {
                "keyword": "$keywords.keyword",
                "types": "$keywords.types"
            },
            "count": {
                "$sum": 1
            }
        }}
    ]

    db = connection._get_db(reconnect=False)

    return db.job.aggregate(pipeline)
开发者ID:Mo-Talha,项目名称:Nomad,代码行数:30,代码来源:statistics.py


示例14: _clean

 def _clean(self):
     #from mongoengine.connection import _get_db
     #db = _get_db()
     #db.drop_collection("example")
     clear_document_registry()
     connect(db='mongoenginetest')
     self.db = _get_db()
     self.db.drop_collection("example")
开发者ID:pelletier,项目名称:mongoengine,代码行数:8,代码来源:fields.py


示例15: _get_unique_filename

def _get_unique_filename(name):
    fs = gridfs.GridFS(_get_db())
    file_root, file_ext = os.path.splitext(name)
    count = itertools.count(1)
    while fs.exists(filename=name):
        # file_ext includes the dot.
        name = os.path.join("%s_%s%s" % (file_root, count.next(), file_ext))
    return name
开发者ID:rozza,项目名称:django-mongoengine,代码行数:8,代码来源:documents.py


示例16: setUp

    def setUp(self):
        connect()
        self.db = _get_db()

        class Person(Document):
            name = StringField()
            age = IntField()
            uid = ObjectIdField()
        self.Person = Person
开发者ID:andrew-cl,项目名称:mongoengine,代码行数:9,代码来源:document.py


示例17: setUp

    def setUp(self):
        connect()
        self.db = _get_db('test')

        @database('test')
        class Person(Document):
            name = StringField()
            age = IntField()
        self.Person = Person
开发者ID:kulasama,项目名称:mongoengine,代码行数:9,代码来源:document.py


示例18: __init__

 def __init__(self, *args, **kwargs):
     """
     We need to patch jinja_env loader to include flaskext.mongoengine
     templates folder.
     """
     super(MongoenginePanel, self).__init__(*args, **kwargs)
     self.jinja_env.loader = ChoiceLoader([self.jinja_env.loader,
                       PackageLoader('flaskext.mongoengine', 'templates')])
     self.db = _get_db()
开发者ID:linuxnow,项目名称:flask-mongoengine,代码行数:9,代码来源:panels.py


示例19: __init__

    def __init__(self, level=logging.DEBUG):
        """ Constructor
        
            Keyword Arguments:
            level -- The logging level
        """

        self.log.setLevel(level)
        self.ianatags = self.danatags + " IANA "
        self.fs = GridFS(_get_db())
开发者ID:nalapati,项目名称:SuryaIANAFramework,代码行数:10,代码来源:IANAFramework.py


示例20: setUp

    def setUp(self):
        warnings.simplefilter('always', category=UserWarning)
        connect()
        self.db = _get_db()
        mongoengine.base._document_registry = {}

        class Person(Document):
            name = StringField()
            age = IntField(default=20)

        self.person_cls = Person
开发者ID:ContextLogic,项目名称:mongoengine,代码行数:11,代码来源:custom_queries.py



注:本文中的mongoengine.connection._get_db函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connection.connect函数代码示例发布时间:2022-05-27
下一篇:
Python common._import_class函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap