예제 #1
0
파일: views.py 프로젝트: MechanisM/kitsune
def watch_question(request, question_id):
    """Start watching a question for replies or solution."""
    question = get_object_or_404(Question, pk=question_id)
    form = WatchQuestionForm(request.POST)

    # Process the form
    if form.is_valid():
        if request.user.is_authenticated():
            email = request.user.email
        else:
            email = form.cleaned_data['email']
        event_type = form.cleaned_data['event_type']
        create_watch(Question, question.id, email, event_type)

    # Respond to ajax request
    if request.is_ajax():
        if form.is_valid():
            msg = _('You will be notified of updates by email.')
            return HttpResponse(json.dumps({'message': msg}))

        if request.POST.get('from_vote'):
            tmpl = 'questions/includes/question_vote_thanks.html'
        else:
            tmpl = 'questions/includes/email_subscribe.html'

        html = jingo.render_to_string(request, tmpl, {'question': question,
                                                      'watch_form': form})
        return HttpResponse(json.dumps({'html': html}))

    # Respond to normal request
    if form.is_valid():
        return HttpResponseRedirect(question.get_absolute_url())

    return answers(request, question.id, watch_form=form)
예제 #2
0
 def test_unwatch(self):
     """Unwatch a question."""
     self.client.login(username='******', password='******')
     user = User.objects.get(username='******')
     create_watch(Question, self.question.id, user.email, 'solution')
     post(self.client, 'questions.unwatch', args=[self.question.id])
     assert not check_watch(Question, self.question.id, user.email,
                            'solution'), 'Watch was not destroyed'
예제 #3
0
def watch_approved(request):
    """Start watching approved revisions."""
    locale = request.POST.get('locale')
    if locale not in settings.SUMO_LANGUAGES:
        raise Http404

    create_watch(Document, None, request.user.email, 'approved', locale)
    return HttpResponseRedirect(reverse('dashboards.localization'))
예제 #4
0
 def test_watch_solution_and_replies(self):
     """User subscribes to solution and replies: page doesn't break"""
     self.client.login(username='******', password='******')
     user = User.objects.get(username='******')
     create_watch(Question, self.question.id, user.email, 'reply')
     create_watch(Question, self.question.id, user.email, 'solution')
     response = get(self.client, 'questions.answers',
                    args=[self.question.id])
     eq_(200, response.status_code)
예제 #5
0
파일: views.py 프로젝트: MechanisM/kitsune
def watch_forum(request, document_slug):
    """Watch/unwatch a forum (based on 'watch' POST param)."""
    doc = get_document(document_slug, request)
    if request.POST.get('watch') == 'yes':
        create_watch(Document, doc.id, request.user.email, 'post')
    else:
        destroy_watch(Document, doc.id, request.user.email, 'post')

    return HttpResponseRedirect(reverse('wiki.discuss.threads',
                                        args=[document_slug]))
예제 #6
0
    def test_double_create_watch(self):
        """create_watch() twice should return false."""
        post = Post.objects.all()[2]
        create_watch(Post, post.pk, '*****@*****.**', 'reply')
        rv = create_watch(Post, post.pk, '*****@*****.**', 'reply')

        assert not rv, 'create_watch() returned True.'

        watches = EventWatch.objects.filter(watch_id=post.pk,
                                            content_type=self.ct)
        eq_(1, len(watches))
예제 #7
0
파일: views.py 프로젝트: MechanisM/kitsune
def watch_forum(request, forum_slug):
    """Watch/unwatch a forum (based on 'watch' POST param)."""
    forum = get_object_or_404(Forum, slug=forum_slug)
    if not forum.allows_viewing_by(request.user):
        raise Http404

    if request.POST.get("watch") == "yes":
        create_watch(Forum, forum.id, request.user.email, "post")
    else:
        destroy_watch(Forum, forum.id, request.user.email, "post")

    return HttpResponseRedirect(reverse("forums.threads", args=[forum_slug]))
예제 #8
0
파일: views.py 프로젝트: MechanisM/kitsune
def watch_thread(request, document_slug, thread_id):
    """Watch/unwatch a thread (based on 'watch' POST param)."""
    doc = get_document(document_slug, request)
    thread = get_object_or_404(Thread, pk=thread_id, document=doc)

    if request.POST.get('watch') == 'yes':
        create_watch(Thread, thread.id, request.user.email, 'reply')
    else:
        destroy_watch(Thread, thread.id, request.user.email, 'reply')

    return HttpResponseRedirect(reverse('wiki.discuss.posts',
                                        args=[document_slug, thread_id]))
예제 #9
0
파일: views.py 프로젝트: MechanisM/kitsune
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":
        create_watch(Thread, thread.id, request.user.email, "reply")
    else:
        destroy_watch(Thread, thread.id, request.user.email, "reply")

    return HttpResponseRedirect(reverse("forums.posts", args=[forum_slug, thread_id]))
예제 #10
0
파일: models.py 프로젝트: sgarrity/kitsune
    def save(self, no_update=False, *args, **kwargs):
        """Override save method to take care of updated."""
        new = not self.id

        if not new and not no_update:
            self.updated = datetime.now()

        # Generate a confirmation_id if necessary
        if new and not self.confirmation_id:
            chars = [random.choice(string.ascii_letters) for x in xrange(10)]
            self.confirmation_id = "".join(chars)

        super(Question, self).save(*args, **kwargs)

        if new:
            # Authors should automatically watch their own questions.
            create_watch(Question, self.id, self.creator.email, 'reply')
예제 #11
0
    def test_create_watch(self):
        """create_watch() should create a new EventWatch."""
        post = Post.objects.all()[1]
        rv = create_watch(Post, post.pk, '*****@*****.**', 'reply')

        assert rv, 'EventWatch was not created.'

        watches = EventWatch.objects.filter(watch_id=post.pk,
                                            content_type=self.ct)
        eq_(1, len(watches))
        eq_('*****@*****.**', watches[0].email)
예제 #12
0
 def test_create_invalid_watch(self):
     """Creating a watch on a non-existent objects should raise DNE."""
     x = lambda pk: create_watch(Post, pk, '*****@*****.**', 'reply')
     self.assertRaises(Post.DoesNotExist, x, 1000)
예제 #13
0
 def test_delete_removes_watches(self):
     create_watch(Thread, 1, '*****@*****.**', 'reply')
     eq_(1, EventWatch.uncached.filter(watch_id=1).count())
     t = Thread.objects.get(pk=1)
     t.delete()
     eq_(0, EventWatch.uncached.filter(watch_id=1).count())
예제 #14
0
def watch_locale(request):
    """Start watching a locale for revisions ready for review."""
    create_watch(Document, None, request.user.email, 'ready_for_review',
                 request.locale)
    return HttpResponseRedirect(reverse('dashboards.localization'))
예제 #15
0
def watch_document(request, document_slug):
    """Start watching a document for edits."""
    document = get_object_or_404(
        Document, locale=request.locale, slug=document_slug)
    create_watch(Document, document.id, request.user.email, 'edited')
    return HttpResponseRedirect(document.get_absolute_url())