Skip to content

Commit 626b830

Browse files
author
Tobias Zanke
committed
use Template view to allow additional context data
1 parent 5925667 commit 626b830

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

djangodav/views/views.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
from django.utils.decorators import method_decorator
1313
from django.utils.functional import cached_property
1414
from django.utils.http import parse_etags
15-
from django.shortcuts import render_to_response
1615
from django.views.decorators.csrf import csrf_exempt
17-
from django.views.generic import View
16+
from django.views.generic import TemplateView
1817

1918
from djangodav.responses import ResponseException, HttpResponsePreconditionFailed, HttpResponseCreated, HttpResponseNoContent, \
2019
HttpResponseConflict, HttpResponseMediatypeNotSupported, HttpResponseBadGateway, \
@@ -25,7 +24,7 @@
2524

2625
PATTERN_IF_DELIMITER = re.compile(r'(<([^>]+)>)|(\(([^\)]+)\))')
2726

28-
class DavView(View):
27+
class DavView(TemplateView):
2928
resource_class = None
3029
lock_class = None
3130
acl_class = None
@@ -173,6 +172,12 @@ def evaluate_conditions(self, res):
173172
cond_if = '<*>' + cond_if
174173
#for (tmpurl, url, tmpcontent, content) in PATTERN_IF_DELIMITER.findall(cond_if):
175174

175+
def get_context_data(self, **kwargs):
176+
context = super(DavView, self).get_context_data(**kwargs)
177+
context['resource'] = self.resource
178+
context['base_url'] = self.base_url
179+
return context
180+
176181
def get(self, request, path, head=False, *args, **kwargs):
177182
if not self.resource.exists:
178183
raise Http404("Resource doesn't exists")
@@ -192,7 +197,7 @@ def get(self, request, path, head=False, *args, **kwargs):
192197
response['Content-Length'] = self.resource.getcontentlength
193198
response.content = self.resource.read()
194199
elif not head:
195-
response = render_to_response(self.template_name, dict(resource=self.resource, base_url=self.base_url))
200+
response = super(DavView, self).get(request, *args, **kwargs)
196201
response['Last-Modified'] = self.resource.getlastmodified
197202
return response
198203

0 commit comments

Comments
 (0)