本文整理汇总了Python中models.Post.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Post.objects方法的具体用法?Python Post.objects怎么用?Python Post.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tags
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def tags(tag=None):
if tag is None:
tags = Post.objects(visible=True).distinct('tags')
return render_template('posts/tags.html',
tags=tags)
else:
posts = Post.objects(tags=tag, visible=POST_VISIBLE)
return render_template('posts/tag_list.html',
posts=posts,
tag=tag,
title=tag)
示例2: admin_list
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def admin_list(group):
user = User.objects(id=current_user.id).get()
if group not in user.moderating:
abort(404)
unapproved_posts = Post.objects(archived=False, approved=False, group=group)
approved_posts = Post.objects(archived=False, approved=True, group=group)
return render_template('admin/list.html',
group=group,
unapproved_posts=unapproved_posts,
approved_posts=approved_posts)
示例3: update
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def update(request):
id = eval("request." + request.method + "['id']")
if Post.objects(id=id):
post = Post.objects(id=id)[0]
if request.method == 'POST':
template = 'admin/index.html'
# update field values and save to mongo
post.title = request.POST['title']
#str_date_published = request.POST['date_published']
#post.date_published = datetime.fromtimestamp(mktime(time.strptime(str_date_published, "%b %d %Y")))
post.publisher = request.POST['publisher']
post.papertype = request.POST['papertype']
post.authors = request.POST['authors']
#post.additional_info = request.POST['additional_info']
#post.page_num = request.POST['page_num']
#if request.POST.get('selectedpublication', True):
# post.selectedpublication = True;
post.save()
params = {'Posts': Post.objects}
elif request.method == 'GET':
template = 'admin/update.html'
params = {'post':post}
elif Section.objects(id=id):
section = Section.objects(id=id)[0]
if request.method == 'POST':
template = 'admin/index.html'
# update field values and save to mongo
section.heading = request.POST['heading']
section.content = request.POST['content']
section.save()
params = {'Sections': Section.objects}
elif request.method == 'GET':
template = 'admin/update.html'
params = {'section':section}
elif Profile.objects(id=id):
profile = Profile.objects(id=id)[0]
if request.method == 'POST':
template = 'admin/index.html'
# update field values and save to mongo
profile.details = request.POST['profile']
profile.save()
params = {'Profile': Profile.objects.limit(1)}
elif request.method == 'GET':
template = 'admin/update.html'
params = {'Profile': Profile.objects.limit(1)}
return render_to_response(template, params, context_instance=RequestContext(request))
示例4: get_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def get_post(ID):
parsed = parse_id(ID)
if parsed:
year, month, day, s = parse_id(ID)
d = date(year, month, day)
posts = Post.objects(date=d, slug=s)
return posts.first()
示例5: update
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def update(request):
id = eval("request." + request.method + "['id']")
# if 'id' in request.POST:
# if request.method == 'POST':
# id = request.POST['id'];
# elif request.method == 'GET':
# id = request.GET["id"]
# else:
# id = 0
post = Post.objects(id=id)[0]
if request.method == 'POST':
# update field values and save to mongo
post.title = request.POST['title']
post.last_update = datetime.datetime.now()
post.content = request.POST['content']
post.save()
template = 'index.html'
params = {'Posts': Post.objects}
elif request.method == 'GET':
template = 'update.html'
params = {'post':post}
return render_to_response(template, params, context_instance=RequestContext(request))
示例6: geo_list
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def geo_list():
form = GeoForm()
posts_found = []
for post in Post.objects():
if within_ran(post, form.lat.data, form.lon.data):
posts_found.append(post)
return render_template("geo.html", title = "geo", posts = posts_found, form = form)
示例7: tags
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def tags(tag):
page = request.args.get("page", 1)
paginated_posts = Post.objects(tags=tag).paginate(page=int(page), per_page=6)
tags = Post.objects.item_frequencies("tags")
return render_template("normal_list.html", pagination=paginated_posts, tags=tags, tag=tag)
示例8: tag_image
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def tag_image():
if request.method == 'POST':
slugval = str(request.form['slug'])
tagval = str(request.form['tag'])
print slugval
p = Post.objects(slug = slugval)
print len(p)
if len(p) >= 1:
#otherwise somethings wrong
post = p[0]
post.tags.append(tagval)
post.save()
tag_url = '/tagged/' + tagval
return redirect(tag_url)
posts_found = Post.objects()
return render_template('tag.html', posts = posts_found)
示例9: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def get(self, post_url=None):
""" View for a single post
"""
today = date.today().strftime('%d-%b-%Y')
is_today = True if post_url == today else False
if 'today' in request.path:
return redirect(url_for('.post', post_url=today))
post = Post.objects(user_ref=current_user.id, url=post_url).first()
if post is None:
try:
validated_date = validate_date(post_url).strftime('%d-%b-%Y')
except:
flash('No post found')
return redirect(url_for('.post', post_url=today))
if validated_date != post_url:
return redirect(url_for('.post', post_url=validated_date))
if is_today:
# create a new post for today
post = DailyPost(user_ref=current_user.id, url=today, kind='Daily')
post.save()
else:
flash('No post found')
return redirect(url_for('.post', post_url=today))
return render_template('writer/write.html', post=post, is_today=is_today)
示例10: show_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def show_posts(user_name):
try:
user_obj = User.objects.get(username=user_name)
user_posts = Post.objects(user_id=user_obj).order_by('-created_on')[:3]
print user_obj.blog_title
return render_template('show_posts.html', posts=user_posts)
except(DoesNotExist):
return abort(404)
示例11: example_query
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def example_query():
for post in Post.objects:
print post.title
print "=" * len(post.title)
if isinstance(post, TextPost):
print post.content
if isinstance(post, LinkPost):
print "Link:", post.link_url
print
for post in Post.objects(tags='mongodb'):
print post.title
num_posts = Post.objects(tags="mongodb").count()
print "Found %d posts with tag 'mongodb'" % num_posts
示例12: category
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def category(slug):
""" Category page controller """
category = Category.objects().filter_by(slug=slug).first()
if not post:
abort(404)
paginator = paginate(request, Post.objects().filter_by(is_published=True,
category_id=category.id))
return {'category': category, 'paginator': paginator}
示例13: deny
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def deny(group, slug):
user = User.objects(id=current_user.id).get()
if group not in user.moderating:
abort(404)
post = Post.objects(group=group, slug=slug).get_or_404()
post.archived = True
post.save()
return redirect(url_for('admin.admin_list', group=group))
示例14: put
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def put(self, id):
if 'content' in request.data:
try:
content = json.loads(request.data)['content']
post = Post.objects(id=id).first()
post.content = content
post.save()
return jsonify( post.to_dict() )
except:
abort(400)
return abort(400)
示例15: retrieve
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import objects [as 别名]
def retrieve(request):
id = eval("request." + request.method + "['_id']")
post = Post.objects(id='_id')[0]
if request.method == 'POST':
return render_to_response(template, params, context_instance=RequestContext(post.first_name))
elif request.method == 'GET':
template = 'update.html'
params = {'post':post}
return render_to_response(template, params, context_instance=RequestContext(request))