本文整理汇总了Python中models.Entry.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.objects方法的具体用法?Python Entry.objects怎么用?Python Entry.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.objects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entry_list
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import objects [as 别名]
def entry_list(request, **kwargs):
entries = Entry.objects(status = Entry.STATUS_PUBLIC)
# TODO: Paginate the Entry-list
return direct_to_template(request, 'mongoblog/entry_list.html', {
'entry_list': entries,
})
示例2: entry_detail
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import objects [as 别名]
def entry_detail(request, slug):
entry = Entry.objects(slug=slug).first()
if not entry:
raise Http404
return direct_to_template(request, 'mongoblog/entry_detail.html', {
'entry': entry,
})
示例3: update_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import objects [as 别名]
def update_entry(entry_id=None):
'''Update an existing entry at /update/entry_id/ or make a new one at /update/.
Returns the entry_id of the new or updated entry.'''
entry = Entry()
if entry_id != None:
entry = Entry.objects(id=entry_id)[0]
revision = Revision(content=request.form['content'], rows=request.form['rows'])
entry.add_revision(revision)
entry.save()
return str(entry.id)
示例4: create
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import objects [as 别名]
def create():
if request.method == 'POST':
if request.form.get('title') and request.form.get('content'):
user=session['user']
entry = Entry(
title=request.form['title'],
content=request.form['content'],
published=True,
#published=request.form.get('published') or False, #for later implementation of drafts
authors=[user['username']])
entry.save()
Entry.objects(id=entry.id).update_one(slug=unicode(entry.id))
entry.reload() #made to avoid duplicate slugs and to generate an url
flash('Entry created successfully.', 'success')
if entry.published:
return redirect(url_for('detail', slug=entry.slug))
else:
return redirect(url_for('edit', slug=entry.slug))
else:
flash('Title and Content are required.', 'danger')
return render_template('create.html')
示例5: system_stats
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import objects [as 别名]
def system_stats():
''' calculates and prints info about the system
usage:
$ . /path/to/venv/bin/activate
(venv)$ python
>> import application
>> application.controllers.system_stats()
there are 1234 entries in the system
'''
# initialize the mongoengine connection
mongo_config = app.config['MONGO_CONFIG']
mongodb_uri = 'mongodb://'
if mongo_config['dbuser'] and mongo_config['dbpassword']:
mongodb_uri += '%s:%[email protected]' % (mongo_config['dbuser']
, mongo_config['dbpassword'])
mongodb_uri += '%s/%s' % (mongo_config['hosts'], mongo_config['db_name'])
connect(mongo_config['db_name'], host=mongodb_uri)
projects = Project.objects()
total_entries = 0
total_points = 0
for project in projects:
schema = project.ordered_schema
entries = Entry.objects(project=project)
# count the points
for entry in entries:
# drop non-uniques or hidden
if not entry.unique or not entry.visible:
continue
total_entries += 1
# count datapoints
for header in schema:
if header.name in entry.values:
if entry['values'][header.name] != None:
total_points += 1
print 'there are %s entries in the system' % total_entries
print 'there are %s datapoints in the system' % total_points