Merge pull request #403 from ungleich/feature/handle_blog_category_not_found
Raise Http404 if BlogCategory is not found
This commit is contained in:
commit
1893bff785
2 changed files with 18 additions and 3 deletions
|
@ -8,6 +8,7 @@ from django.apps import apps
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import Http404
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import get_language
|
||||
from django.views.generic import DetailView, ListView
|
||||
|
@ -177,9 +178,12 @@ class CategoryEntriesView(BaseBlogListView, ListView):
|
|||
@property
|
||||
def category(self):
|
||||
if not self._category:
|
||||
self._category = BlogCategory.objects.active_translations(
|
||||
get_language(), slug=self.kwargs['category']
|
||||
).get()
|
||||
try:
|
||||
self._category = BlogCategory.objects.active_translations(
|
||||
get_language(), slug=self.kwargs['category']
|
||||
).get()
|
||||
except BlogCategory.DoesNotExist:
|
||||
raise Http404
|
||||
return self._category
|
||||
|
||||
def get(self, *args, **kwargs):
|
||||
|
|
|
@ -484,3 +484,14 @@ class ViewTest(BaseTest):
|
|||
self.assertEqual(view_obj.get_template_names(), os.path.join('whatever', 'post_list.html'))
|
||||
self.app_config_1.app_data.config.template_prefix = ''
|
||||
self.app_config_1.save()
|
||||
|
||||
def test_non_existing_blog_category_should_raise_404(self):
|
||||
pages = self.get_pages()
|
||||
with smart_override('en'):
|
||||
request = self.get_request(pages[1], 'en', AnonymousUser())
|
||||
view_obj = CategoryEntriesView()
|
||||
view_obj.request = request
|
||||
view_obj.namespace, view_obj.config = get_app_instance(request)
|
||||
with self.assertRaises(Http404):
|
||||
view_obj.kwargs = {'category': 'unknown-category'}
|
||||
category_obj = view_obj.get_queryset()
|
||||
|
|
Loading…
Reference in a new issue