本文整理汇总了Python中misago.acl.add_acl函数的典型用法代码示例。如果您正苦于以下问题:Python add_acl函数的具体用法?Python add_acl怎么用?Python add_acl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_acl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_threads_for_merge
def clean_threads_for_merge(request):
threads_ids = clean_ids_list(
request.data.get('threads', []),
_("One or more thread ids received were invalid."),
)
if len(threads_ids) < 2:
raise MergeError(_("You have to select at least two threads to merge."))
elif len(threads_ids) > MERGE_LIMIT:
message = ungettext(
"No more than %(limit)s thread can be merged at single time.",
"No more than %(limit)s threads can be merged at single time.",
MERGE_LIMIT,
)
raise MergeError(message % {'limit': MERGE_LIMIT})
threads_tree_id = trees_map.get_tree_id_for_root(THREADS_ROOT_NAME)
threads_queryset = Thread.objects.filter(
id__in=threads_ids,
category__tree_id=threads_tree_id,
).select_related('category').order_by('-id')
threads = []
for thread in threads_queryset:
add_acl(request.user, thread)
if can_see_thread(request.user, thread):
threads.append(thread)
if len(threads) != len(threads_ids):
raise MergeError(_("One or more threads to merge could not be found."))
return threads
示例2: poll_vote_create
def poll_vote_create(request, thread, poll):
poll.make_choices_votes_aware(request.user)
allow_vote_poll(request.user, poll)
serializer = NewVoteSerializer(
data={
'choices': request.data,
},
context={
'allowed_choices': poll.allowed_choices,
'choices': poll.choices,
},
)
if not serializer.is_valid():
return Response(
{
'detail': serializer.errors['choices'][0],
},
status=400,
)
remove_user_votes(request.user, poll, serializer.data['choices'])
set_new_votes(request, poll, serializer.data['choices'])
add_acl(request.user, poll)
serialized_poll = PollSerializer(poll).data
poll.choices = list(map(presave_clean_choice, deepcopy(poll.choices)))
poll.save()
return Response(serialized_poll)
示例3: __init__
def __init__(self, request, thread, page):
try:
thread_model = thread.unwrap()
except AttributeError:
thread_model = thread
posts_queryset = self.get_queryset(request, thread_model)
list_page = paginate(
posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
paginator = pagination_dict(list_page, include_page_range=False)
posts = list(list_page.object_list)
posters = []
for post in posts:
post.category = thread.category
post.thread = thread_model
if post.poster:
posters.append(post.poster)
add_acl(request.user, posts)
make_posts_read_aware(request.user, thread_model, posts)
make_users_status_aware(request.user, posters)
if thread.category.acl['can_see_posts_likes']:
add_likes_to_posts(request.user, posts)
self._user = request.user
self.posts = posts
self.paginator = paginator
示例4: check_forum_permissions
def check_forum_permissions(self, request, forum):
if forum.special_role:
raise Http404()
add_acl(request.user, forum)
allow_see_forum(request.user, forum)
allow_browse_forum(request.user, forum)
示例5: post_editor
def post_editor(self, request, thread_pk, pk):
thread = self.get_thread(
request,
get_int_or_404(thread_pk),
read_aware=False,
subscription_aware=False
)
post = self.get_post(request, thread, get_int_or_404(pk)).model
allow_edit_post(request.user, post)
attachments = []
for attachment in post.attachment_set.order_by('-id'):
add_acl(request.user, attachment)
attachments.append(attachment)
attachments_json = AttachmentSerializer(
attachments, many=True, context={'user': request.user}).data
return Response({
'id': post.pk,
'api': post.get_api_url(),
'post': post.original,
'attachments': attachments_json,
'can_protect': bool(thread.category.acl['can_protect_posts']),
'is_protected': post.is_protected,
'poster': post.poster_name
})
示例6: __init__
def __init__(self, request, **kwargs):
self._categories = self.get_categories(request)
add_acl(request.user, self._categories)
self._model = self.get_category(request, self._categories, **kwargs)
self._subcategories = list(filter(self._model.has_child, self._categories))
self._children = list(filter(lambda s: s.parent_id == self._model.pk, self._subcategories))
示例7: clean_threads_for_merge
def clean_threads_for_merge(request):
try:
threads_ids = map(int, request.data.get('threads', []))
except (ValueError, TypeError):
raise MergeError(_("One or more thread ids received were invalid."))
if len(threads_ids) < 2:
raise MergeError(_("You have to select at least two threads to merge."))
elif len(threads_ids) > MERGE_LIMIT:
message = ungettext(
"No more than %(limit)s thread can be merged at single time.",
"No more than %(limit)s threads can be merged at single time.",
MERGE_LIMIT)
raise MergeError(message % {'limit': MERGE_LIMIT})
threads_queryset = Thread.objects.filter(
id__in=threads_ids,
category__tree_id=CATEGORIES_TREE_ID,
).select_related('category').order_by('-id')
threads = []
for thread in threads_queryset:
add_acl(request.user, thread)
if can_see_thread(request.user, thread):
threads.append(thread)
if len(threads) != len(threads_ids):
raise MergeError(_("One or more threads to merge could not be found."))
return threads
示例8: warnings
def warnings(request, profile, page=0):
warnings_qs = profile.warnings.order_by('-id')
warnings = paginate(warnings_qs, page, 5, 2)
items_left = warnings.paginator.count - warnings.end_index()
add_acl(request.user, warnings.object_list)
warning_level = get_user_warning_level(profile)
warning_level_obj = get_user_warning_obj(profile)
active_warnings = warning_level - warnings.start_index() + 1
for warning in warnings.object_list:
if warning.is_canceled:
warning.is_active = False
else:
warning.is_active = active_warnings > 0
active_warnings -= 1
levels_total = len(get_warning_levels()) - 1
if levels_total and warning_level:
warning_progress = 100 - warning_level * 100 / levels_total
else:
warning_progress = 100
if warning_level:
warning_level_obj.level = warning_level
return render(request, 'misago/profile/warnings.html', {
'profile': profile,
'warnings': warnings,
'warning_level': warning_level_obj,
'warning_progress': warning_progress,
'page_number': warnings.number,
'items_left': items_left
})
示例9: 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)
示例10: get_initial_attachments
def get_initial_attachments(self, mode, user, post):
attachments = []
if mode == PostingEndpoint.EDIT:
queryset = post.attachment_set.select_related('filetype')
attachments = list(queryset)
add_acl(user, attachments)
return attachments
示例11: create
def create(self, request, thread_pk):
thread = self.get_thread_for_update(request, thread_pk)
allow_start_poll(request.user, thread)
try:
if thread.poll and thread.poll.pk:
raise PermissionDenied(_("There's already a poll in this thread."))
except Poll.DoesNotExist:
pass
instance = Poll(
thread=thread,
category=thread.category,
poster=request.user,
poster_name=request.user.username,
poster_slug=request.user.slug,
poster_ip=request.user_ip,
)
serializer = NewPollSerializer(instance, data=request.data)
if serializer.is_valid():
serializer.save()
add_acl(request.user, instance)
for choice in instance.choices:
choice['selected'] = False
return Response(PollSerializer(instance).data)
else:
return Response(serializer.errors, status=400)
示例12: _test_thread_read
def _test_thread_read(self):
"""thread read flag is set for user, then its set as unread by reply"""
self.reply_thread(self.thread)
add_acl(self.user, self.categories)
threadstracker.make_read_aware(self.user, self.thread)
self.assertFalse(self.thread.is_read)
threadstracker.read_thread(self.user, self.thread, self.post)
threadstracker.make_read_aware(self.user, self.thread)
self.assertTrue(self.thread.is_read)
categoriestracker.make_read_aware(self.user, self.categories)
self.assertTrue(self.category.is_read)
self.thread.last_post_on = timezone.now()
self.thread.save()
self.category.synchronize()
self.category.save()
self.reply_thread()
threadstracker.make_read_aware(self.user, self.thread)
self.assertFalse(self.thread.is_read)
categoriestracker.make_read_aware(self.user, self.categories)
self.assertFalse(self.category.is_read)
posts = [post for post in self.thread.post_set.order_by('id')]
threadstracker.make_posts_read_aware(self.user, self.thread, posts)
for post in posts[:-1]:
self.assertTrue(post.is_read)
self.assertFalse(posts[-1].is_read)
示例13: clean
def clean(self):
data = super(MovePostsForm, self).clean()
new_thread_url = data.get('new_thread_url')
try:
if not new_thread_url:
raise Http404()
resolution = resolve(urlparse(new_thread_url).path)
if not 'thread_id' in resolution.kwargs:
raise Http404()
queryset = Thread.objects.select_related('forum')
self.new_thread = queryset.get(id=resolution.kwargs['thread_id'])
add_acl(self.user, self.new_thread.forum)
add_acl(self.user, self.new_thread)
allow_see_forum(self.user, self.new_thread.forum)
allow_browse_forum(self.user, self.new_thread.forum)
allow_see_thread(self.user, self.new_thread)
except (Http404, Thread.DoesNotExist):
message = _("You have to enter valid link to thread.")
raise forms.ValidationError(message)
if self.thread == self.new_thread:
message = _("New thread is same as current one.")
raise forms.ValidationError(message)
if self.new_thread.forum.special_role:
message = _("You can't move posts to special threads.")
raise forms.ValidationError(message)
return data
示例14: __init__
def __init__(self, request, thread, page):
posts_queryset = self.get_queryset(request, thread.model)
list_page = paginate(posts_queryset, page, settings.MISAGO_POSTS_PER_PAGE, settings.MISAGO_POSTS_TAIL)
paginator = pagination_dict(list_page, include_page_range=False)
posts = list(list_page.object_list)
posters = []
for post in posts:
post.category = thread.category
post.thread = thread.model
if post.poster:
posters.append(post.poster)
add_acl(request.user, posts)
make_posts_read_aware(request.user, thread.model, posts)
make_users_status_aware(request.user, posters)
self._user = request.user
self.posts = posts
self.paginator = paginator
示例15: patch_acl
def patch_acl(request, event, value):
"""useful little op that updates event acl to current state"""
if value:
add_acl(request.user, event)
return {'acl': event.acl}
else:
return {'acl': None}