コード例 #1
0
ファイル: views.py プロジェクト: omarbenhamid/djangodav
    def relocate(self, request, path, method, *args, **kwargs):
        """
        Relocate an element

        Handles copying and moving of all sorts of elements
        :param request:
        :param path:
        :param method:
        :param args:
        :param kwargs:
        :return:
        """
        if not self.resource.exists:
            raise Http404("Resource doesn't exists")
        if not self.has_access(self.resource, 'read'):
            return self.no_access()
        # need to double unquote the HTTP_DESTINATION header (Windows 7 Compatibility)
        dst = urlparse.unquote(
            urlparse.unquote(request.META.get(
                'HTTP_DESTINATION', '')))  # .decode(self.xml_encoding)
        if not dst:
            return HttpResponseBadRequest('Destination header missing.')

        original_dst = dst

        dparts = urlparse.urlparse(dst)
        sparts = urlparse.urlparse(request.build_absolute_uri())
        if sparts.scheme != dparts.scheme or sparts.hostname != dparts.hostname:
            return HttpResponseBadGateway(
                'Source and destination must have the same scheme and host.')
        # adjust path for our base url:
        dst = self.get_resource(path=dparts.path[len(self.base_url):])
        if not dst.get_parent().exists:
            return HttpResponseConflict()
        if not self.has_access(self.resource, 'write'):
            return self.no_access()
        overwrite = request.META.get('HTTP_OVERWRITE', 'T')
        if overwrite not in ('T', 'F'):
            return HttpResponseBadRequest('Overwrite header must be T or F.')
        overwrite = (overwrite == 'T')
        if not overwrite and dst.exists:
            return HttpResponsePreconditionFailed(
                'Destination exists and overwrite False.')
        dst_exists = dst.exists
        if dst_exists:
            self.lock_class(self.resource).del_locks()
            self.lock_class(dst).del_locks()
            dst.delete()
        errors = getattr(self.resource, method)(dst, *args, **kwargs)
        if errors:
            print(errors)
            return self.build_xml_response(
                response_class=HttpResponseMultiStatus)  # WAT?
        if dst_exists:
            return HttpResponseNoContent()

        # return a response with the new location
        response = HttpResponseCreated()
        response['Location'] = original_dst
        return response
コード例 #2
0
ファイル: views.py プロジェクト: TZanke/djangodav
    def unlock(self, request, path, xbody=None, *args, **kwargss):
        if not self.has_access(self.resource, 'write'):
            return self.no_access()

        token = request.META.get('HTTP_LOCK_TOKEN')
        if not token:
            return HttpResponseBadRequest('Lock token required')
        if not self.lock_class(self.resource).release(token):
            return self.no_access()
        return HttpResponseNoContent()
コード例 #3
0
ファイル: views.py プロジェクト: TZanke/djangodav
 def delete(self, request, path, *args, **kwargs):
     if not self.resource.exists:
         raise Http404("Resource doesn't exists")
     if not self.has_access(self.resource, 'delete'):
         return self.no_access()
     self.lock_class(self.resource).del_locks()
     self.resource.delete()
     response = HttpResponseNoContent()
     self.__dict__['resource'] = self.get_resource(
         path=self.resource.get_path())
     return response
コード例 #4
0
 def put(self, request, path, *args, **kwargs):
     parent = self.resource.get_parent()
     if not parent.exists:
         raise Http404("Resource doesn't exists")
     if self.resource.is_collection:
         return self.no_access()
     if not self.resource.exists and not self.has_access(parent, 'write'):
         return self.no_access()
     if self.resource.exists and not self.has_access(
             self.resource, 'write'):
         return self.no_access()
     created = not self.resource.exists
     self.resource.write(request)
     if created:
         self.__dict__['resource'] = self.get_resource(
             path=self.resource.get_path())
         return HttpResponseCreated()
     else:
         return HttpResponseNoContent()
