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

Python bans.get_user_ban函数代码示例

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

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



在下文中一共展示了get_user_ban函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_expired_ban

    def test_expired_ban(self):
        """user is not caught by expired ban"""
        Ban.objects.create(banned_value='bo*',
                           expires_on=timezone.now() - timedelta(days=7))

        self.assertIsNone(get_user_ban(self.user))
        self.assertFalse(self.user.ban_cache.is_banned)
开发者ID:CAvancouver,项目名称:Misago,代码行数:7,代码来源:test_bans.py


示例2: test_expired_ban

    def test_expired_ban(self):
        """user is not caught by expired ban"""
        Ban.objects.create(banned_value='bo*',
                           valid_until=date.today() - timedelta(days=7))

        self.assertIsNone(get_user_ban(self.user))
        self.assertFalse(self.user.ban_cache.is_banned)
开发者ID:dahito,项目名称:Misago,代码行数:7,代码来源:test_bans.py


示例3: process_request

 def process_request(self, request):
     if request.user.is_anonymous():
         request.user = AnonymousUser()
     elif not request.user.is_superuser:
         if get_request_ip_ban(request) or get_user_ban(request.user):
             logout(request)
     request.user.ip = request._misago_real_ip
开发者ID:ChristosChristofidis,项目名称:Misago,代码行数:7,代码来源:middleware.py


示例4: reset_password_form

def reset_password_form(request, user_id, token):
    User = get_user_model()
    requesting_user = get_object_or_404(User.objects, pk=user_id)

    try:
        if (request.user.is_authenticated() and
                request.user.id != requesting_user.id):
            message = _("%(user)s, your link has expired. "
                        "Please request new link and try again.")
            message = message % {'user': requesting_user.username}
            raise ResetError(message)

        if not is_password_change_token_valid(requesting_user, token):
            message = _("%(user)s, your link is invalid. "
                        "Please try again or request new link.")
            message = message % {'user': requesting_user.username}
            raise ResetError(message)

        ban = get_user_ban(requesting_user)
        if ban:
            raise Banned(ban)
    except ResetError as e:
        return render(request, 'misago/forgottenpassword/error.html', {
                'message': e.args[0],
            }, status=400)

    api_url = reverse('misago:api:change_forgotten_password', kwargs={
        'user_id': user_id,
        'token': token,
    })

    request.frontend_context['CHANGE_PASSWORD_API_URL'] = api_url
    return render(request, 'misago/forgottenpassword/form.html')
开发者ID:Thuruv,项目名称:Misago,代码行数:33,代码来源:forgottenpassword.py


示例5: activate_by_token

def activate_by_token(request, user_id, token):
    User = get_user_model()
    inactive_user = get_object_or_404(User.objects, pk=user_id)

    try:
        if not inactive_user.requires_activation:
            message = _("%(user)s, your account is already active.")
            message = message % {"user": inactive_user.username}
            raise ActivationStopped(message)

        if not is_activation_token_valid(inactive_user, token):
            message = _("%(user)s, your activation link is invalid. " "Try again or request new activation link.")
            message = message % {"user": inactive_user.username}
            raise ActivationError(message)

        ban = get_user_ban(inactive_user)
        if ban:
            raise Banned(ban)
    except ActivationStopped as e:
        return render(request, "misago/activation/stopped.html", {"message": e.args[0]})
    except ActivationError as e:
        return render(request, "misago/activation/error.html", {"message": e.args[0]}, status=400)

    inactive_user.requires_activation = ACTIVATION_REQUIRED_NONE
    inactive_user.save(update_fields=["requires_activation"])

    message = _("%(user)s, your account has been activated!")

    return render(request, "misago/activation/done.html", {"message": message % {"user": inactive_user.username}})
开发者ID:Thuruv,项目名称:Misago,代码行数:29,代码来源:activation.py


示例6: get_context_data

    def get_context_data(self, request, profile):
        ban = get_user_ban(profile)

        request.frontend_context['PROFILE_BAN'] = BanDetailsSerializer(ban).data

        return {
            'ban': ban,
        }
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:8,代码来源:profile.py


示例7: user_ban

def user_ban(request, profile):
    ban = get_user_ban(profile)

    request.frontend_context['PROFILE_BAN'] = ban.get_serialized_message()

    return render(request, 'misago/profile/ban_details.html', {
        'profile': profile,
        'ban': ban,
    })
开发者ID:nescode,项目名称:Misago,代码行数:9,代码来源:profile.py


示例8: test_permanent_ban

    def test_permanent_ban(self):
        """user is caught by permanent ban"""
        Ban.objects.create(banned_value="bob", user_message="User reason", staff_message="Staff reason")

        user_ban = get_user_ban(self.user)
        self.assertIsNotNone(user_ban)
        self.assertEqual(user_ban.user_message, "User reason")
        self.assertEqual(user_ban.staff_message, "Staff reason")
        self.assertTrue(self.user.ban_cache.is_banned)
