Example #1
0
def comment(request, article_id):
    article = get_object_or_404(Article, id=article_id)
    comment = request.POST['comment']

    if not comment:
        return render(request, 'articles/detail.html', {
            'article': article,
            'error_message': "You didn't have any commnet.",
        })

    db.flush()
    return HttpResponseRedirect(reverse('article:results', args=(article.id,)))
Example #2
0
    def test_get_object_or_404(self):
        owner = Owner.objects.first()

        obj = shortcuts.get_object_or_404(Owner, id=owner.id)
        self.assertIsNotNone(obj)

        with self.assertRaises(Http404):
            shortcuts.get_object_or_404(Owner, id=0)

        obj = shortcuts.get_object_or_404(Owner.query, id=owner.id)
        self.assertIsNotNone(obj)

        with self.assertRaises(Http404):
            shortcuts.get_object_or_404(Owner.query, id=0)

        with self.assertRaises(ImproperlyConfigured):

            class Dummy:
                pass

            shortcuts.get_object_or_404(Dummy, id=0)
Example #3
0
    def test_get_object_or_404(self):
        owner = Owner.objects.first()

        obj = shortcuts.get_object_or_404(Owner, id=owner.id)
        self.assertIsNotNone(obj)

        with self.assertRaises(Http404):
            shortcuts.get_object_or_404(Owner, id=0)

        obj = shortcuts.get_object_or_404(Owner.query, id=owner.id)
        self.assertIsNotNone(obj)

        with self.assertRaises(Http404):
            shortcuts.get_object_or_404(Owner.query, id=0)
Example #4
0
def results(request, article_id):
    article = get_object_or_404(Article, id=article_id)
    return render(request, 'articles/results.html', {'article': article})
Example #5
0
def detail(request, article_id):
    article = get_object_or_404(Article, id=article_id)
    return render(request, 'articles/detail.html', {'article': article})