mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	magic-removal: Changed get_object_or_404 to take the model class, not the magic model module
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1666 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
|  | from django.contrib.flatpages.models import FlatPage | ||||||
| from django.core import template_loader | from django.core import template_loader | ||||||
| from django.core.extensions import get_object_or_404, DjangoContext | from django.core.extensions import get_object_or_404, DjangoContext | ||||||
| from django.models.flatpages import flatpages |  | ||||||
| from django.utils.httpwrappers import HttpResponse | from django.utils.httpwrappers import HttpResponse | ||||||
| from django.conf.settings import SITE_ID | from django.conf.settings import SITE_ID | ||||||
|  |  | ||||||
| @@ -19,7 +19,7 @@ def flatpage(request, url): | |||||||
|     """ |     """ | ||||||
|     if not url.startswith('/'): |     if not url.startswith('/'): | ||||||
|         url = "/" + url |         url = "/" + url | ||||||
|     f = get_object_or_404(flatpages, url__exact=url, sites__id__exact=SITE_ID) |     f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=SITE_ID) | ||||||
|     # If registration is required for accessing this page, and the user isn't |     # If registration is required for accessing this page, and the user isn't | ||||||
|     # logged in, redirect to the login page. |     # logged in, redirect to the login page. | ||||||
|     if f.registration_required and request.user.is_anonymous(): |     if f.registration_required and request.user.is_anonymous(): | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| # of MVC. In other words, these functions/classes introduce controlled coupling | # of MVC. In other words, these functions/classes introduce controlled coupling | ||||||
| # for convenience's sake. | # for convenience's sake. | ||||||
|  |  | ||||||
| from django.core.exceptions import Http404, ObjectDoesNotExist | from django.core.exceptions import Http404 | ||||||
| from django.core.template import Context, loader | from django.core.template import Context, loader | ||||||
| from django.conf.settings import DEBUG, INTERNAL_IPS | from django.conf.settings import DEBUG, INTERNAL_IPS | ||||||
| from django.utils.httpwrappers import HttpResponse | from django.utils.httpwrappers import HttpResponse | ||||||
| @@ -11,10 +11,10 @@ def render_to_response(*args, **kwargs): | |||||||
|     return HttpResponse(loader.render_to_string(*args, **kwargs)) |     return HttpResponse(loader.render_to_string(*args, **kwargs)) | ||||||
| load_and_render = render_to_response # For backwards compatibility. | load_and_render = render_to_response # For backwards compatibility. | ||||||
|  |  | ||||||
| def get_object_or_404(mod, **kwargs): | def get_object_or_404(klass, **kwargs): | ||||||
|     try: |     try: | ||||||
|         return mod.get_object(**kwargs) |         return klass._default_manager.get_object(**kwargs) | ||||||
|     except ObjectDoesNotExist: |     except klass.DoesNotExist: | ||||||
|         raise Http404 |         raise Http404 | ||||||
|  |  | ||||||
| def get_list_or_404(mod, **kwargs): | def get_list_or_404(mod, **kwargs): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user