本文整理汇总了Python中pybb.compat.get_user_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_model函数的具体用法?Python get_user_model怎么用?Python get_user_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_model函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:magatz,项目名称:pybbm,代码行数:7,代码来源:util.py
示例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()
开发者ID:bastianh,项目名称:pybbm,代码行数:7,代码来源:util.py
示例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))
开发者ID:thoas,项目名称:pybbm,代码行数:11,代码来源:test_models.py
示例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()
开发者ID:thoas,项目名称:pybbm,代码行数:32,代码来源:models.py
示例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
开发者ID:thoas,项目名称:pybbm,代码行数:7,代码来源:base.py
示例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)
开发者ID:magatz,项目名称:pybbm-1,代码行数:25,代码来源:tests.py
示例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
开发者ID:magatz,项目名称:pybbm-1,代码行数:25,代码来源:helpers.py
示例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())
开发者ID:DylannCordel,项目名称:pybbm,代码行数:8,代码来源:signals.py
示例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)
开发者ID:ChrisFreeman,项目名称:pdxcodeguild.com,代码行数:11,代码来源:supermoderator.py
示例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()
开发者ID:ugoertz,项目名称:pybbm,代码行数:11,代码来源:signals.py
示例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))
开发者ID:magatz,项目名称:pybbm-1,代码行数:12,代码来源:tests.py
示例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))
开发者ID:thoas,项目名称:pybbm,代码行数:13,代码来源:test_models.py
示例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
开发者ID:ChrisFreeman,项目名称:pdxcodeguild.com,代码行数:13,代码来源:util.py
示例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)
开发者ID:thoas,项目名称:pybbm,代码行数:13,代码来源:test_anonymous.py
示例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))
开发者ID:thoas,项目名称:pybbm,代码行数:16,代码来源:test_models.py
示例16: quote
def quote(tag_name, value, options, parent, context):
if 'quote' not in options:
return value
splits = options['quote'].split(';')
try:
username, post_id = splits
post_id = int(post_id)
except ValueError:
if len(splits) == 1:
return settings.PYBB_QUOTES_QUOTE_MINIMAL_FORMAT % {
'message': value,
'username': splits[0],
}
return settings.PYBB_QUOTES_QUOTE_BASIC_FORMAT % {
'message': value,
}
try:
post = Post.objects.get(pk=post_id)
user = post.user
except (Post.DoesNotExist, get_user_model().DoesNotExist):
return settings.PYBB_QUOTES_QUOTE_MINIMAL_FORMAT % {
'message': value,
'username': splits[0],
}
if 'obj' in context and context['obj']:
current_post = context['obj']
if current_post.user:
quoted.send(sender=current_post.__class__,
user=current_post.user,
from_post=current_post,
to_post=post)
return settings.PYBB_QUOTES_QUOTE_VALID_FORMAT % {
'user_url': settings.PYBB_QUOTES_USER_URL(user),
'message': value,
'username': username,
'post_url': settings.PYBB_QUOTES_POST_URL(post) # anonymous anchor url
}
开发者ID:magatz,项目名称:pybbm-1,代码行数:45,代码来源:formatters.py
示例17: test_subscription
def test_subscription(self):
user = get_user_model().objects.create_user(username='user2', password='user2', email='[email protected]')
client = Client()
client.login(username='user2', password='user2')
response = client.post(reverse('pybb:subscription_create'), data={
'topic_id': self.topic.pk,
'type': Subscription.TYPE_INSTANT_ALERT
})
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, self.topic.get_absolute_url())
self.assertTrue(user in list(self.topic.subscribers.all()))
new_post = Post(topic=self.topic, user=self.user, body='test subscribtion юникод')
new_post.save()
self.assertTrue([msg for msg in mail.outbox if new_post.get_absolute_url() in msg.body])
response = client.post(reverse('pybb:subscription_delete'), data={
'topic_id': self.topic.pk
})
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, self.topic.get_absolute_url())
self.assertTrue(user not in list(self.topic.subscribers.all()))
开发者ID:thoas,项目名称:pybbm,代码行数:20,代码来源:test_features.py
示例18: mention
def mention(tag_name, value, options, parent, context):
User = get_user_model()
if 'mention' not in options:
return settings.PYBB_MENTIONS_MENTION_FORMAT_WITHOUT_USER % {
'username': value
}
user_id = options['mention']
try:
user = User.objects.get(pk=user_id)
except (User.DoesNotExist, ValueError):
return settings.PYBB_MENTIONS_MENTION_FORMAT_WITHOUT_USER % {
'username': value
}
else:
if 'obj' in context and context['obj'] and context['obj'].user:
mentioned.send(sender=User, user=user, post=context['obj'])
return settings.PYBB_MENTIONS_MENTION_FORMAT_WITH_USER % {
'user_url': settings.PYBB_MENTIONS_USER_URL(user),
'username': value
}
开发者ID:magatz,项目名称:pybbm-1,代码行数:24,代码来源:formatters.py
示例19: get_queryset
def get_queryset(self):
return get_user_model().objects.all()
开发者ID:magatz,项目名称:pybbm-1,代码行数:2,代码来源:views.py
示例20: AttachmentForm
from __future__ import unicode_literals
import re
import inspect
from django import forms
from django.core.exceptions import FieldError
from django.forms.models import inlineformset_factory, BaseInlineFormSet
from django.utils.translation import ugettext, ugettext_lazy
from django.utils.timezone import now as tznow
from pybb import compat, defaults, util
from pybb.models import Topic, Post, Attachment, PollAnswer
User = compat.get_user_model()
username_field = compat.get_username_field()
class AttachmentForm(forms.ModelForm):
class Meta(object):
model = Attachment
fields = ('file', )
def clean_file(self):
if self.cleaned_data['file'].size > defaults.PYBB_ATTACHMENT_SIZE_LIMIT:
raise forms.ValidationError(ugettext('Attachment is too big'))
return self.cleaned_data['file']
AttachmentFormSet = inlineformset_factory(Post, Attachment, extra=1, form=AttachmentForm)
开发者ID:DylannCordel,项目名称:pybbm,代码行数:29,代码来源:forms.py
注:本文中的pybb.compat.get_user_model函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论