コード例 #1
0
ファイル: forms.py プロジェクト: hangnhat57/Kiwi
    def get_content(self):
        generatecss = True
        embedable = True
        odhandler = ODF2XHTML(generatecss, embedable)

        doc = load(self.uploaded_file)
        return odhandler.odf2xhtml(doc)
コード例 #2
0
ファイル: forms.py プロジェクト: MrSenko/Nitrate
    def get_content(self):
        generatecss = True
        embedable = True
        odhandler = ODF2XHTML(generatecss, embedable)

        doc = load(self.uploaded_file)
        return odhandler.odf2xhtml(doc)
コード例 #3
0
ファイル: forms.py プロジェクト: Aaln1986/Nitrate
    def clean(self, data, initial=None):
        f = super(PlanFileField, self).clean(data, initial)
        if f is None:
            return None
        elif not data and initial:
            return initial

        # Detemine the file type, raise error if the file type is not correct
        if not (data.content_type == 'text/html'
                or data.content_type == 'text/plain'
                or data.content_type == 'application/octet-stream'
                or data.content_type ==
                'application/vnd.oasis.opendocument.text'):
            raise forms.ValidationError(
                self.error_messages['invalid_file_type'])

        # Process the ODF file
        if data.content_type == 'application/octet-stream' \
                or data.content_type == \
                'application/vnd.oasis.opendocument.text':
            generatecss = True
            embedable = True
            odhandler = ODF2XHTML(generatecss, embedable)

            try:
                doc = load(data)
                plan_text = odhandler.odf2xhtml(doc)
            except Exception:
                raise forms.ValidationError(
                    self.error_messages['unexcept_odf_error'])

            return plan_text

        # We need to get a file object. We might have a path or we might
        # have to read the data into memory.
        if hasattr(data, 'temporary_file_path'):
            plan_text = data.temporary_file_path()
        elif hasattr(data, 'read'):
            plan_text = data.read()
        else:
            plan_text = data['content']

        return plan_text
コード例 #4
0
ファイル: forms.py プロジェクト: Aaln1986/Nitrate
    def clean(self, data, initial=None):
        f = super(PlanFileField, self).clean(data, initial)
        if f is None:
            return None
        elif not data and initial:
            return initial

        # Detemine the file type, raise error if the file type is not correct
        if not (data.content_type == 'text/html'
                or data.content_type == 'text/plain' or data.content_type
                == 'application/octet-stream' or data.content_type
                == 'application/vnd.oasis.opendocument.text'):
            raise forms.ValidationError(
                self.error_messages['invalid_file_type'])

        # Process the ODF file
        if data.content_type == 'application/octet-stream' \
                or data.content_type == \
                'application/vnd.oasis.opendocument.text':
            generatecss = True
            embedable = True
            odhandler = ODF2XHTML(generatecss, embedable)

            try:
                doc = load(data)
                plan_text = odhandler.odf2xhtml(doc)
            except Exception:
                raise forms.ValidationError(
                    self.error_messages['unexcept_odf_error'])

            return plan_text

        # We need to get a file object. We might have a path or we might
        # have to read the data into memory.
        if hasattr(data, 'temporary_file_path'):
            plan_text = data.temporary_file_path()
        elif hasattr(data, 'read'):
            plan_text = data.read()
        else:
            plan_text = data['content']

        return plan_text