开发者ID:ZerGabriel,项目名称:Misago,代码行数:9,代码来源:test_bans.py


示例9: user_ban

def user_ban(request, profile):
    ban = get_user_ban(profile)
    if not ban:
        raise Http404()

    return render(request, 'misago/profile/ban_details.html', {
        'profile': profile,
        'ban': ban
    })
开发者ID:David1119,项目名称:Misago,代码行数:9,代码来源:profile.py


示例10: ban

    def ban(self, request, pk=None):
        profile = self.get_user(pk)
        allow_see_ban_details(request.user, profile)

        ban = get_user_ban(profile)
        if (ban):
            return Response(BanDetailsSerializer(ban).data)
        else:
            return Response({})
开发者ID:Didan,项目名称:Misago,代码行数:9,代码来源:users.py


示例11: user_ban

def user_ban(request, profile):
    ban = get_user_ban(profile)

    request.frontend_context['PROFILE_BAN'] = BanDetailsSerializer(ban).data

    return render(request, 'misago/profile/ban_details.html', {
        'profile': profile,
        'ban': ban,
    })
开发者ID:mayblue9,项目名称:Misago,代码行数:9,代码来源:profile.py


示例12: can_see_ban_details

 def can_see_ban_details(request, profile):
     if request.user.is_authenticated():
         if request.user.acl['can_see_ban_details']:
             from misago.users.bans import get_user_ban
             return bool(get_user_ban(profile))
         else:
             return False
     else:
         return False
开发者ID:Backenkoehler,项目名称:Misago,代码行数:9,代码来源:apps.py


示例13: test_ban_user

    def test_ban_user(self):
        """ban_user utility bans user"""
        user = UserModel.objects.create_user('Bob', '[email protected]', 'pass123')

        ban = ban_user(user, 'User reason', 'Staff reason')
        self.assertEqual(ban.user_message, 'User reason')
        self.assertEqual(ban.staff_message, 'Staff reason')

        db_ban = get_user_ban(user)
        self.assertEqual(ban.pk, db_ban.ban_id)
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:10,代码来源:test_bans.py


示例14: test_ban_user

    def test_ban_user(self):
        """ban_user bans user"""
        User = get_user_model()
        user = User.objects.create_user("Bob", "[email protected]", "pass123")

        ban = ban_user(user, "User reason", "Staff reason")
        self.assertEqual(ban.user_message, "User reason")
        self.assertEqual(ban.staff_message, "Staff reason")

        db_ban = get_user_ban(user)
        self.assertEqual(ban.pk, db_ban.ban_id)
开发者ID:ZerGabriel,项目名称:Misago,代码行数:11,代码来源:test_bans.py


示例15: test_temporary_ban

    def test_temporary_ban(self):
        """user is caught by temporary ban"""
        Ban.objects.create(banned_value='bo*',
                           user_message='User reason',
                           staff_message='Staff reason',
                           expires_on=timezone.now() + timedelta(days=7))

        user_ban = get_user_ban(self.user)
        self.assertIsNotNone(user_ban)
        self.assertEqual(user_ban.user_message, 'User reason')
        self.assertEqual(user_ban.staff_message, 'Staff reason')
        self.assertTrue(self.user.ban_cache.is_banned)
开发者ID:CAvancouver,项目名称:Misago,代码行数:12,代码来源:test_bans.py


示例16: test_bans_caches_updates

    def test_bans_caches_updates(self):
        """ban caches are updated"""
        # create user
        User = get_user_model()
        user = User.objects.create_user("Bob", "[email protected]", "Pass.123")

        # ban user
        Ban.objects.create(banned_value="bob")
        user_ban = bans.get_user_ban(user)

        self.assertIsNotNone(user_ban)
        self.assertEqual(Ban.objects.filter(is_valid=True).count(), 1)

        # first call didn't touch ban
        command = bansmaintenance.Command()

        out = StringIO()
        command.execute(stdout=out)
        command_output = out.getvalue().splitlines()[1].strip()

        self.assertEqual(command_output, 'Ban caches emptied: 0')
        self.assertEqual(Ban.objects.filter(is_valid=True).count(), 1)

        # expire bans
        bans_expired = (timezone.now() - timedelta(days=10)).date()
        Ban.objects.all().update(valid_until=bans_expired, is_valid=True)
        BanCache.objects.all().update(valid_until=bans_expired)

        # invalidate expired ban cache
        out = StringIO()
        command.execute(stdout=out)
        command_output = out.getvalue().splitlines()[1].strip()

        self.assertEqual(command_output, 'Ban caches emptied: 1')
        self.assertEqual(Ban.objects.filter(is_valid=True).count(), 0)

        # see if user is banned anymore
        user = User.objects.get(id=user.id)
        self.assertIsNone(bans.get_user_ban(user))
开发者ID:jinchaoh,项目名称:Misago,代码行数:39,代码来源:test_bansmaintenance.py


