本文整理汇总了Python中pybb.compat.get_user_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_model函数的具体用法?Python get_user_model怎么用?Python get_user_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pybb_profile_model
def get_pybb_profile_model():
from pybb import defaults
if defaults.PYBB_PROFILE_RELATED_NAME:
return getattr(get_user_model(), defaults.PYBB_PROFILE_RELATED_NAME).related.field.model
else:
return get_user_model()
示例2: get_pybb_profile_model
def get_pybb_profile_model():
from pybb import defaults
if defaults.PYBB_PROFILE_RELATED_NAME:
return compat.get_related_model_class(get_user_model(), defaults.PYBB_PROFILE_RELATED_NAME)
else:
return get_user_model()
示例3: test_post_in_category_hidden_is_accessible_by_unauthenticated_user
def test_post_in_category_hidden_is_accessible_by_unauthenticated_user(self):
self.parent_forum.hidden = True
self.parent_forum.save()
with patch.object(get_user_model(), 'is_authenticated', new_callable=PropertyMock, return_value=False):
self.assertFalse(self.post.is_accessible_by(self.newbie))
with patch.object(get_user_model(), 'is_authenticated', new_callable=PropertyMock, return_value=True):
self.assertTrue(self.post.is_accessible_by(self.user))
self.assertTrue(self.post.is_accessible_by(self.staff))
self.assertTrue(self.post.is_accessible_by(self.superuser))
示例4: handle_user_logged_in
def handle_user_logged_in(sender, request, user, **kwargs):
from pybb.compat import get_user_model
User = get_user_model()
try:
BannedUser.objects.get(user=user)
except BannedUser.DoesNotExist:
value = request.COOKIES.get(settings.PYBB_BAN_COOKIE_NAME, None)
banned_user = None
if value:
try:
existing_user = User.objects.get(pk=int(value))
except (User.DoesNotExist, ValueError):
banned_user = BannedUser(user=user,
reason=_('Cookie exists: user already banned from anonymous account'))
else:
banned_user = BannedUser(user=user,
reason=_('Cookie exists: user already banned for the account %s') % existing_user)
ip_address = get_ip(request)
exists = IPAddress.objects.filter(ip_address=ip_address, banned=True).exists()
if exists:
banned_user = BannedUser(user=user,
reason=_('IP Address %s is banned') % ip_address)
if banned_user:
banned_user.save()
示例5: superuser
def superuser(self):
superuser = get_user_model().objects.create_user('oleiade', '[email protected]', '$ecret')
superuser.is_superuser = True
superuser.is_staff = True
superuser.save()
return superuser
示例6: test_ban_middelware
def test_ban_middelware(self):
from pybb.compat import get_user_model
with patch.object(get_user_model(), 'is_authenticated') as is_authenticated:
is_authenticated.return_value = True
factory = RequestFactory(REMOTE_ADDR='199.59.149.230')
request = factory.get('/post/1')
request.user = self.user
request.session = {}
middleware = PybbBanMiddleware()
middleware.process_request(request)
self.assertEqual(IPAddress.objects.filter(user=self.user, ip_address='199.59.149.230').count(), 1)
ip_address = IPAddress.objects.get(user=self.user, ip_address='199.59.149.230')
ip_address.banned = True
ip_address.save()
middleware = PybbBanMiddleware()
response = middleware.process_request(request)
self.assertEqual(int(response.cookies[settings.PYBB_BAN_COOKIE_NAME].value), self.user.pk)
示例7: lookup_users
def lookup_users(qs):
user_ids = queryset_to_dict(qs, key='user_id', singular=False)
users = queryset_to_dict(get_user_model().objects.filter(id__in=user_ids.keys()))
try:
Profile = get_profile_model()
profiles = queryset_to_dict(Profile.objects.filter(user__in=users.keys()), key='user_id')
except SiteProfileNotAvailable:
profiles = {}
for user_id, objs in user_ids.iteritems():
if user_id in users:
user = users[user_id]
for obj in objs:
obj.user = user
if user_id in profiles:
obj.user._profile_cache = profiles[user_id]
obj.user._profile_cache.user = obj.user
else:
for obj in objs:
obj.user_id = None
示例8: setup
def setup():
pre_save.connect(pre_save_category_slug, sender=Category)
pre_save.connect(pre_save_forum_slug, sender=Forum)
pre_save.connect(pre_save_topic_slug, sender=Topic)
post_save.connect(post_saved, sender=Post)
post_delete.connect(post_deleted, sender=Post)
if defaults.PYBB_AUTO_USER_PERMISSIONS:
post_save.connect(user_saved, sender=compat.get_user_model())
示例9: handle
def handle(self, *args, **kwargs):
if len(args) != 2:
raise CommandError("Enter action {add|del} and username")
action, username = args
assert action in ('add', 'del')
user = compat.get_user_model().objects.get(**{compat.get_username_field(): username})
forums = Forum.objects.all()
for forum in forums:
forum.moderators.remove(user)
if action == 'add':
forum.moderators.add(user)
示例10: post_deleted
def post_deleted(instance, **kwargs):
Profile = util.get_pybb_profile_model()
User = compat.get_user_model()
try:
profile = util.get_pybb_profile(instance.user)
except (Profile.DoesNotExist, User.DoesNotExist) as e:
#When we cascade delete an user, profile and posts are also deleted
pass
else:
profile.post_count = instance.user.posts.count()
profile.save()
示例11: test_post_in_forum_hidden_is_accessible_by_unauthenticated_user
def test_post_in_forum_hidden_is_accessible_by_unauthenticated_user(self):
self.forum.hidden = True
self.forum.save()
with patch.object(get_user_model(), 'is_authenticated') as is_authenticated:
is_authenticated.return_value = False
self.assertFalse(self.post.is_accessible_by(self.newbie))
self.assertTrue(self.post.is_accessible_by(self.user))
self.assertTrue(self.post.is_accessible_by(self.staff))
self.assertTrue(self.post.is_accessible_by(self.superuser))
示例12: test_post_editable_by_moderator_with_permission
def test_post_editable_by_moderator_with_permission(self):
self.assertFalse(self.post.is_editable_by(self.newbie))
Moderator.objects.create(forum=self.post.topic.forum, user=self.newbie)
self.assertFalse(self.post.is_editable_by(self.newbie, 'can_change_post'))
UserObjectPermission.objects.assign_perm('can_change_post', self.newbie, obj=self.post.topic.forum)
self.post = Post.objects.get(pk=self.post.pk)
with patch.object(get_user_model(), 'is_authenticated', new_callable=PropertyMock, return_value=True):
self.assertTrue(self.post.is_editable_by(self.newbie))
示例13: get_pybb_profile
def get_pybb_profile(user):
from pybb import defaults
if not user.is_authenticated():
if defaults.PYBB_ENABLE_ANONYMOUS_POST:
user = get_user_model().objects.get(**{get_username_field(): defaults.PYBB_ANONYMOUS_USERNAME})
else:
raise ValueError(_('Can\'t get profile for anonymous user'))
if defaults.PYBB_PROFILE_RELATED_NAME:
return getattr(user, defaults.PYBB_PROFILE_RELATED_NAME)
else:
return user
示例14: setUp
def setUp(self):
self.ORIG_PYBB_ENABLE_ANONYMOUS_POST = defaults.PYBB_ENABLE_ANONYMOUS_POST
self.ORIG_PYBB_ANONYMOUS_USERNAME = defaults.PYBB_ANONYMOUS_USERNAME
defaults.PYBB_ENABLE_ANONYMOUS_POST = True
defaults.PYBB_ANONYMOUS_USERNAME = 'Anonymous'
self.user = get_user_model().objects.create_user('Anonymous', '[email protected]', 'Anonymous')
self.parent_forum = Forum.objects.create(name='foo')
self.forum = Forum.objects.create(name='xfoo', description='bar', forum=self.parent_forum)
self.topic = Topic.objects.create(name='etopic', forum=self.forum, user=self.user)
add_post_permission = Permission.objects.get_by_natural_key('add_post', 'pybb', 'post')
self.user.user_permissions.add(add_post_permission)
示例15: test_topic_on_moderation
def test_topic_on_moderation(self):
self.post
self.topic.on_moderation = True
self.topic.save()
with patch.object(get_user_model(), 'is_authenticated', new_callable=PropertyMock, return_value=True):
self.assertTrue(self.post.is_accessible_by(self.user))
self.assertTrue(self.post.is_accessible_by(self.staff))
self.assertTrue(self.post.is_accessible_by(self.superuser))
self.assertFalse(self.post.is_accessible_by(self.newbie))
Moderator.objects.create(forum=self.post.topic.forum, user=self.newbie)
self.assertTrue(self.post.is_accessible_by(self.newbie))