本文整理汇总了Python中mongoengine.connection._get_db函数的典型用法代码示例。如果您正苦于以下问题:Python _get_db函数的具体用法?Python _get_db怎么用?Python _get_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_get_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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}},
)
示例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)})
示例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)
示例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)
示例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)
示例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
示例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]
示例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
示例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)
示例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)
示例11: setUp
def setUp(self):
connect(db='mongoenginetest')
self.db = _get_db()
class Person(Document):
name = StringField()
age = IntField()
self.Person = Person
示例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)
示例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)
示例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")
示例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