当前位置: 首页>>代码示例>>Python>>正文


Python events.NewPostEvent类代码示例

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


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

示例1: test_autowatch_reply

    def test_autowatch_reply(self, get_current):
        """Replying to a thread creates a watch."""
        get_current.return_value.domain = 'testserver'

        u = user(save=True)
        t1 = thread(save=True)
        t2 = thread(save=True)

        assert not NewPostEvent.is_notifying(u, t1)
        assert not NewPostEvent.is_notifying(u, t2)

        self.client.login(username=u.username, password='testpass')

        # If the poster has the forums_watch_after_reply setting set to True,
        # they will start watching threads they reply to.
        s = Setting.objects.create(user=u, name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(u, t1)

        # Setting forums_watch_after_reply back to False, now they shouldn't
        # start watching threads they reply to.
        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(u, t2)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:27,代码来源:test_notifications.py

示例2: _toggle_watch_thread_as

 def _toggle_watch_thread_as(self, thread, user, turn_on=True):
     """Watch a thread and return it."""
     self.client.login(username=user.username, password='testpass')
     watch = 'yes' if turn_on else 'no'
     post(self.client, 'forums.watch_thread', {'watch': watch},
          args=[thread.forum.slug, thread.id])
     # Watch exists or not, depending on watch.
     if turn_on:
         assert NewPostEvent.is_notifying(user, thread), (
                'NewPostEvent should be notifying.')
     else:
         assert not NewPostEvent.is_notifying(user, thread), (
                'NewPostEvent should not be notifying.')
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:13,代码来源:test_notifications.py

示例3: test_watch_thread

    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        self.client.login(username='rrosario', password='testpass')
        user = User.objects.get(username='rrosario')

        t = Thread.objects.filter()[1]
        post(self.client, 'forums.watch_thread', {'watch': 'yes'},
             args=[t.forum.slug, t.id])
        assert NewPostEvent.is_notifying(user, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(user, t.forum)

        post(self.client, 'forums.watch_thread', {'watch': 'no'},
             args=[t.forum.slug, t.id])
        assert not NewPostEvent.is_notifying(user, t)
开发者ID:Akamad007,项目名称:kitsune,代码行数:15,代码来源:test_views.py

示例4: watch_thread

def watch_thread(request, forum_slug, thread_id):
    """Watch/unwatch a thread (based on 'watch' POST param)."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

    if request.POST.get('watch') == 'yes':
        NewPostEvent.notify(request.user, thread)
    else:
        NewPostEvent.stop_notifying(request.user, thread)

    return HttpResponseRedirect(reverse('forums.posts',
                                        args=[forum_slug, thread_id]))
开发者ID:Sancus,项目名称:kitsune,代码行数:15,代码来源:views.py

示例5: posts

def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
    """View all the posts in a thread."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

    posts_ = paginate(request, thread.post_set.all(),
                      constants.POSTS_PER_PAGE)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={'forum_slug': forum_slug,
                                  'thread_id': thread_id}),
                  PostsFeed().title(thread)),)

    is_watching_thread = (request.user.is_authenticated() and
                          NewPostEvent.is_notifying(request.user, thread))
    return jingo.render(request, 'forums/posts.html',
                        {'forum': forum, 'thread': thread,
                         'posts': posts_, 'form': form,
                         'reply_preview': reply_preview,
                         'is_watching_thread': is_watching_thread,
                         'feeds': feed_urls,
                         'forums': Forum.objects.all()})
开发者ID:GPHemsley,项目名称:kuma,代码行数:28,代码来源:views.py

示例6: test_watch_thread

    def test_watch_thread(self):
        """Watch then unwatch a thread."""
        t = thread(save=True)
        u = user(save=True)

        self.client.login(username=u.username, password='testpass')

        post(self.client, 'forums.watch_thread', {'watch': 'yes'},
             args=[t.forum.slug, t.id])
        assert NewPostEvent.is_notifying(u, t)
        # NewThreadEvent is not notifying.
        assert not NewThreadEvent.is_notifying(u, t.forum)

        post(self.client, 'forums.watch_thread', {'watch': 'no'},
             args=[t.forum.slug, t.id])
        assert not NewPostEvent.is_notifying(u, t)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:16,代码来源:test_views.py

