+from django.conf import settings
from django.contrib.sites.models import Site
-from philo.models import Node
+from django.http import Http404
+from philo.models import Node, View
class LazyNode(object):
request.__class__.node = LazyNode()
def process_view(self, request, view_func, view_args, view_kwargs):
- request._cached_node_path = view_kwargs.get('path', '/')
\ No newline at end of file
+ request._cached_node_path = view_kwargs.get('path', '/')
+
+ def process_exception(self, request, exception):
+ if settings.DEBUG or not hasattr(request, 'node') or not request.node:
+ return
+
+ if isinstance(exception, Http404):
+ error_view = request.node.attributes.get('Http404', None)
+ else:
+ error_view = request.node.attributes.get('Http500', None)
+
+ if error_view is None or not isinstance(error_view, View):
+ # Should this be duck-typing? Perhaps even no testing?
+ return
+
+ extra_context = {'exception': exception}
+ return error_view.render_to_response(request, extra_context)
\ No newline at end of file
# Value is probably a queryset - but allow any iterable.
# These lines shouldn't be necessary; however, if value is an EmptyQuerySet,
- # the code won't work without them. Unclear why...
+ # the code (specifically the object_id__in query) won't work without them. Unclear why...
if not value:
value = []
+ # Before we can fiddle with the many-to-many to foreignkeyvalues, we need
+ # a pk.
+ if self.pk is None:
+ self.save()
+
if isinstance(value, models.query.QuerySet):
value = value.values_list('id', flat=True)
class ManyToManyAttributeDescriptor(AttributeFieldDescriptor):
def __set__(self, instance, value):
- if isinstance(value, models.QuerySet):
+ if isinstance(value, models.query.QuerySet):
if self.field in instance._removed_attribute_registry:
instance._removed_attribute_registry.remove(self.field)
instance._added_attribute_registry[self.field] = value
-from django.contrib.sites.models import Site
-from django.conf import settings
-from django.http import Http404, HttpResponse
-from django.template import RequestContext
+from django.http import Http404
from django.views.decorators.vary import vary_on_headers
from philo.exceptions import MIDDLEWARE_NOT_CONFIGURED
-from philo.models import Node
@vary_on_headers('Accept')
node = request.node
subpath = request.node.subpath
- try:
- if subpath and not node.accepts_subpath:
- raise Http404
- return node.render_to_response(request, kwargs)
- except Http404, e:
- if settings.DEBUG:
- raise
-
- try:
- Http404View = node.attributes['Http404']
- except KeyError:
- Http404View = None
-
- if not Http404View:
- raise e
-
- extra_context = {'exception': e}
-
- return Http404View.render_to_response(request, extra_context)
- except Exception, e:
- if settings.DEBUG:
- raise
-
- try:
- Http500View = node.attributes['Http500']
-
- if not Http500View:
- raise e
-
- extra_context = {'exception': e}
-
- return Http500View.render_to_response(request, extra_context)
- except:
- raise e
\ No newline at end of file
+ if subpath and not node.accepts_subpath:
+ raise Http404
+ return node.render_to_response(request, kwargs)
\ No newline at end of file