Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Several smaller updates #2

Open
wants to merge 5 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
17 changes: 15 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Basic Authentication on Windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Be careful when using Basic Authentication on Windows, as it is not enabled by default (for non SSL sites). You can
either set ``BasicAuthLevel`` to ``2`` in the `Windows Registry <http://www.windowspage.de/tipps/022703.html>`_ , or
either set the registry parameter ``BasicAuthLevel`` to ``2`` in ``HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\WebClient\Parameters`` - see `this help article <http://www.windowspage.de/tipps/022703.html>`_ - or
just make sure your site uses SSL and has a valid SSL certificate.


Expand Down Expand Up @@ -219,7 +219,7 @@ This example is a bit more complex, as it requires two Django models and some ha

root = "/path/to/folder"

def write(self, request, temp_file=None):
def write(self, request, temp_file=None, range_start=None):
size = len(request.body)

# calculate a hashsum of the request (ToDo: probably need to replace this with SHA1 or such, and maybe add a salt)
Expand Down Expand Up @@ -283,3 +283,16 @@ This example is a bit more complex, as it requires two Django models and some ha
(r'^dbdav(?P<path>.*)$', DavView.as_view(resource_class=MyFSDavResource, lock_class=DummyLock,
acl_class=FullAcl)),
)


Settings
--------

The following Django settings are available:

- `DJANGODAV_X_REDIRECT` (Boolean, Default: False) - enable `X-Accel-Redirect` feature for nginx
- `DJANGODAV_X_REDIRECT_PREFIX` (String, Default: '') - base path used when `X-Accel-Redirect` is used
- `DJANGODAV_ENABLE_HTTP_X_FILE_NAME` (Boolean, Default: False) - allow temp-file uploads via the webserver (uses the `X-File-Name` header)

For the nginx/webserver related features, please take a look at nginx configuration in the `DjangoDav example repo <https://github.com/anx-ckreuzberger/djangodav-example-app>`_, e.g.: https://github.com/anx-ckreuzberger/djangodav-example-app/blob/master/docker/nginx/django.conf

4 changes: 2 additions & 2 deletions djangodav/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
# You should have received a copy of the GNU Affero General Public License
# along with DjangoDav. If not, see <http://www.gnu.org/licenses/>.

VERSION = (0, 0, 1, 'beta', 27)
__version__ = "0.0.1b27"
VERSION = (0, 0, 2, 'beta', 1)
__version__ = "0.0.2b1"
2 changes: 1 addition & 1 deletion djangodav/db/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def read(self):
raise NotImplementedError

# ToDo: here it is called `content`, but in our example it is called `request` ... why?
def write(self, content, temp_file=None):
def write(self, content, temp_file=None, range_start=None):
raise NotImplementedError

def delete(self):
Expand Down
2 changes: 1 addition & 1 deletion djangodav/fs/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def write(self, request, temp_file=None, range_start=None):
if temp_file:
# move temp file (e.g., coming from nginx)
shutil.move(temp_file, self.get_abs_path())
elif range_start == None:
elif range_start is None:
# open binary file and write to disk
with open(self.get_abs_path(), 'wb') as dst:
shutil.copyfileobj(request, dst)
Expand Down
2 changes: 1 addition & 1 deletion djangodav/templates/djangodav/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<head></head>

<body>
<h1>Index of {{ resource.get_displaypath }}</h1>
<h1>Index of {{ resource.get_escaped_path }}</h1>
<table>
<tr>
<th>Name</th>
Expand Down
24 changes: 17 additions & 7 deletions djangodav/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# get settings
DJANGODAV_X_REDIRECT = getattr(settings, 'DJANGODAV_X_REDIRECT', None)
DJANGODAV_X_REDIRECT_PREFIX = getattr(settings, 'DJANGODAV_X_REDIRECT_PREFIX', "")
DJANGODAV_ENABLE_HTTP_X_FILE_NAME = getattr(settings, 'DJANGODAV_ENABLE_HTTP_X_FILE_NAME', False)


class DavView(TemplateView):
Expand Down Expand Up @@ -302,16 +303,25 @@ def put(self, request, path, *args, **kwargs):
return self.no_access()
created = not self.resource.exists

# check headers for X-File-Name
file_name_forwarding = None
# check headers for X-File-Name (temp file upload)
if DJANGODAV_ENABLE_HTTP_X_FILE_NAME:
file_name_forwarding = request.META.get('HTTP_X_FILE_NAME', None)

# check headers for HTTP Content Range (allow partial uploads)
range = request.META.get('HTTP_CONTENT_RANGE', None)
if range == None:
range_start=None
if range is None:
range_start = None
else:
m=PATTERN_CONTENT_RANGE.match(range)
if not m: return HttpResponseBadRequest("Invalid Content-Range")
m = PATTERN_CONTENT_RANGE.match(range)

if not m:
return HttpResponseBadRequest("Invalid Content-Range")

range_start=int(m[1])

self.resource.write(request, range_start=range_start)

# write the file
self.resource.write(request, range_start=range_start, temp_file=file_name_forwarding)

if created:
self.__dict__['resource'] = self.get_resource(path=self.resource.get_path())
Expand Down