• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python acl.add_acl函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中misago.acl.add_acl函数的典型用法代码示例。如果您正苦于以下问题:Python add_acl函数的具体用法?Python add_acl怎么用?Python add_acl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add_acl函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:33,代码来源:merge.py


示例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)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:33,代码来源:pollvotecreateendpoint.py


示例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
开发者ID:1905410,项目名称:Misago,代码行数:34,代码来源:posts.py


示例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)
开发者ID:Backenkoehler,项目名称:Misago,代码行数:7,代码来源:base.py


示例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
        })
开发者ID:l0ud,项目名称:Misago,代码行数:27,代码来源:threadposts.py


示例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))
开发者ID:l0ud,项目名称:Misago,代码行数:7,代码来源:category.py


示例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
开发者ID:mayblue9,项目名称:Misago,代码行数:30,代码来源:merge.py


示例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
    })
开发者ID:David1119,项目名称:Misago,代码行数:35,代码来源:profile.py


示例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)
开发者ID:David1119,项目名称:Misago,代码行数:26,代码来源:profile.py


示例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
开发者ID:l0ud,项目名称:Misago,代码行数:7,代码来源:attachments.py


示例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)
开发者ID:1905410,项目名称:Misago,代码行数:30,代码来源:threadpoll.py


示例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)
开发者ID:fengrussell,项目名称:Misago,代码行数:31,代码来源:test_readtracker.py


示例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
开发者ID:Backenkoehler,项目名称:Misago,代码行数:35,代码来源:moderation.py


示例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
开发者ID:l0ud,项目名称:Misago,代码行数:25,代码来源:posts.py


示例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}
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:7,代码来源:patch_event.py


示例16: __init__

    def __init__(self, request, category, list_type, page):
        self.allow_see_list(request, category, list_type)

        base_queryset = self.get_base_queryset(request, category.categories, list_type)
        threads_categories = [category.category] + category.subcategories

        threads_queryset = self.get_remaining_threads_queryset(base_queryset, category.category, threads_categories)

        list_page = paginate(threads_queryset, page, settings.MISAGO_THREADS_PER_PAGE, settings.MISAGO_THREADS_TAIL)
        paginator = pagination_dict(list_page, include_page_range=False)

        if list_page.number > 1:
            threads = list(list_page.object_list)
        else:
            pinned_threads = list(self.get_pinned_threads(base_queryset, category.category, threads_categories))
            threads = list(pinned_threads) + list(list_page.object_list)

        if list_type in ('new', 'unread'):
            # we already know all threads on list are unread
            threadstracker.make_unread(threads)
        else:
            threadstracker.make_threads_read_aware(request.user, threads)

        add_categories_to_threads(category.category, category.categories, threads)
        add_acl(request.user, threads)
        make_subscription_aware(request.user, threads)

        # set state on object for easy access from hooks
        self.category = category
        self.threads = threads
        self.list_type = list_type
        self.paginator = paginator
开发者ID:h094071,项目名称:Misago,代码行数:32,代码来源:threads.py


示例17: get_categories_tree

def get_categories_tree(user, parent=None):
    if not user.acl['visible_categories']:
        return []

    if parent:
        queryset = parent.get_descendants().order_by('lft')
    else:
        queryset = Category.objects.all_categories()

    queryset_with_acl = queryset.filter(id__in=user.acl['visible_categories'])
    visible_categories = list(queryset_with_acl)

    categories_dict = {}
    categories_list = []

    parent_level = parent.level + 1 if parent else 1

    for category in visible_categories:
        category.subcategories = []
        categories_dict[category.pk] = category
        categories_list.append(category)

        if category.parent_id and category.level > parent_level:
            categories_dict[category.parent_id].subcategories.append(category)

    add_acl(user, categories_list)
    categoriestracker.make_read_aware(user, categories_list)

    for category in reversed(visible_categories):
        if category.acl['can_browse']:
            category.parent = categories_dict.get(category.parent_id)
            if category.parent:
                category.parent.threads += category.threads
                category.parent.posts += category.posts

                if category.parent.last_post_on and category.last_post_on:
                    parent_last_post = category.parent.last_post_on
                    category_last_post = category.last_post_on
                    update_last_thead = parent_last_post < category_last_post
                elif not category.parent.last_post_on and category.last_post_on:
                    update_last_thead = True
                else:
                    update_last_thead = False

                if update_last_thead:
                    category.parent.last_post_on = category.last_post_on
                    category.parent.last_thread_id = category.last_thread_id
                    category.parent.last_thread_title = category.last_thread_title
                    category.parent.last_thread_slug = category.last_thread_slug
                    category.parent.last_poster_name = category.last_poster_name
                    category.parent.last_poster_slug = category.last_poster_slug

                if not category.is_read:
                    category.parent.is_read = False

    flat_list = []
    for category in categories_list:
        if category.level == parent_level:
            flat_list.append(category)
    return flat_list
开发者ID:Didan,项目名称:Misago,代码行数:60,代码来源:utils.py


示例18: get_posts

    def get_posts(self, user, forum, thread, kwargs):
        queryset = self.get_posts_queryset(user, forum, thread)
        queryset = self.exclude_invisible_posts(queryset, user, forum, thread)
        page = paginate(queryset, kwargs.get('page', 0),
                        settings.MISAGO_POSTS_PER_PAGE,
                        settings.MISAGO_THREAD_TAIL)

        posts = []
        for post in page.object_list:
            post.forum = forum
            post.thread = thread

            add_acl(user, post)

            if post.poster:
                poster_state = get_user_state(post.poster, user.acl)
                post.poster.online_state = poster_state
            posts.append(post)

        if page.next_page_first_item:
            add_events_to_posts(
                user, thread, posts, page.next_page_first_item.posted_on)
        else:
            add_events_to_posts(user, thread, posts)

        return page, posts
开发者ID:Backenkoehler,项目名称:Misago,代码行数:26,代码来源:view.py


示例19: patch_acl

def patch_acl(request, thread, value):
    """useful little op that updates thread acl to current state"""
    if value:
        add_acl(request.user, thread)
        return {'acl': thread.acl}
    else:
        return {'acl': None}
开发者ID:1905410,项目名称:Misago,代码行数:7,代码来源:patch.py


示例20: test_sync_record_for_empty_category

    def test_sync_record_for_empty_category(self):
        """sync_record sets read flag on empty category"""
        add_acl(self.user, self.categories)
        categoriestracker.sync_record(self.user, self.category)
        self.user.categoryread_set.get(category=self.category)

        categoriestracker.make_read_aware(self.user, self.categories)
        self.assertTrue(self.category.is_read)
开发者ID:fengrussell,项目名称:Misago,代码行数:8,代码来源:test_readtracker.py



注:本文中的misago.acl.add_acl函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python algebra.sum_acls函数代码示例发布时间:2022-05-27
下一篇:
Python lib.get_host函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap