本文整理汇总了Python中misago.users.bans.get_user_ban函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_ban函数的具体用法?Python get_user_ban怎么用?Python get_user_ban使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_ban函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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')
示例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}})
示例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,
}
示例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,
})
示例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)
示例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
})
示例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({})
示例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,
})
示例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
示例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)
示例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)
示例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)