本文整理汇总了Python中mig_main.utility.Permissions.can_create_forum方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.can_create_forum方法的具体用法?Python Permissions.can_create_forum怎么用?Python Permissions.can_create_forum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig_main.utility.Permissions
的用法示例。
在下文中一共展示了Permissions.can_create_forum方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_permissions
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_create_forum [as 别名]
def get_permissions(user):
permission_dict=get_member_permissions(user)
is_member=False
if hasattr(user,'userprofile') and user.userprofile.is_member():
is_member=True
permission_dict.update({'can_create_thread':Permissions.can_create_thread(user),
'can_create_forum':Permissions.can_create_forum(user),
'can_comment':hasattr(user,'userprofile') and user.userprofile.is_member(),
'can_moderate':Permissions.can_create_forum(user),
'can_downvote':get_user_points(user.userprofile.memberprofile)>0 if is_member else False})
return permission_dict
示例2: create_forum
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_create_forum [as 别名]
def create_forum(request):
if not Permissions.can_create_forum(request.user):
raise PermissionDenied()
NewForumForm = modelform_factory(Forum)
form = NewForumForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
form.save()
request.session['success_message'] = 'Forum successfully created'
return get_previous_page(request, alternate='fora:index')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_form.html')
context_dict = {
'form': form,
'has_files': False,
'submit_name': 'Create new forum',
'form_title': 'Create new forum',
'help_text': ('A new forum should be organized around a topic or a '
'style of post.'),
'base': 'fora/base_fora.html',
'back_button': {
'link': reverse('fora:index'),
'text': 'Back to fora'
},
}
context_dict.update(get_permissions(request.user))
context_dict.update(get_common_context(request))
return HttpResponse(template.render(context_dict, request))
示例3: delete_forum
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_create_forum [as 别名]
def delete_forum(request,forum_id):
if not Permissions.can_create_forum(request.user):
request.session['error_message']='You are not authorized to delete fora'
return redirect('fora:index')
forum=get_object_or_404(Forum,id=forum_id)
if forum.forumthread_set.filter(hidden=False).exists():
request.session['error_message']='Forum has visible threads, unable to delete'
return get_previous_page(request,alternate='fora:index')
forum.delete()
return redirect('fora:index')
示例4: hide_comment
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_create_forum [as 别名]
def hide_comment(request,comment_id):
if not Permissions.can_create_forum(request.user):
request.session['error_message']='You are not authorized to hide comments'
return redirect('fora:index')
message = get_object_or_404(ForumMessage,id=comment_id)
message.hidden=True
message.save()
if not message.in_reply_to:
thread =message.forum_thread
thread.hidden=True
thread.save()
return redirect('fora:index')
return get_previous_page(request,alternate='fora:index')