Пример #1
0
    def get_content(self):
        generatecss = True
        embedable = True
        odhandler = ODF2XHTML(generatecss, embedable)

        doc = load(self.uploaded_file)
        return odhandler.odf2xhtml(doc)
Пример #2
0
    def get_content(self):
        generatecss = True
        embedable = True
        odhandler = ODF2XHTML(generatecss, embedable)

        doc = load(self.uploaded_file)
        return odhandler.odf2xhtml(doc)
Пример #3
0
    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
    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