Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility patch for use with https://github.com/perry-mitchell/we… #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djangodav/base/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_descendants(self, depth=1, include_self=True):
# If depth is less than 0, then it started out as -1.
# We need to keep recursing until we hit 0, or forever
# in case of infinity.
if depth != 0:
if depth != 0 and self.is_collection:
for child in self.get_children():
for desc in child.get_descendants(depth=depth-1, include_self=True):
yield desc
Expand Down
1 change: 1 addition & 0 deletions djangodav/base/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_get_path_collection(self):
def test_get_path_object(self):
self.assertEqual(self.resource.get_path(), '/path/to/name')

@patch('djangodav.base.resources.BaseDavResource.is_collection', True)
@patch('djangodav.base.resources.BaseDavResource.get_children', Mock(return_value=[]))
def test_get_descendants(self):
self.assertEqual(list(self.resource.get_descendants(depth=1, include_self=True)), [self.resource])
Expand Down
19 changes: 11 additions & 8 deletions djangodav/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ def dispatch(self, request, path, *args, **kwargs):

meta = request.META.get
self.xbody = kwargs['xbody'] = None
if (request.method.lower() != 'put'
and "/xml" in meta('CONTENT_TYPE', '')
and meta('CONTENT_LENGTH', 0) != ''
and int(meta('CONTENT_LENGTH', 0)) > 0):
self.xbody = kwargs['xbody'] = etree.XPathDocumentEvaluator(
etree.parse(request, etree.XMLParser(ns_clean=True)),
namespaces=WEBDAV_NSMAP
)
try:
if (request.method.lower() != 'put'
# and "/xml" in meta('CONTENT_TYPE', '')
and meta('CONTENT_LENGTH', 0) != ''
and int(meta('CONTENT_LENGTH', 0)) > 0):
self.xbody = kwargs['xbody'] = etree.XPathDocumentEvaluator(
etree.parse(request, etree.XMLParser(ns_clean=True)),
namespaces=WEBDAV_NSMAP
)
except etree.ParseError:
return HttpResponseBadRequest("invalid XML in body")

if request.method.upper() in self._allowed_methods():
handler = getattr(self, request.method.lower(), self.http_method_not_allowed)
Expand Down