コード例 #5
0
ファイル: views.py プロジェクト: arcli/djangodav
 def delete(self, request, path, *args, **kwargs):
     """
     Delete an element
     :param request:
     :param path:
     :param args:
     :param kwargs:
     :return:
     """
     if not self.resource.exists:
         raise Http404("Resource doesn't exists")
     if not self.has_access(self.resource, 'delete'):
         return self.no_access()
     self.lock_class(self.resource).del_locks()
     self.resource.delete()
     response = HttpResponseNoContent()
     self.__dict__['resource'] = self.get_resource(
         path=self.resource.get_path(), user=self.user)
     return response
コード例 #6
0
ファイル: views.py プロジェクト: TZanke/djangodav
 def put(self, request, path, *args, **kwargs):
     parent = self.resource.get_parent()
     if not parent.exists:
         return HttpResponseConflict("Resource doesn't exists")
     if self.resource.is_collection:
         return HttpResponseNotAllowed(
             list(set(self._allowed_methods()) - set(['MKCOL', 'PUT'])))
     if not self.resource.exists and not self.has_access(parent, 'write'):
         return self.no_access()
     if self.resource.exists and not self.has_access(
             self.resource, 'write'):
         return self.no_access()
     created = not self.resource.exists
     self.resource.write(request)
     if created:
         self.__dict__['resource'] = self.get_resource(
             path=self.resource.get_path())
         return HttpResponseCreated()
     else:
         return HttpResponseNoContent()
コード例 #7
0
ファイル: views.py プロジェクト: TZanke/djangodav
 def relocate(self, request, path, method, *args, **kwargs):
     if not self.resource.exists:
         raise Http404("Resource doesn't exists")
     if not self.has_access(self.resource, 'read'):
         return self.no_access()
     dst = urlparse.unquote(request.META.get('HTTP_DESTINATION',
                                             '')).decode(self.xml_encoding)
     if not dst:
         return HttpResponseBadRequest('Destination header missing.')
     dparts = urlparse.urlparse(dst)
     sparts = urlparse.urlparse(request.build_absolute_uri())
     if sparts.scheme != dparts.scheme or sparts.hostname != dparts.hostname:
         return HttpResponseBadGateway(
             'Source and destination must have the same scheme and host.')
     # adjust path for our base url:
     dst = self.get_resource(path=dparts.path[len(self.base_url):])
     if not dst.get_parent().exists:
         return HttpResponseConflict()
     if not self.has_access(self.resource, 'write'):
         return self.no_access()
     overwrite = request.META.get('HTTP_OVERWRITE', 'T')
     if overwrite not in ('T', 'F'):
         return HttpResponseBadRequest('Overwrite header must be T or F.')
     overwrite = (overwrite == 'T')
     if not overwrite and dst.exists:
         return HttpResponsePreconditionFailed(
             'Destination exists and overwrite False.')
     dst_exists = dst.exists
     if dst_exists:
         self.lock_class(self.resource).del_locks()
         self.lock_class(dst).del_locks()
         dst.delete()
     errors = getattr(self.resource, method)(dst, *args, **kwargs)
     if errors:
         return self.build_xml_response(
             response_class=HttpResponseMultiStatus)  # WAT?
     if dst_exists:
         return HttpResponseNoContent()
     return HttpResponseCreated()
コード例 #8
0
ファイル: views.py プロジェクト: omarbenhamid/djangodav
    def put(self, request, path, *args, **kwargs):
        """
        Upload a new file
        :param request:
        :param path:
        :param args:
        :param kwargs:
        :return:
        """
        parent = self.resource.get_parent()
        if not parent.exists:
            return HttpResponseConflict("Resource doesn't exists")
        if self.resource.is_collection:
            return HttpResponseNotAllowed(
                list(set(self._allowed_methods()) - set(['MKCOL', 'PUT'])))
        if not self.resource.exists and not self.has_access(parent, 'write'):
            return self.no_access()
        if self.resource.exists and not self.has_access(
                self.resource, 'write'):
            return self.no_access()
        created = not self.resource.exists

        # check headers for X-File-Name
        range = request.META.get('HTTP_CONTENT_RANGE', None)
        if range == None:
            range_start = None
        else:
            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)

        if created:
            self.__dict__['resource'] = self.get_resource(
                path=self.resource.get_path())
            return HttpResponseCreated()
        else:
            return HttpResponseNoContent()