• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Setting类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中users.models.Setting的典型用法代码示例。如果您正苦于以下问题:Python Setting类的具体用法?Python Setting怎么用?Python Setting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Setting类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_non_existant_setting

 def test_non_existant_setting(self):
     user = User.objects.all()[0]
     form = SettingsForm()
     bad_setting = 'doesnt_exist'
     assert bad_setting not in form.fields.keys()
     with self.assertRaises(KeyError):
         Setting.get_for_user(user, bad_setting)
开发者ID:Curlified,项目名称:kitsune,代码行数:7,代码来源:test_models.py


示例2: 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'

        to = User.objects.all()[1]
        s, c = Setting.objects.get_or_create(user=to,
                                             name='email_private_messages')
        s.value = True
        s.save()
        # User has setting, and should recieve notification email.

        assert Setting.get_for_user(to, 'email_private_messages')

        self.client.login(username='jsocol', password='testpass')
        res = post(self.client, 'messages.new',
             {'to': to, 'message': 'a message'})
        subject = u'[SUMO] You have a new private message from [{sender}]'

        attrs_eq(mail.outbox[0], to=[to.email],
                 subject=subject.format(sender='jsocol'))
        starts_with(mail.outbox[0].body,
                    PRIVATE_MESSAGE_EMAIL.format(sender='jsocol'))
开发者ID:erikrose,项目名称:kitsune,代码行数:25,代码来源:test_notifications.py


示例3: 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_
            else:
                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)
开发者ID:fox2mike,项目名称:kitsune,代码行数:30,代码来源:views.py


示例4: test_default_values

 def test_default_values(self):
     eq_(0, Setting.objects.count())
     user = User.objects.get(username='timw')
     keys = SettingsForm.base_fields.keys()
     for setting in keys:
         field = SettingsForm.base_fields[setting]
         eq_(field.initial, Setting.get_for_user(user, setting))
开发者ID:Curlified,项目名称:kitsune,代码行数:7,代码来源:test_models.py


示例5: 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 jingo.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"])
        else:
            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 jingo.render(
        request, "kbforums/new_thread.html", {"form": form, "document": doc, "post_preview": post_preview}
    )
开发者ID:georgedorn,项目名称:kitsune,代码行数:33,代码来源:views.py


示例6: test_view_activities

    def test_view_activities(self):
        from users.forms import SettingsForm
        from users.models import Setting

        request = self.factory.get(reverse('lets'))
        request.user = self.u
        views.activities(request)

        eq_('lets', Setting.get_for_user(self.u, 'home_tab'))

        form = SettingsForm(data={'home_tab': 'stream'})
        form.is_valid()
        form.save_for_user(request.user)
        eq_('stream', Setting.get_for_user(self.u, 'home_tab'))

        views.activities(request)
        eq_('lets', Setting.get_for_user(self.u, 'home_tab'))
开发者ID:ccarlos,项目名称:code-samples,代码行数:17,代码来源:test_views.py


示例7: test_create_setting

 def test_create_setting(self):
     url = reverse('users.edit_settings', locale='en-US')
     eq_(Setting.objects.filter(user=self.user).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.user, 'forums_watch_new_thread')
开发者ID:icaaq,项目名称:kitsune,代码行数:9,代码来源:test_views.py


示例8: 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 jingo.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()
        else:
            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 jingo.render(request, 'forums/new_thread.html',
                        {'form': form, 'forum': forum,
                         'post_preview': post_preview})
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:46,代码来源:views.py


示例9: 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)
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:17,代码来源:__init__.py


示例10: activities

def activities(request, category=None, home_tab=None):
    search_lets = get_relevant_lets(
        request.user, page=request.GET.get('page'),
        category=request.GET.get('category'))
    pages = paginate(request, search_lets['ids'], lcs.LETS_PER_PAGE)
    data = {'lets': search_lets['results'], 'catg': CATEGORY_CHOICES,
            'pages': pages, 'profile': request.user.profile}

    if not home_tab:
        from users.models import Setting
        home_tab = Setting.get_for_user(request.user, 'home_tab')
        if home_tab != 'lets':
            from users.forms import SettingsForm
            form = SettingsForm(data={'home_tab': 'lets'})
            form.is_valid()
            form.save_for_user(request.user)

    return jingo.render(request, 'lets/activities.html', data)
开发者ID:ccarlos,项目名称:code-samples,代码行数:18,代码来源:views.py


示例11: reply

def reply(request, question_id):
    """Post a new answer to a question."""
    question = get_object_or_404(Question, pk=question_id)
    answer_preview = None
    if question.is_locked:
        raise PermissionDenied

    form = AnswerForm(request.POST)

    # NOJS: delete images
    if 'delete_images' in request.POST:
        for image_id in request.POST.getlist('delete_image'):
            ImageAttachment.objects.get(pk=image_id).delete()

        return answers(request, question_id=question_id, form=form)

    # NOJS: upload image
    if 'upload_image' in request.POST:
        upload_imageattachment(request, question)
        return answers(request, question_id=question_id, form=form)

    if form.is_valid():
        answer = Answer(question=question, creator=request.user,
                        content=form.cleaned_data['content'])
        if 'preview' in request.POST:
            answer_preview = answer
        else:
            answer.save()
            ct = ContentType.objects.get_for_model(answer)
            # Move over to the answer all of the images I added to the
            # reply form
            up_images = question.images.filter(creator=request.user)
            up_images.update(content_type=ct, object_id=answer.id)
            statsd.incr('questions.answer')

            if Setting.get_for_user(request.user,
                                    'questions_watch_after_reply'):
                QuestionReplyEvent.notify(request.user, question)

            return HttpResponseRedirect(answer.get_absolute_url())

    return answers(request, question_id=question_id, form=form,
                   answer_preview=answer_preview)
开发者ID:lonnen,项目名称:kitsune,代码行数:43,代码来源:views.py


示例12: 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
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:19,代码来源:test_notifications.py


示例13: 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'

        to = User.objects.all()[1]
        s, c = Setting.objects.get_or_create(user=to,
                                             name='email_private_messages')
        # Now usershould not recieve email.
        s.value = False
        s.save()
        assert not Setting.get_for_user(to, 'email_private_messages')

        self.client.login(username='jsocol', password='testpass')
        res = post(self.client, 'messages.new',
             {'to': to, 'message': 'a message'})
        subject = u'You have a new private message from [{sender}]'

        assert not mail.outbox
开发者ID:erikrose,项目名称:kitsune,代码行数:21,代码来源:test_notifications.py


示例14: 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'])
        else:
            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})
开发者ID:LASarkar,项目名称:kitsune,代码行数:39,代码来源:views.py


示例15: 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()
            else:
                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)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:39,代码来源:views.py


示例16: 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)
开发者ID:browning,项目名称:kitsune,代码行数:6,代码来源:test_models.py


示例17: 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))
开发者ID:browning,项目名称:kitsune,代码行数:6,代码来源:test_models.py



注:本文中的users.models.Setting类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.User类代码示例发布时间:2022-05-27
下一篇:
Python models.Profile类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap