예제 #1
0
파일: utils.py 프로젝트: lezardrouge/tracim
    def create_file(self):
        """
        Called when this is a new file; will create a new Content initialized with the correct content
        """

        is_temporary = self._file_name.startswith(
            ".~") or self._file_name.startswith("~")
        try:
            with self._session.no_autoflush:
                file = self._api.create(
                    filename=self._file_name,
                    content_type_slug=content_type_list.File.slug,
                    workspace=self._workspace,
                    parent=self._parent,
                    is_temporary=is_temporary,
                    do_save=False,
                )
                self._api.update_file_data(
                    file,
                    self._file_name,
                    util.guessMimeType(self._file_name),
                    self._file_stream.read(),
                )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc
        self._api.save(file, ActionDescription.CREATION)
예제 #2
0
파일: utils.py 프로젝트: tracim/tracim
    def create_file(self):
        """
        Called when this is a new file; will create a new Content initialized with the correct content
        """

        is_temporary = self._file_name.startswith('.~') or self._file_name.startswith('~')
        try:
            with self._session.no_autoflush:
                file = self._api.create(
                    filename=self._file_name,
                    content_type_slug=content_type_list.File.slug,
                    workspace=self._workspace,
                    parent=self._parent,
                    is_temporary=is_temporary,
                    do_save=False,
                )
                self._api.update_file_data(
                    file,
                    self._file_name,
                    util.guessMimeType(self._file_name),
                    self._file_stream.read()
                )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc
        self._api.save(file, ActionDescription.CREATION)
    def getContentType(self):
#        (mimetype, _mimeencoding) = mimetypes.guess_type(self.path)
#        print "mimetype(%s): %r, %r" % (self.path, mimetype, _mimeencoding)
#        if not mimetype:
#            mimetype = "application/octet-stream"
#        print "mimetype(%s): return %r" % (self.path, mimetype)
#        return mimetype
        return util.guessMimeType(self.path)
예제 #4
0
 def getContentType(self):
     #        (mimetype, _mimeencoding) = mimetypes.guess_type(self.path)
     #        print "mimetype(%s): %r, %r" % (self.path, mimetype, _mimeencoding)
     #        if not mimetype:
     #            mimetype = "application/octet-stream"
     #        print "mimetype(%s): return %r" % (self.path, mimetype)
     #        return mimetype
     return util.guessMimeType(self.path)
예제 #5
0
    def getContentType(self):
        if not os.path.isfile(self.filePath):
            return "text/html"
#        (mimetype, _mimeencoding) = mimetypes.guess_type(self.filePath)
#        if not mimetype:
#            mimetype = "application/octet-stream"
#        return mimetype
        return util.guessMimeType(self.filePath)
예제 #6
0
    def getContentType(self):
        if self.isCollection:
            return None
#        (mimetype, _mimeencoding) = mimetypes.guess_type(self.path)  
#        if not mimetype:
#            return "application/octet-stream" 
#        return mimetype
        return util.guessMimeType(self.path)
예제 #7
0
    def getContentType(self):
        if self.isCollection:
            return None
#        (mimetype, _mimeencoding) = mimetypes.guess_type(self.path)
#        if not mimetype:
#            return "application/octet-stream"
#        return mimetype
        return util.guessMimeType(self.path)
예제 #8
0
    def getContentType(self):
        if not os.path.isfile(self.filePath):
            return "text/html"
#        (mimetype, _mimeencoding) = mimetypes.guess_type(self.filePath) 
#        if not mimetype:
#            mimetype = "application/octet-stream" 
#        return mimetype
        return util.guessMimeType(self.filePath)
예제 #9
0
    def update_file(self):
        """
        Called when we're updating an existing content; we create a new revision and update the file content
        """

        with new_revision(self._content):
            self._api.update_file_data(
                self._content, self._file_name,
                util.guessMimeType(self._content.file_name),
                self._file_stream.read())

            self._api.save(self._content, ActionDescription.EDITION)
예제 #10
0
    def update_file(self):
        """
        Called when we're updating an existing content; we create a new revision and update the file content
        """

        with new_revision(self._content):
            self._api.update_file_data(
                self._content,
                self._file_name,
                util.guessMimeType(self._content.file_name),
                self._file_stream.read()
            )

            self._api.save(self._content, ActionDescription.REVISION)
예제 #11
0
    def update_file(self):
        """
        Called when we're updating an existing content; we create a new revision and update the file content
        """

        with new_revision(
                session=self._session,
                content=self._content,
                tm=transaction.manager,
        ):
            self._api.update_file_data(
                self._content, self._file_name,
                util.guessMimeType(self._content.file_name),
                self._file_stream.read())

            self._api.save(self._content, ActionDescription.REVISION)
예제 #12
0
    def create_file(self):
        """
        Called when this is a new file; will create a new Content initialized with the correct content
        """

        is_temporary = self._file_name.startswith(
            '.~') or self._file_name.startswith('~')

        file = self._api.create(content_type=ContentType.File,
                                workspace=self._workspace,
                                parent=self._parent,
                                is_temporary=is_temporary)

        self._api.update_file_data(file, self._file_name,
                                   util.guessMimeType(self._file_name),
                                   self._file_stream.read())

        self._api.save(file, ActionDescription.CREATION)
예제 #13
0
파일: utils.py 프로젝트: lezardrouge/tracim
    def update_file(self):
        """
        Called when we're updating an existing content; we create a new revision and update the file content
        """
        try:
            with new_revision(session=self._session,
                              content=self._content,
                              tm=transaction.manager):
                self._api.update_file_data(
                    self._content,
                    self._file_name,
                    util.guessMimeType(self._content.file_name),
                    self._file_stream.read(),
                )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        self._api.save(self._content, ActionDescription.REVISION)
예제 #14
0
파일: utils.py 프로젝트: tracim/tracim
    def update_file(self):
        """
        Called when we're updating an existing content; we create a new revision and update the file content
        """
        try:
            with new_revision(
                    session=self._session,
                    content=self._content,
                    tm=transaction.manager,
            ):
                self._api.update_file_data(
                    self._content,
                    self._file_name,
                    util.guessMimeType(self._content.file_name),
                    self._file_stream.read()
                )
        except TracimException as exc:
            raise DAVError(HTTP_FORBIDDEN) from exc

        self._api.save(self._content, ActionDescription.REVISION)
예제 #15
0
    def create_file(self):
        """
        Called when this is a new file; will create a new Content initialized with the correct content
        """

        is_temporary = self._file_name.startswith(
            '.~') or self._file_name.startswith('~')
        with self._session.no_autoflush:
            file = self._api.create(
                filename=self._file_name,
                content_type_slug=content_type_list.File.slug,
                workspace=self._workspace,
                parent=self._parent,
                is_temporary=is_temporary,
                do_save=False,
            )
            self._api.update_file_data(file, self._file_name,
                                       util.guessMimeType(self._file_name),
                                       self._file_stream.read())
        self._api.save(file, ActionDescription.CREATION)
예제 #16
0
    def create_file(self):
        """
        Called when this is a new file; will create a new Content initialized with the correct content
        """

        is_temporary = self._file_name.startswith('.~') or self._file_name.startswith('~')

        file = self._api.create(
            content_type=ContentType.File,
            workspace=self._workspace,
            parent=self._parent,
            is_temporary=is_temporary
        )

        self._api.update_file_data(
            file,
            self._file_name,
            util.guessMimeType(self._file_name),
            self._file_stream.read()
        )

        self._api.save(file, ActionDescription.CREATION)
예제 #17
0
 def getContentType(self):
     return util.guessMimeType(self.path)