How to use the spirit.topic.models.Topic function in spirit

To help you get started, we’ve selected a few spirit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nitely / Spirit / spirit / comment / tests.py View on Github external
utils.login(self)
        self.user.st.is_moderator = True
        self.user.save()
        Topic.objects.filter(pk=self.topic.pk).update(comment_count=2)
        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(category=self.category)
        form_data = {'topic': to_topic.pk,
                     'comments': [comment.pk, comment2.pk], }
        response = self.client.post(reverse('spirit:comment:move', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        expected_url = self.topic.get_absolute_url()
        self.assertRedirects(response, expected_url, status_code=302)
        self.assertEqual(Comment.objects.filter(topic=to_topic.pk).count(), 2)
        self.assertEqual(Comment.objects.filter(topic=self.topic.pk).count(), 0)
        self.assertEqual(Topic.objects.get(pk=self.topic.pk).comment_count, 0)
github nitely / Spirit / spirit / topic / private / tests.py View on Github external
reverse('spirit:topic:private:publish'),
            {'comment': 'new foo', 'title': topic_title, 'users': [self.user2.username]})
        self.assertEqual(len(Topic.objects.all()), 1)  # Prevented!

        self.assertRedirects(
            response,
            expected_url=category_private.get_absolute_url(),
            status_code=302,
            target_status_code=200)

        # New post
        utils.cache_clear()  # Clear rate limit
        self.client.post(
            reverse('spirit:topic:private:publish'),
            {'comment': 'foo', 'title': 'new topic', 'users': [self.user2.username]})
        self.assertEqual(len(Topic.objects.all()), 2)
github nitely / Spirit / spirit / search / tests.py View on Github external
def setUp(self):
        utils.cache_clear()
        self.topic_sqs = SearchQuerySet().models(Topic)
        self.now = timezone.now()
        self.yesterday = timezone.now() - datetime.timedelta(days=1)
        self.tomorrow = timezone.now() + datetime.timedelta(days=1)
github nitely / Spirit / spirit / comment / bookmark / views.py View on Github external
def find(request, topic_id):
    # TODO: test!, this aint used yet.
    bookmark = BookmarkForm.objects.filter(user=request.user, topic_id=topic_id)

    if not bookmark:
        topic = get_object_or_404(Topic, pk=topic_id)
        return redirect(topic.get_absolute_url())

    return redirect(bookmark.get_absolute_url())
github nitely / Spirit / spirit / comment / views.py View on Github external
def publish(request, topic_id, pk=None):
    user = request.user
    topic = get_object_or_404(
        Topic.objects.opened().for_access(user),
        pk=topic_id)

    if request.method == 'POST':
        form = CommentForm(user=user, topic=topic, data=request.POST)

        if not request.is_limited() and form.is_valid():
            if not user.st.update_post_hash(form.get_comment_hash()):
                # Hashed comment may have not been saved yet
                return redirect(
                    request.POST.get('next', None) or
                    Comment
                    .get_last_for_topic(topic_id)
                    .get_absolute_url())

            comment = form.save()
            comment_posted(comment=comment, mentions=form.mentions)
github nitely / Spirit / spirit / topic / models.py View on Github external
def increase_comment_count(self):
        (Topic.objects
         .filter(pk=self.pk)
         .update(comment_count=F('comment_count') + 1, last_active=timezone.now()))
github nitely / Spirit / spirit / topic / models.py View on Github external
Topic.objects\
            .filter(pk=self.pk)\
            .update(comment_count=F('comment_count') + 1, last_active=timezone.now())

    def decrease_comment_count(self):
        # todo: update last_active to last() comment
        Topic.objects\
            .filter(pk=self.pk)\
            .update(comment_count=F('comment_count') - 1)


def increase_user_profile_comment_count(sender, instance, created, **kwargs):
    if created and not instance.category.is_private:
        instance.user.st.increase_topic_count()

post_save.connect(increase_user_profile_comment_count, sender=Topic, dispatch_uid='Topic:increase_user_profile_comment_count')


def decrease_user_profile_comment_count(sender, instance, **kwargs):
    if not instance.category.is_private:
        instance.user.st.decrease_topic_count()

post_delete.connect(decrease_user_profile_comment_count, sender=Topic, dispatch_uid='Topic:decrease_user_profile_comment_count')