示例7: posts

def posts(request, forum_slug, thread_id, form=None, reply_preview=None):
    """View all the posts in a thread."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    thread = get_object_or_404(Thread, pk=thread_id, forum=forum)

    posts_ = thread.post_set.all()
    count = posts_.count()
    posts_ = posts_.select_related('author', 'updated_by')
    posts_ = posts_.extra(
        select={'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE '
                                     'forums_post.author_id = auth_user.id'})
    posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={'forum_slug': forum_slug,
                                  'thread_id': thread_id}),
                  PostsFeed().title(thread)),)

    is_watching_thread = (request.user.is_authenticated() and
                          NewPostEvent.is_notifying(request.user, thread))
    return jingo.render(request, 'forums/posts.html',
                        {'forum': forum, 'thread': thread,
                         'posts': posts_, 'form': form,
                         'reply_preview': reply_preview,
                         'is_watching_thread': is_watching_thread,
                         'feeds': feed_urls,
                         'forums': Forum.objects.all()})
开发者ID:Sancus,项目名称:kitsune,代码行数:33,代码来源: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: test_autowatch_reply

    def test_autowatch_reply(self, get_current):
        get_current.return_value.domain = 'testserver'

        user = User.objects.get(username='timw')
        t1, t2 = Thread.objects.filter(is_locked=False)[0:2]
        assert not NewPostEvent.is_notifying(user, t1)
        assert not NewPostEvent.is_notifying(user, t2)

        self.client.login(username='timw', password='testpass')
        s = Setting.objects.create(user=user, name='forums_watch_after_reply',
                                   value='True')
        data = {'content': 'some content'}
        post(self.client, 'forums.reply', data, args=[t1.forum.slug, t1.pk])
        assert NewPostEvent.is_notifying(user, t1)

        s.value = 'False'
        s.save()
        post(self.client, 'forums.reply', data, args=[t2.forum.slug, t2.pk])
        assert not NewPostEvent.is_notifying(user, t2)
开发者ID:fox2mike,项目名称:kitsune,代码行数:19,代码来源:test_notifications.py

示例10: 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

示例11: test_autowatch_new_thread

    def test_autowatch_new_thread(self, get_current):
        """Creating a new thread should email responses"""
        get_current.return_value.domain = 'testserver'

        eq_(0, len(mail.outbox))
        f = Forum.objects.get(pk=1)
        self.client.login(username='jsocol', password='testpass')
        user = User.objects.get(username='jsocol')
        s = Setting.objects.create(user=user, name='forums_watch_new_thread',
                                   value='False')
        data = {'title': 'a title', 'content': 'a post'}
        post(self.client, 'forums.new_thread', data, args=[f.slug])
        t1 = Thread.objects.all().order_by('-id')[0]
        assert not NewPostEvent.is_notifying(user, t1), (
            'NewPostEvent should not be notifying.')

        s.value = 'True'
        s.save()
        post(self.client, 'forums.new_thread', data, args=[f.slug])
        t2 = Thread.uncached.all().order_by('-id')[0]
        assert NewPostEvent.is_notifying(user, t2), (
            'NewPostEvent should be notifying.')
开发者ID:fox2mike,项目名称:kitsune,代码行数:22,代码来源:test_notifications.py

示例12: test_watch_forum

    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        self.client.login(username='rrosario', password='testpass')
        user = User.objects.get(username='rrosario')

        f = Forum.objects.filter()[0]
        post(self.client, 'forums.watch_forum', {'watch': 'yes'},
             args=[f.slug])
        assert NewThreadEvent.is_notifying(user, f)
        # NewPostEvent is not notifying.
        assert not NewPostEvent.is_notifying(user, f.last_post)

        post(self.client, 'forums.watch_forum', {'watch': 'no'},
             args=[f.slug])
        assert not NewThreadEvent.is_notifying(user, f)
开发者ID:Akamad007,项目名称:kitsune,代码行数:15,代码来源:test_views.py

示例13: posts

def posts(request, forum_slug, thread_id, form=None, post_preview=None,
          is_reply=False):
    """View all the posts in a thread."""
    thread = get_object_or_404(Thread, pk=thread_id)
    forum = thread.forum

    if forum.slug != forum_slug and not is_reply:
        new_forum = get_object_or_404(Forum, slug=forum_slug)
        if new_forum.allows_viewing_by(request.user):
            return HttpResponseRedirect(thread.get_absolute_url())
        raise Http404  # User has no right to view destination forum.
    elif forum.slug != forum_slug:
        raise Http404

    if not forum.allows_viewing_by(request.user):
        raise Http404

    posts_ = thread.post_set.all()
    count = posts_.count()
    if count:
        last_post = posts_[count - 1]
    else:
        last_post = None
    posts_ = posts_.select_related('author', 'updated_by')
    posts_ = posts_.extra(
        select={'author_post_count': 'SELECT COUNT(*) FROM forums_post WHERE '
                                     'forums_post.author_id = auth_user.id'})
    posts_ = paginate(request, posts_, constants.POSTS_PER_PAGE, count=count)

    if not form:
        form = ReplyForm()

    feed_urls = ((reverse('forums.posts.feed',
                          kwargs={'forum_slug': forum_slug,
                                  'thread_id': thread_id}),
                  PostsFeed().title(thread)),)

    is_watching_thread = (request.user.is_authenticated() and
                          NewPostEvent.is_notifying(request.user, thread))
    return jingo.render(request, 'forums/posts.html',
                        {'forum': forum, 'thread': thread,
                         'posts': posts_, 'form': form,
                         'count': count,
                         'last_post': last_post,
                         'post_preview': post_preview,
                         'is_watching_thread': is_watching_thread,
                         'feeds': feed_urls,
                         'forums': Forum.objects.all()})
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:48,代码来源:views.py

示例14: _toggle_watch_forum_as

 def _toggle_watch_forum_as(self, username, turn_on=True, forum_id=1):
     """Watch a forum and return it."""
     forum = Forum.objects.get(pk=forum_id)
     self.client.login(username=username, password='testpass')
     user = User.objects.get(username=username)
     watch = 'yes' if turn_on else 'no'
     post(self.client, 'forums.watch_forum', {'watch': watch},
          args=[forum.slug])
     # Watch exists or not, depending on watch.
     if turn_on:
         assert NewThreadEvent.is_notifying(user, forum), (
                'NewThreadEvent should be notifying.')
     else:
         assert not NewPostEvent.is_notifying(user, forum), (
                'NewThreadEvent should not be notifying.')
     return forum
开发者ID:bowmasters,项目名称:kitsune,代码行数:16,代码来源:test_notifications.py

示例15: test_watch_forum

    def test_watch_forum(self):
        """Watch then unwatch a forum."""
        f = forum(save=True)
        forum_post(thread=thread(forum=f, save=True), save=True)
        u = user(save=True)

        self.client.login(username=u.username, password='testpass')

        post(self.client, 'forums.watch_forum', {'watch': 'yes'},
             args=[f.slug])
        assert NewThreadEvent.is_notifying(u, f)
        # NewPostEvent is not notifying.
        assert not NewPostEvent.is_notifying(u, f.last_post)

        post(self.client, 'forums.watch_forum', {'watch': 'no'},
             args=[f.slug])
        assert not NewThreadEvent.is_notifying(u, f)
开发者ID:Apokalyptica79,项目名称:kitsune,代码行数:17,代码来源:test_views.py


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