本文整理汇总了Python中pybb.util.get_pybb_profile函数的典型用法代码示例。如果您正苦于以下问题:Python get_pybb_profile函数的具体用法?Python get_pybb_profile怎么用?Python get_pybb_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_pybb_profile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
def process_request(self, request):
if request.user.is_authenticated():
try:
# Here we try to load profile, but can get error
# if user created during syncdb but profile model
# under south control. (Like pybb.Profile).
profile = util.get_pybb_profile(request.user)
except ObjectDoesNotExist:
# Ok, we should create new profile for this user
# and grant permissions for add posts
# It should be caused rarely, so we move import signal here
# to prevent circular import
from pybb.models import user_saved
user_saved(request.user, created=True)
profile = util.get_pybb_profile(request.user)
language = translation.get_language_from_request(request)
if not profile.language:
profile.language = language
profile.save()
if profile.language and profile.language != language:
request.session['django_language'] = profile.language
translation.activate(profile.language)
request.LANGUAGE_CODE = translation.get_language()
示例2: post_saved
def post_saved(instance, **kwargs):
notify_topic_subscribers(instance)
if get_pybb_profile(instance.user).autosubscribe:
instance.topic.subscribers.add(instance.user)
if kwargs['created']:
profile = get_pybb_profile(instance.user)
profile.post_count = instance.user.posts.count()
profile.save()
示例3: post_saved
def post_saved(instance, **kwargs):
if not defaults.PYBB_DISABLE_NOTIFICATIONS:
notify_topic_subscribers(instance)
if util.get_pybb_profile(instance.user).autosubscribe and \
perms.may_subscribe_topic(instance.user, instance.topic):
instance.topic.subscribers.add(instance.user)
if kwargs['created']:
profile = util.get_pybb_profile(instance.user)
profile.post_count = instance.user.posts.count()
profile.save()
示例4: dispatch
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated():
self.user = request.user
else:
if defaults.PYBB_ENABLE_ANONYMOUS_POST:
self.user, new = User.objects.get_or_create(**{username_field: defaults.PYBB_ANONYMOUS_USERNAME})
else:
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.get_full_path())
self.forum = None
self.topic = None
if 'forum_id' in kwargs:
self.forum = get_object_or_404(perms.filter_forums(request.user, Forum.objects.all()), pk=kwargs['forum_id'])
if not perms.may_create_topic(self.user, self.forum):
raise PermissionDenied
elif 'topic_id' in kwargs:
self.topic = get_object_or_404(perms.filter_topics(request.user, Topic.objects.all()), pk=kwargs['topic_id'])
if not perms.may_create_post(self.user, self.topic):
raise PermissionDenied
self.quote = ''
if 'quote_id' in request.GET:
try:
quote_id = int(request.GET.get('quote_id'))
except TypeError:
raise Http404
else:
post = get_object_or_404(Post, pk=quote_id)
profile = util.get_pybb_profile(post.user)
self.quote = util._get_markup_quoter(defaults.PYBB_MARKUP)(post.body, profile.get_display_name())
if self.quote and request.is_ajax():
return HttpResponse(self.quote)
return super(AddPostView, self).dispatch(request, *args, **kwargs)
示例5: notify_topic_subscribers
def notify_topic_subscribers(post):
topic = post.topic
if post != topic.head:
for user in topic.subscribers.all():
if user != post.user:
try:
email_validator.clean(user.email)
except:
#invalid email
continue
old_lang = translation.get_language()
lang = util.get_pybb_profile(user).language or settings.LANGUAGE_CODE
translation.activate(lang)
delete_url = reverse('pybb:delete_subscription', args=[post.topic.id])
current_site = Site.objects.get_current()
subject = render_to_string('pybb/mail_templates/subscription_email_subject.html',
{ 'site': current_site,
'post': post
})
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('pybb/mail_templates/subscription_email_body.html',
{ 'site': current_site,
'post': post,
'delete_url': delete_url,
})
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=True)
translation.activate(old_lang)
示例6: pybb_user_time
def pybb_user_time(context_time, user):
delta = tznow() - context_time
today = tznow().replace(hour=0, minute=0, second=0)
yesterday = today - timedelta(days=1)
tomorrow = today + timedelta(days=1)
if delta.days == 0:
if delta.seconds < 60:
msg = ungettext('%d second ago', '%d seconds ago', delta.seconds)
return msg % delta.seconds
elif delta.seconds < 3600:
minutes = int(delta.seconds / 60)
msg = ungettext('%d minute ago', '%d minutes ago', minutes)
return msg % minutes
if is_authenticated(user):
if time.daylight: # pragma: no cover
tz1 = time.altzone
else: # pragma: no cover
tz1 = time.timezone
tz = tz1 + util.get_pybb_profile(user).time_zone * 60 * 60
context_time = context_time + timedelta(seconds=tz)
if today < context_time < tomorrow:
return _('today, %s') % context_time.strftime('%H:%M')
elif yesterday < context_time < today:
return _('yesterday, %s') % context_time.strftime('%H:%M')
else:
return dateformat.format(context_time, 'd M, Y H:i')
示例7: send_notification
def send_notification(users, template, context=None):
context = context or {}
if not 'site' in context:
context['site'] = Site.objects.get_current()
old_lang = translation.get_language()
from_email = settings.DEFAULT_FROM_EMAIL
mails = []
for user in users:
if not getattr(util.get_pybb_profile(user), 'receive_emails', True):
continue
try:
validate_email(user.email)
except:
# Invalid email
continue
if user.email == '%[email protected]' % getattr(user, compat.get_username_field()):
continue
context['user'] = user
lang = util.get_pybb_profile(user).language or settings.LANGUAGE_CODE
translation.activate(lang)
subject = render_to_string('pybb/mail_templates/%s_subject.html' % template, context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
context['subject'] = subject
txt_message = render_to_string('pybb/mail_templates/%s_body.html' % template, context)
try:
html_message = render_to_string('pybb/mail_templates/%s_body-html.html' % template, context)
except TemplateDoesNotExist as e:
mails.append((subject, txt_message, from_email, [user.email]))
else:
mails.append((subject, txt_message, from_email, [user.email], html_message))
# Send mails
send_mass_html_mail(mails, fail_silently=True)
# Reactivate previous language
translation.activate(old_lang)
示例8: post_saved
def post_saved(instance, **kwargs):
if getattr(instance, '_post_saved_done', False):
#Do not spam users when post is saved more than once in a same request.
#For eg, when we parse attachments.
return
instance._post_saved_done = True
if not defaults.PYBB_DISABLE_NOTIFICATIONS:
notify_topic_subscribers(instance)
if util.get_pybb_profile(instance.user).autosubscribe and \
perms.may_subscribe_topic(instance.user, instance.topic):
instance.topic.subscribers.add(instance.user)
if kwargs['created']:
profile = util.get_pybb_profile(instance.user)
profile.post_count = instance.user.posts.count()
profile.save()
示例9: 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()
示例10: notify_topic_subscribers
def notify_topic_subscribers(post):
topic = post.topic
if post != topic.head:
old_lang = translation.get_language()
# Define constants for templates rendering
delete_url = reverse('pybb:delete_subscription', args=[post.topic.id])
current_site = Site.objects.get_current()
from_email = settings.DEFAULT_FROM_EMAIL
subject = render_to_string('pybb/mail_templates/subscription_email_subject.html',
{'site': current_site,
'post': post})
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
mails = tuple()
for user in topic.subscribers.exclude(pk=post.user.pk):
try:
validate_email(user.email)
except:
# Invalid email
continue
if user.email == '%[email protected]' % getattr(user, compat.get_username_field()):
continue
lang = util.get_pybb_profile(user).language or settings.LANGUAGE_CODE
translation.activate(lang)
message = render_to_string('pybb/mail_templates/subscription_email_body.html',
{'site': current_site,
'post': post,
'delete_url': delete_url,
'user': user})
mails += ((subject, message, from_email, [user.email]),)
# Send mails
send_mass_mail(mails, fail_silently=True)
# Reactivate previous language
translation.activate(old_lang)
示例11: render
def render(self, context):
context_time = self.time.resolve(context)
delta = tznow() - context_time
today = tznow().replace(hour=0, minute=0, second=0)
yesterday = today - timedelta(days=1)
tomorrow = today + timedelta(days=1)
if delta.days == 0:
if delta.seconds < 60:
if context['LANGUAGE_CODE'].startswith('ru') and pytils_enabled:
msg = _('seconds ago,seconds ago,seconds ago')
msg = pytils.numeral.choose_plural(delta.seconds, msg)
else:
msg = _('seconds ago')
return '%d %s' % (delta.seconds, msg)
elif delta.seconds < 3600:
minutes = int(delta.seconds / 60)
if context['LANGUAGE_CODE'].startswith('ru') and pytils_enabled:
msg = _('minutes ago,minutes ago,minutes ago')
msg = pytils.numeral.choose_plural(minutes, msg)
else:
msg = _('minutes ago')
return '%d %s' % (minutes, msg)
if context['user'].is_authenticated():
if time.daylight:
tz1 = time.altzone
else:
tz1 = time.timezone
tz = tz1 + util.get_pybb_profile(context['user']).time_zone * 60 * 60
context_time = context_time + timedelta(seconds=tz)
if today < context_time < tomorrow:
return _('today, %s') % context_time.strftime('%H:%M')
elif yesterday < context_time < today:
return _('yesterday, %s') % context_time.strftime('%H:%M')
else:
return dateformat.format(context_time, 'd M, Y H:i')
示例12: post_deleted
def post_deleted(instance, **kwargs):
profile = get_pybb_profile(instance.user)
profile.post_count = instance.user.posts.count()
profile.save()
示例13: get_object
def get_object(self, queryset=None):
return util.get_pybb_profile(self.request.user)
示例14: pybb_get_profile
def pybb_get_profile(*args, **kwargs):
try:
return util.get_pybb_profile(kwargs.get('user') or args[0])
except:
return util.get_pybb_profile_model().objects.none()
示例15: __init__
def __init__(self, instance, user, *args, **kwargs):
super(MovePostForm, self).__init__(*args, **kwargs)
self.instance = instance
self.user = user
self.post = self.instance
self.category, self.forum, self.topic = self.post.get_parents()
if not self.post.is_topic_head:
# we do not move an entire topic but a part of it's posts. Let's select those posts.
self.posts_to_move = Post.objects.filter(created__gte=self.post.created,
topic=self.topic).order_by('created', 'pk')
# if multiple posts exists with the same created datetime, it's important to keep the
# same order and do not move some posts which could be "before" our post.
# We can not just filter by adding `pk__gt=self.post.pk` because we could exclude
# some posts if for some reasons, a lesser pk has a greater "created" datetime
# Most of the time, we just do one extra request to be sure the first post is
# the wanted one
first_pk = self.posts_to_move.values_list('pk', flat=True)[0]
while first_pk != self.post.pk:
self.posts_to_move = self.posts_to_move.exclude(pk=first_pk)
first_pk = self.posts_to_move.values_list('pk', flat=True)[0]
i = 0
choices = []
for post in self.posts_to_move[1:]: # all except the current one
i += 1
bvars = {'author': util.get_pybb_profile(post.user).get_display_name(),
'abstract': Truncator(post.body_text).words(8),
'i': i}
label = _('%(i)d (%(author)s: "%(abstract)s")') % bvars
choices.append((i, label))
choices.insert(0, (0, _('None')))
choices.insert(0, (-1, _('All')))
self.fields['number'] = forms.TypedChoiceField(
label=ugettext_lazy('Number of following posts to move with'),
choices=choices, required=True, coerce=int,
)
# we move the entire topic, so we want to change it's forum.
# So, let's exclude the current one
# get all forum where we can move this post (and the others)
move_to_forums = permissions.perms.filter_forums(self.user, Forum.objects.all())
if self.post.is_topic_head:
# we move the entire topic, so we want to change it's forum.
# So, let's exclude the current one
move_to_forums = move_to_forums.exclude(pk=self.forum.pk)
last_cat_pk = None
choices = []
for forum in move_to_forums.order_by('category__position', 'position', 'name'):
if not permissions.perms.may_create_topic(self.user, forum):
continue
if last_cat_pk != forum.category.pk:
last_cat_pk = forum.category.pk
choices.append(('%s' % forum.category, []))
if self.forum.pk == forum.pk:
name = '%(forum)s (forum of the current post)' % {'forum': self.forum}
else:
name = '%s' % forum
choices[-1][1].append((forum.pk, name))
self.fields['move_to'] = forms.ChoiceField(label=ugettext_lazy('Move to forum'),
initial=self.forum.pk,
choices=choices, required=True,)
self.fields['name'] = forms.CharField(label=_('New subject'),
initial=self.topic.name,
max_length=255, required=True)
if permissions.perms.may_edit_topic_slug(self.user):
self.fields['slug'] = forms.CharField(label=_('New topic slug'),
initial=self.topic.slug,
max_length=255, required=False)