示例17: lift_user_ban

def lift_user_ban(request, user):
    return_path = moderation_return_path(request, user)

    user_ban = get_user_ban(user).ban
    user_ban.lift()
    user_ban.save()

    Ban.objects.invalidate_cache()

    message = _("%(user)s's ban has been lifted.")
    messages.success(request, message % {'user': user.username})

    return redirect(return_path)
开发者ID:ZerGabriel,项目名称:Misago,代码行数:13,代码来源:moderation.py


示例18: allow_lift_ban

def allow_lift_ban(user, target):
    if not user.acl_cache['can_lift_bans']:
        raise PermissionDenied(_("You can't lift bans."))
    ban = get_user_ban(target)
    if not ban:
        raise PermissionDenied(_("This user is not banned."))
    if user.acl_cache['max_lifted_ban_length']:
        expiration_limit = timedelta(days=user.acl_cache['max_lifted_ban_length'])
        lift_cutoff = (timezone.now() + expiration_limit).date()
        if not ban.valid_until:
            raise PermissionDenied(_("You can't lift permanent bans."))
        elif ban.valid_until > lift_cutoff:
            message = _("You can't lift bans that expire after %(expiration)s.")
            raise PermissionDenied(message % {'expiration': format_date(lift_cutoff)})
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:14,代码来源:moderation.py


示例19: reset_password_form

def reset_password_form(request, user_id, token):
    User = get_user_model()
    requesting_user = get_object_or_404(User.objects, pk=user_id)

    try:
        if requesting_user.requires_activation_by_admin:
            message = _(
                "%(user)s, administrator has to activate your "
                "account before you will be able to request "
                "new password."
            )
            message = message % {"user": requesting_user.username}
            raise ResetStopped(message)
        if requesting_user.requires_activation_by_user:
            message = _(
                "%(user)s, you have to activate your account " "before you will be able to request new password."
            )
            message = message % {"user": requesting_user.username}
            raise ResetStopped(message)
        if get_user_ban(requesting_user):
            message = _("%(user)s, your account is banned " "and it's password can't be changed.")
            message = message % {"user": requesting_user.username}
            raise ResetError(message)
        if not is_password_reset_token_valid(requesting_user, token):
            message = _("%(user)s, your link is invalid. " "Try again or request new link.")
            message = message % {"user": requesting_user.username}
            raise ResetError(message)
    except ResetStopped as e:
        messages.info(request, e.args[0])
        return redirect("misago:index")
    except ResetError as e:
        messages.error(request, e.args[0])
        return redirect("misago:request_password_reset")

    form = SetNewPasswordForm()
    if request.method == "POST":
        form = SetNewPasswordForm(request.POST)
        if form.is_valid():
            requesting_user.set_password(form.cleaned_data["new_password"])
            requesting_user.save(update_fields=["password"])

            message = _("%(user)s, your password has been changed.")
            message = message % {"user": requesting_user.username}
            messages.success(request, message)
            return redirect(settings.LOGIN_URL)

    return render(
        request, "misago/forgottenpassword/reset_password_form.html", {"requesting_user": requesting_user, "form": form}
    )
开发者ID:sun5495,项目名称:Misago,代码行数:49,代码来源:forgottenpassword.py


示例20: get_user_status

def get_user_status(viewer, user):
    user_status = {
        'is_banned': False,
        'is_hidden': user.is_hiding_presence,
        'is_online_hidden': False,
        'is_offline_hidden': False,
        'is_online': False,
        'is_offline': False,
        'banned_until': None,
        'last_click': user.last_login or user.joined_on,
    }

    user_ban = get_user_ban(user)
    if user_ban:
        user_status['is_banned'] = True
        user_status['banned_until'] = user_ban.expires_on

    try:
        online_tracker = user.online_tracker
        is_hidden = user.is_hiding_presence and not viewer.acl_cache['can_see_hidden_users']

        if online_tracker and not is_hidden:
            if online_tracker.last_click >= timezone.now() - ACTIVITY_CUTOFF:
                user_status['is_online'] = True
                user_status['last_click'] = online_tracker.last_click
    except Online.DoesNotExist:
        pass

    if user_status['is_hidden']:
        if viewer.acl_cache['can_see_hidden_users']:
            user_status['is_hidden'] = False
            if user_status['is_online']:
                user_status['is_online_hidden'] = True
                user_status['is_online'] = False
            else:
                user_status['is_offline_hidden'] = True
                user_status['is_offline'] = False
        else:
            user_status['is_hidden'] = True
    else:
        if user_status['is_online']:
            user_status['is_online'] = True
        else:
            user_status['is_offline'] = True

    return user_status
开发者ID:dasdsadadaddasa,项目名称:PythonScientists,代码行数:46,代码来源:utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python strings.slugify函数代码示例发布时间:2022-05-27
下一篇:
Python testutils.reply_thread函数代码示例发布时间: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