本文整理汇总了Python中misago.core.shortcuts.get_object_or_404函数的典型用法代码示例。如果您正苦于以下问题:Python get_object_or_404函数的具体用法?Python get_object_or_404怎么用?Python get_object_or_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_object_or_404函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: generic
def generic(request):
queryset = get_user_model().objects
if request.query_params.get('followers'):
user_pk = get_int_or_404(request.query_params.get('followers'))
queryset = get_object_or_404(queryset, pk=user_pk).followed_by
elif request.query_params.get('follows'):
user_pk = get_int_or_404(request.query_params.get('follows'))
queryset = get_object_or_404(queryset, pk=user_pk).follows
if request.query_params.get('rank'):
rank_pk = get_int_or_404(request.query_params.get('rank'))
rank = get_object_or_404(Rank.objects, pk=rank_pk, is_tab=True)
queryset = queryset.filter(rank=rank)
if request.query_params.get('name'):
name_starts_with = request.query_params.get('name').strip().lower()
if name_starts_with:
queryset = queryset.filter(slug__startswith=name_starts_with)
else:
raise Http404()
queryset = queryset.select_related('rank', 'ban_cache', 'online_tracker')
paginator = Paginator()
users = paginator.paginate_queryset(queryset.order_by('slug'), request)
make_users_status_aware(users, request.user.acl)
return paginator.get_paginated_response(
UserSerializer(users, many=True).data)
开发者ID:Didan,项目名称:Misago,代码行数:29,代码来源:list.py
示例2: rank
def rank(request, rank_slug, page=0):
rank = get_object_or_404(Rank.objects.filter(is_tab=True), slug=rank_slug)
queryset = rank.user_set.select_related('rank').order_by('slug')
page = paginate(queryset, page, settings.MISAGO_USERS_PER_PAGE, 4)
paginator = pagination_dict(page)
request.frontend_context['USERS'] = dict(
results=UserSerializer(page.object_list, many=True).data,
**paginator
)
if rank.description:
description = {
'plain': rank.description,
'html': format_plaintext_for_html(rank.description)
}
else:
description = None
template = "misago/userslists/rank.html"
return render(request, template, {
'rank': rank,
'users': page.object_list,
'paginator': paginator
})
开发者ID:fengrussell,项目名称:Misago,代码行数:27,代码来源:lists.py
示例3: decorator
def decorator(request, *args, **kwargs):
User = get_user_model()
relations = ('rank', 'online_tracker', 'ban_cache')
queryset = User.objects.select_related(*relations)
profile = get_object_or_404(queryset, id=kwargs.pop('user_id'))
validate_slug(profile, kwargs.pop('user_slug'))
kwargs['profile'] = profile
add_acl(request.user, profile)
if profile.acl_['can_follow']:
profile.is_followed = request.user.is_following(profile)
else:
profile.is_followed = False
if profile.acl_['can_block'] and request.user.is_authenticated():
profile.is_blocked = request.user.is_blocking(profile)
else:
profile.is_blocked = False
if request.user.is_authenticated and request.method == "GET":
read_user_notification(request.user, "profile_%s" % profile.pk)
return f(request, *args, **kwargs)
开发者ID:David1119,项目名称:Misago,代码行数:26,代码来源:profile.py
示例4: fetch_forum
def fetch_forum(self, request, lock=False, **kwargs):
queryset = Forum.objects
if lock:
queryset = queryset.select_for_update()
return get_object_or_404(
queryset, id=kwargs.get('forum_id'), role='forum')
开发者ID:nikescar,项目名称:Misago,代码行数:7,代码来源:base.py
示例5: fetch_thread
def fetch_thread(self, request, lock=False, select_related=None, **kwargs):
queryset = Thread.objects
if lock:
queryset = queryset.select_for_update()
if select_related:
queryset = queryset.select_related(*select_related)
return get_object_or_404(queryset, id=kwargs.get('thread_id'))
开发者ID:dahito,项目名称:Misago,代码行数:8,代码来源:base.py
示例6: decorator
def decorator(request, forum_slug, forum_id):
allow_see_forum(request.user, forum_id)
forums = Forum.objects.all_forums()
forum = get_object_or_404(forums, pk=forum_id, role=role)
validate_slug(forum, forum_slug)
return f(request, forum)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:8,代码来源:__init__.py
示例7: fetch_post
def fetch_post(self, request, lock=False, select_related=None,
queryset=None, **kwargs):
queryset = queryset or Post.objects
if lock:
queryset = queryset.select_for_update()
if select_related:
queryset = queryset.select_related(*select_related)
return get_object_or_404(queryset, id=kwargs.get('post_id'))
开发者ID:nikescar,项目名称:Misago,代码行数:9,代码来源:base.py
示例8: rank
def rank(request, queryset):
rank_slug = request.query_params.get('rank')
if not rank_slug:
return
rank = get_object_or_404(Rank.objects.filter(is_tab=True), slug=rank_slug)
queryset = queryset.filter(rank=rank).order_by('slug')
return {'queryset': queryset, 'paginate': True}
开发者ID:ZerGabriel,项目名称:Misago,代码行数:9,代码来源:list.py
示例9: patch_top_category
def patch_top_category(request, thread, value):
category_pk = get_int_or_404(value)
root_category = get_object_or_404(
Category.objects.all_categories(include_root=True),
pk=category_pk
)
categories = list(Category.objects.all_categories().filter(
id__in=request.user.acl['visible_categories']
))
add_categories_to_items(root_category, categories, [thread])
return {'top_category': CategorySerializer(thread.top_category).data}
开发者ID:1905410,项目名称:Misago,代码行数:12,代码来源:patch.py
示例10: decorator
def decorator(request, *args, **kwargs):
queryset = get_user_model().objects.select_for_update()
user_id = kwargs.pop('user_id')
kwargs['user'] = get_object_or_404(queryset, id=user_id)
validate_slug(kwargs['user'], kwargs.pop('user_slug'))
add_acl(request.user, kwargs['user'])
if required_permission:
required_permission(request.user, kwargs['user'])
return f(request, *args, **kwargs)
开发者ID:ZerGabriel,项目名称:Misago,代码行数:12,代码来源:moderation.py
示例11: get_thread
def get_thread(self, user, thread_id):
thread = get_object_or_404(Thread.objects.select_related('category'),
id=get_int_or_404(thread_id),
category__tree_id=self.TREE_ID,
)
add_acl(user, thread.category)
add_acl(user, thread)
self.validate_thread_visible(user, thread)
return thread
开发者ID:Didan,项目名称:Misago,代码行数:12,代码来源:threads.py
示例12: read_threads
def read_threads(user, pk):
user.lock()
category_id = get_int_or_404(pk)
threads_tree_id = trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
category = get_object_or_404(Category, id=category_id, tree_id=threads_tree_id)
if category.level:
allow_see_category(user, category)
allow_browse_category(user, category)
read_category(user, category)
开发者ID:rafalp,项目名称:Misago,代码行数:13,代码来源:read.py
示例13: decorator
def decorator(request, *args, **kwargs):
User = get_user_model()
relations = ('rank', 'online_tracker', 'ban_cache')
queryset = User.objects.select_related(*relations)
profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))
validate_slug(profile, kwargs.pop('slug'))
kwargs['profile'] = profile
add_acl(request.user, profile)
return f(request, *args, **kwargs)
开发者ID:mayblue9,项目名称:Misago,代码行数:13,代码来源:profile.py
示例14: read
def read(self, request):
if request.query_params.get('category'):
category_id = get_int_or_404(request.query_params.get('category'))
category = get_object_or_404(Category.objects,
id=category_id,
tree_id=self.TREE_ID,
)
allow_see_category(request.user, category)
allow_browse_category(request.user, category)
else:
category = Category.objects.root_category()
read_category(request.user, category)
return Response({'detail': 'ok'})
开发者ID:Didan,项目名称:Misago,代码行数:15,代码来源:threads.py
示例15: fetch_thread
def fetch_thread(self, request, lock=False, select_related=None,
queryset=None, **kwargs):
queryset = queryset or Thread.objects
if lock:
queryset = queryset.select_for_update()
select_related = select_related or []
if not 'forum' in select_related:
select_related.append('forum')
queryset = queryset.select_related(*select_related)
where = {'id': kwargs.get('thread_id')}
if 'forum_id' in kwargs:
where['forum_id'] = kwargs.get('forum_id')
return get_object_or_404(queryset, **where)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:15,代码来源:base.py
示例16: rank
def rank(request):
rank_slug = request.query_params.get('rank')
if not rank_slug:
raise Http404()
rank = get_object_or_404(Rank.objects, slug=rank_slug, is_tab=True)
queryset = rank.user_set.select_related(
'rank', 'ban_cache', 'online_tracker').order_by('slug')
paginator = Paginator()
users = paginator.paginate_queryset(queryset, request)
make_users_status_aware(users, request.user.acl)
return paginator.get_paginated_response(
UserSerializer(users, many=True).data)
开发者ID:nescode,项目名称:Misago,代码行数:15,代码来源:list.py
示例17: get_category
def get_category(self, request):
if request.query_params.get('category'):
category_id = get_int_or_404(request.query_params['category'])
category = get_object_or_404(
Category.objects.select_related('parent'),
tree_id=CATEGORIES_TREE_ID,
id=category_id,
)
allow_see_category(request.user, category)
allow_browse_category(request.user, category)
return category
else:
return Category.objects.root_category()
开发者ID:fengrussell,项目名称:Misago,代码行数:15,代码来源:list.py
示例18: get_queryset
def get_queryset(self):
queryset = UsernameChange.objects
if self.request.query_params.get('user'):
user_pk = get_int_or_404(self.request.query_params.get('user'))
queryset = get_object_or_404(
get_user_model().objects, pk=user_pk).namechanges
if self.request.query_params.get('search'):
search_phrase = self.request.query_params.get('search').strip()
if search_phrase:
queryset = queryset.filter(
Q(changed_by_username__istartswith=search_phrase) |
Q(new_username__istartswith=search_phrase) |
Q(old_username__istartswith=search_phrase))
return queryset.select_related('user', 'changed_by').order_by('-id')
开发者ID:fengrussell,项目名称:Misago,代码行数:17,代码来源:usernamechanges.py
示例19: read
def read(self, request):
if request.query_params.get('category'):
threads_tree_id = trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
category_id = get_int_or_404(request.query_params.get('category'))
category = get_object_or_404(Category,
id=category_id,
tree_id=threads_tree_id,
)
allow_see_category(request.user, category)
allow_browse_category(request.user, category)
else:
category = Category.objects.root_category()
read_category(request.user, category)
return Response({'detail': 'ok'})
开发者ID:h094071,项目名称:Misago,代码行数:17,代码来源:threads.py
示例20: read
def read(self, request, pk):
request.user.lock()
category_id = get_int_or_404(pk)
threads_tree_id = trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
category = get_object_or_404(Category,
id=category_id,
tree_id=threads_tree_id,
)
if category.level:
allow_see_category(request.user, category)
allow_browse_category(request.user, category)
read_category(request.user, category)
return Response({'detail': 'ok'})
开发者ID:1905410,项目名称:Misago,代码行数:18,代码来源:api.py
注:本文中的misago.core.shortcuts.get_object_or_404函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论