Ejemplo n.º 1
0
    def delete(self, using=None):
        """Custom delete method to remove the points for completed action."""
        profile = self.user.profile

        if self.approval_status == "approved":
            # remove all related point transaction
            profile.remove_related_points(self)
        else:
            # drop any possible signup transaction
            self._drop_signup_points()

        if profile.team:
            message = "is no longer participating in the %s \"%s\"." % (
                self.action.type,
                self.action.title,
            )
            post = Post(user=self.user,
                        team=profile.team,
                        text=message,
                        style_class="system_post")
            post.save()

        self.invalidate_cache()

        super(ActionMember, self).delete()
Ejemplo n.º 2
0
def post(request):
    """handle the submission of the wall post"""
    if request.is_ajax() and request.method == "POST":
        form = WallForm(request.POST)
        if form.is_valid():
            wall_post = Post(user=request.user,
                             team=request.user.profile.team,
                             text=form.cleaned_data["post"])
            wall_post.save()

            # Render the post and send it as a response.
            template = render_to_string(
                "user_post.html", {"post": wall_post},
                context_instance=RequestContext(request))
            return HttpResponse(json.dumps({
                "contents": template,
            }),
                                mimetype="application/json")

        # At this point there is a form validation error.
        return HttpResponse(json.dumps(
            {"message": "This should not be blank."}),
                            mimetype="application/json")

    raise Http404
Ejemplo n.º 3
0
def post(request):
    """handle the submission of the wall post"""
    if request.is_ajax() and request.method == "POST":
        form = WallForm(request.POST)
        if form.is_valid():
            wall_post = Post(
                user=request.user,
                team=request.user.get_profile().team,
                text=form.cleaned_data["post"]
            )
            wall_post.save()

            # Render the post and send it as a response.
            template = render_to_string("user_post.html", {"post": wall_post},
                context_instance=RequestContext(request))
            return HttpResponse(json.dumps({
                "contents": template,
                }), mimetype="application/json")

        # At this point there is a form validation error.
        return HttpResponse(json.dumps({
            "message": "This should not be blank."
        }), mimetype="application/json")

    raise Http404
Ejemplo n.º 4
0
    def post_to_wall(self):
        """post to team wall as system post."""
        team = self.user.get_profile().team
        if team:
            if self.approval_status == "approved":
                # User completed the commitment
                message = 'has completed the %s "%s".' % (self.action.type, self.action.title)
            else:
                # User is adding the commitment.
                message = 'is participating in the %s "%s".' % (self.action.type, self.action.title)

            post = Post(user=self.user, team=team, text=message, style_class="system_post")
            post.save()
Ejemplo n.º 5
0
    def post_to_wall(self):
        """post to team wall as system post."""
        team = self.user.get_profile().team
        if team:
            if self.approval_status == "approved":
                # User completed the commitment
                message = "has completed the %s \"%s\"." % (self.action.type,
                                                            self.action.title,)
            else:
                # User is adding the commitment.
                message = "is participating in the %s \"%s\"." % (self.action.type,
                                                                  self.action.title,)

            post = Post(user=self.user,
                        team=team,
                        text=message,
                        style_class="system_post")
            post.save()
Ejemplo n.º 6
0
    def delete(self, using=None):
        """Custom delete method to remove the points for completed action."""
        profile = self.user.get_profile()

        if self.approval_status == "approved":
            # remove all related point transaction
            profile.remove_related_points(self)
        else:
            # drop any possible signup transaction
            self._drop_signup_points()

        if profile.team:
            message = 'is no longer participating in the %s "%s".' % (self.action.type, self.action.title)
            post = Post(user=self.user, team=profile.team, text=message, style_class="system_post")
            post.save()

        self.invalidate_cache()

        super(ActionMember, self).delete()
Ejemplo n.º 7
0
    def testAjaxPosts(self):
        """Test that we can load new posts via AJAX."""
        # Generate test posts.
        for i in range(0, DEFAULT_POST_COUNT + 1):
            text = "Testing AJAX response %d." % i
            post = Post(user=self.user, team=self.team, text=text)
            post.save()

        second_post = Post.objects.all().order_by("-pk")[0]
        response = self.client.get(reverse("news_more_user_posts") + "?page_name=news",
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.failUnlessEqual(response.status_code, 200)
        self.assertNotContains(response, "Testing AJAX response 0.")
        self.assertContains(response, "See more")
        for i in range(1, DEFAULT_POST_COUNT + 1):
            self.assertContains(response, "Testing AJAX response %d" % i)

        response = self.client.get(reverse("news_more_user_posts") +
                                   ("?last_post=%d&page_name=news" % second_post.id),
            HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertContains(response, "Testing AJAX response 0.")