本文整理汇总了Python中kitsune.users.models.Setting类的典型用法代码示例。如果您正苦于以下问题:Python Setting类的具体用法?Python Setting怎么用?Python Setting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Setting类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reply
def reply(request, document_slug, thread_id):
"""Reply to a thread."""
doc = get_document(document_slug, request)
form = ReplyForm(request.POST)
post_preview = None
if form.is_valid():
thread = get_object_or_404(Thread, pk=thread_id, document=doc)
if not thread.is_locked:
reply_ = form.save(commit=False)
reply_.thread = thread
reply_.creator = request.user
if 'preview' in request.POST:
post_preview = reply_
elif not _is_ratelimited(request):
reply_.save()
statsd.incr('kbforums.reply')
# Subscribe the user to the thread.
if Setting.get_for_user(request.user,
'kbforums_watch_after_reply'):
NewPostEvent.notify(request.user, thread)
# Send notifications to thread/forum watchers.
NewPostEvent(reply_).fire(exclude=reply_.creator)
return HttpResponseRedirect(reply_.get_absolute_url())
return posts(request, document_slug, thread_id, form, post_preview)
示例2: new_thread
def new_thread(request, document_slug):
"""Start a new thread."""
doc = get_document(document_slug, request)
if request.method == "GET":
form = NewThreadForm()
return render(request, "kbforums/new_thread.html", {"form": form, "document": doc})
form = NewThreadForm(request.POST)
post_preview = None
if form.is_valid():
if "preview" in request.POST:
thread = Thread(creator=request.user, title=form.cleaned_data["title"])
post_preview = Post(thread=thread, creator=request.user, content=form.cleaned_data["content"])
elif not _is_ratelimited(request):
thread = doc.thread_set.create(creator=request.user, title=form.cleaned_data["title"])
thread.save()
statsd.incr("kbforums.thread")
post = thread.new_post(creator=request.user, content=form.cleaned_data["content"])
post.save()
# Send notifications to forum watchers.
NewThreadEvent(post).fire(exclude=post.creator)
# Add notification automatically if needed.
if Setting.get_for_user(request.user, "kbforums_watch_new_thread"):
NewPostEvent.notify(request.user, thread)
return HttpResponseRedirect(reverse("wiki.discuss.posts", args=[document_slug, thread.id]))
return render(request, "kbforums/new_thread.html", {"form": form, "document": doc, "post_preview": post_preview})
示例3: test_create_setting
def test_create_setting(self):
url = reverse('users.edit_settings', locale='en-US')
eq_(Setting.objects.filter(user=self.u).count(), 0) # No settings
res = self.client.get(url, follow=True)
eq_(200, res.status_code)
res = self.client.post(url, {'forums_watch_new_thread': True},
follow=True)
eq_(200, res.status_code)
assert Setting.get_for_user(self.u, 'forums_watch_new_thread')
示例4: new_thread
def new_thread(request, forum_slug):
"""Start a new thread."""
forum = get_object_or_404(Forum, slug=forum_slug)
user = request.user
if not forum.allows_posting_by(user):
if forum.allows_viewing_by(user):
raise PermissionDenied
else:
raise Http404
if request.method == 'GET':
form = NewThreadForm()
return render(request, 'forums/new_thread.html', {
'form': form, 'forum': forum})
form = NewThreadForm(request.POST)
post_preview = None
if form.is_valid():
if 'preview' in request.POST:
thread = Thread(creator=request.user,
title=form.cleaned_data['title'])
post_preview = Post(thread=thread, author=request.user,
content=form.cleaned_data['content'])
post_preview.author_post_count = \
post_preview.author.post_set.count()
elif (_skip_post_ratelimit(request) or
not is_ratelimited(request, increment=True, rate='5/d', ip=False,
keys=user_or_ip('forum-post'))):
thread = forum.thread_set.create(creator=request.user,
title=form.cleaned_data['title'])
thread.save()
statsd.incr('forums.thread')
post = thread.new_post(author=request.user,
content=form.cleaned_data['content'])
post.save()
NewThreadEvent(post).fire(exclude=post.author)
# Add notification automatically if needed.
if Setting.get_for_user(request.user, 'forums_watch_new_thread'):
NewPostEvent.notify(request.user, thread)
url = reverse('forums.posts', args=[forum_slug, thread.id])
return HttpResponseRedirect(urlparams(url, last=post.id))
return render(request, 'forums/new_thread.html', {
'form': form, 'forum': forum,
'post_preview': post_preview})
示例5: send_message
def send_message(to, text, sender=None):
"""Send a private message.
:arg to: a list of Users to send the message to
:arg sender: the User who is sending the message
:arg text: the message text
"""
if sender:
msg = OutboxMessage.objects.create(sender=sender, message=text)
msg.to.add(*to)
for user in to:
im = InboxMessage.objects.create(sender=sender, to=user, message=text)
if Setting.get_for_user(user, 'email_private_messages'):
email_private_message(inbox_message_id=im.id)
message_sent.send(sender=InboxMessage, to=to, text=text,
msg_sender=sender)
示例6: test_private_message_not_sends_email
def test_private_message_not_sends_email(self, get_current):
"""
With the setting not enabled and receiving a private message.
The user should not get an email.
"""
get_current.return_value.domain = 'testserver'
s, c = Setting.objects.get_or_create(user=self.to,
name='email_private_messages')
# Now user should not recieve email.
s.value = False
s.save()
assert not Setting.get_for_user(self.to, 'email_private_messages')
self.client.login(username=self.sender.username, password='testpass')
post(self.client, 'messages.new',
{'to': self.to, 'message': 'a message'})
assert not mail.outbox
示例7: reply
def reply(request, forum_slug, thread_id):
"""Reply to a thread."""
forum = get_object_or_404(Forum, slug=forum_slug)
user = request.user
if not forum.allows_posting_by(user):
if forum.allows_viewing_by(user):
raise PermissionDenied
else:
raise Http404
form = ReplyForm(request.POST)
post_preview = None
if form.is_valid():
thread = get_object_or_404(Thread, pk=thread_id, forum=forum)
if not thread.is_locked:
reply_ = form.save(commit=False)
reply_.thread = thread
reply_.author = request.user
if 'preview' in request.POST:
post_preview = reply_
post_preview.author_post_count = \
reply_.author.post_set.count()
elif (_skip_post_ratelimit(request) or
not is_ratelimited(request, increment=True, rate='5/d',
ip=False,
keys=user_or_ip('forum-post'))):
reply_.save()
statsd.incr('forums.reply')
# Subscribe the user to the thread.
if Setting.get_for_user(request.user,
'forums_watch_after_reply'):
NewPostEvent.notify(request.user, thread)
# Send notifications to thread/forum watchers.
NewPostEvent(reply_).fire(exclude=reply_.author)
return HttpResponseRedirect(thread.get_last_post_url())
return posts(request, forum_slug, thread_id, form, post_preview,
is_reply=True)
示例8: test_private_message_sends_email
def test_private_message_sends_email(self, get_current):
"""
With the setting enabled and receiving a private message should
send and email.
"""
get_current.return_value.domain = 'testserver'
s, c = Setting.objects.get_or_create(user=self.to, name='email_private_messages')
s.value = True
s.save()
# User has setting, and should recieve notification email.
assert Setting.get_for_user(self.to, 'email_private_messages')
self.client.login(username=self.sender.username, password='testpass')
post(self.client, 'messages.new',
{'to': self.to, 'message': 'a message'})
subject = u'[SUMO] You have a new private message from [{sender}]'
attrs_eq(mail.outbox[0], to=[self.to.email],
subject=subject.format(sender=self.sender.profile.name))
starts_with(mail.outbox[0].body,
PRIVATE_MESSAGE_EMAIL.format(sender=self.sender.profile.name))
示例9: test_default_values
def test_default_values(self):
eq_(0, Setting.objects.count())
keys = SettingsForm.base_fields.keys()
for setting in keys:
field = SettingsForm.base_fields[setting]
eq_(field.initial, Setting.get_for_user(self.u, setting))
示例10: test_non_existant_setting
def test_non_existant_setting(self):
form = SettingsForm()
bad_setting = 'doesnt_exist'
assert bad_setting not in form.fields.keys()
with self.assertRaises(KeyError):
Setting.get_for_user(self.u, bad_setting)