当前位置: 首页>>代码示例>>Python>>正文


Python forms.UploadFileForm类代码示例

本文整理汇总了Python中reviewboard.attachments.forms.UploadFileForm的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm类的具体用法?Python UploadFileForm怎么用?Python UploadFileForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UploadFileForm类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_utf16_thumbnail

    def test_utf16_thumbnail(self):
        """Testing file attachment thumbnail generation for UTF-16 files"""
        filename = os.path.join(os.path.dirname(__file__), "testdata", "utf-16.txt")
        with open(filename) as f:
            review_request = self.create_review_request(publish=True)

            file = SimpleUploadedFile(f.name, f.read(), content_type="text/plain;charset=utf-16le")
            form = UploadFileForm(review_request, files={"path": file})
            form.is_valid()

            file_attachment = form.create()

            self.assertEqual(
                file_attachment.thumbnail,
                '<div class="file-thumbnail"> <div class="file-thumbnail-clipp'
                'ed"><pre>UTF-16le encoded sample plain-text file</pre><pre>'
                "\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e"
                "\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e"
                "\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e"
                "\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e\u203e</pre>"
                "<pre></pre><pre>Markus Kuhn [\u02c8ma\u02b3k\u028as ku\u02d0"
                "n] &lt;http://www.cl.cam.ac.uk/~mgk25/&gt; \u2014 2002-07-25"
                "</pre><pre></pre><pre></pre><pre>The ASCII compatible UTF-8 "
                "encoding used in this plain-text file</pre><pre>is defined "
                "in Unicode, ISO 10646-1, and RFC 2279.</pre><pre></pre><pre>"
                "</pre><pre>Using Unicode/UTF-8, you can write in emails and "
                "source code things such as</pre><pre></pre><pre>Mathematics "
                "and sciences:</pre><pre></pre><pre>  \u222e E\u22c5da = Q,  "
                "n \u2192 \u221e, \u2211 f(i) = \u220f g(i),      \u23a7\u23a1"
                "\u239b\u250c\u2500\u2500\u2500\u2500\u2500\u2510\u239e\u23a4"
                "\u23ab</pre><pre>                                           "
                " \u23aa\u23a2\u239c\u2502a\xb2+b\xb3 \u239f\u23a5\u23aa"
                "</pre><pre>  \u2200x\u2208</pre></div></div>",
            )
开发者ID:priestd09,项目名称:reviewboard,代码行数:34,代码来源:tests.py

示例2: setUp

    def setUp(self):
        uploaded_file = SimpleUploadedFile("test.txt", b"<p>This is a test</p>", content_type="text/plain")

        review_request = self.create_review_request(publish=True)

        form = UploadFileForm(review_request, files={"path": uploaded_file})
        self.assertTrue(form.is_valid())
开发者ID:priestd09,项目名称:reviewboard,代码行数:7,代码来源:tests.py

示例3: test_utf16_thumbnail

    def test_utf16_thumbnail(self):
        """Testing file attachment thumbnail generation for UTF-16 files"""
        filename = os.path.join(os.path.dirname(__file__),
                                'testdata', 'utf-16.txt')
        with open(filename) as f:
            review_request = self.create_review_request(publish=True)

            file = SimpleUploadedFile(f.name, f.read(),
                                      content_type='text/plain;charset=utf-16le')
            form = UploadFileForm(review_request, files={'path': file})
            form.is_valid()

            file_attachment = form.create()

            self.assertEqual(file_attachment.thumbnail,
                             '<div class="file-thumbnail-clipped"><pre>'
                             'UTF-16le encoded sample plain-text file</pre>'
                             '<pre>\u203e\u203e\u203e\u203e\u203e\u203e'
                             '\u203e\u203e\u203e\u203e\u203e\u203e\u203e'
                             '\u203e\u203e\u203e\u203e\u203e\u203e\u203e'
                             '\u203e\u203e\u203e\u203e\u203e\u203e\u203e'
                             '\u203e\u203e\u203e\u203e\u203e\u203e\u203e'
                             '\u203e\u203e\u203e\u203e\u203e</pre><pre>'
                             '</pre><pre>Markus Kuhn [\u02c8ma\u02b3k\u028as'
                             ' ku\u02d0n] &lt;http://www.cl.cam.ac.uk/~mgk25/'
                             '&gt; \u2014 2002-07-25</pre><pre></pre><pre>'
                             '</pre><pre>The ASCII compatible UTF-8 encoding '
                             'used in this plain-text file</pre><pre>is '
                             'defined in Unicode, ISO 10646-1, and RFC 2279.'
                             '</pre></div>')
开发者ID:down-networks,项目名称:reviewboard,代码行数:30,代码来源:tests.py

示例4: test_upload_file

    def test_upload_file(self):
        """Testing uploading a file attachment"""
        review_request = self.create_review_request(publish=True)

        file = self.make_uploaded_file()
        form = UploadFileForm(review_request, files={"path": file})
        self.assertTrue(form.is_valid())

        file_attachment = form.create()
        self.assertTrue(os.path.basename(file_attachment.file.name).endswith("__trophy.png"))
        self.assertEqual(file_attachment.mimetype, "image/png")
开发者ID:priestd09,项目名称:reviewboard,代码行数:11,代码来源:tests.py

示例5: update

    def update(self, request, *args, **kwargs):
        try:
            filediff = self.get_object(request, *args, **kwargs)
            review_request_draft = filediff.diffset.review_request_draft.get()
        except ObjectDoesNotExist:
            return DOES_NOT_EXIST

        if not review_request_draft.is_mutable_by(request.user):
            return self._no_access_error(request.user)

        if 'dest_attachment_file' in request.FILES:
            if not filediff.binary:
                return INVALID_FORM_DATA, {
                    'fields': {
                        'dest_attachment_file': [
                            'Cannot upload a file attachment to a '
                            'non-binary file in a diff.',
                        ]
                    }
                }

            try:
                # Check if there's already an attachment. If so, bail.
                attachment = FileAttachment.objects.get_for_filediff(filediff)

                return INVALID_FORM_DATA, {
                    'fields': {
                        'dest_attachment_file': [
                            'There is already a file attachment associated '
                            'with this binary file.',
                        ]
                    }
                }
            except ObjectDoesNotExist:
                pass

            dest_attachment_file = request.FILES.get('dest_attachment_file')

            form = UploadFileForm({}, {
                'path': dest_attachment_file,
            })

            if not form.is_valid():
                return INVALID_FORM_DATA, {
                    'fields': self._get_form_errors(form),
                }

            form.create(dest_attachment_file,
                        review_request_draft.review_request,
                        filediff)

        return 200, {
            self.item_result_key: filediff,
        }
开发者ID:EricSchles,项目名称:reviewboard,代码行数:54,代码来源:draft_filediff.py

示例6: test_upload_file_with_history

    def test_upload_file_with_history(self):
        """Testing uploading a file attachment to an existing
        FileAttachmentHistory
        """
        review_request_1 = self.create_review_request(publish=True)
        history = FileAttachmentHistory.objects.create(display_position=0)
        review_request_1.file_attachment_histories.add(history)

        file = self.make_uploaded_file()
        form = UploadFileForm(review_request_1, data={"attachment_history": history.pk}, files={"path": file})
        self.assertTrue(form.is_valid())
        form.create()
开发者ID:priestd09,项目名称:reviewboard,代码行数:12,代码来源:tests.py

示例7: test_upload_file_with_history_mismatch

    def test_upload_file_with_history_mismatch(self):
        """Testing uploading a file attachment to an existing
        FileAttachmentHistory with a mismatched review request
        """
        review_request_1 = self.create_review_request(publish=True)
        review_request_2 = self.create_review_request(publish=True)

        history = FileAttachmentHistory.objects.create(display_position=0)
        review_request_1.file_attachment_histories.add(history)

        form = UploadFileForm(review_request_2, data={"attachment_history": history.pk}, files={"path": file})
        self.assertFalse(form.is_valid())
开发者ID:priestd09,项目名称:reviewboard,代码行数:12,代码来源:tests.py

示例8: test_upload_file

    def test_upload_file(self):
        """Testing uploading a file attachment"""
        file = self.make_uploaded_file()
        form = UploadFileForm(files={
            'path': file,
        })
        self.assertTrue(form.is_valid())

        review_request = ReviewRequest.objects.get(pk=1)
        file_attachment = form.create(file, review_request)
        self.assertTrue(os.path.basename(file_attachment.file.name).endswith(
            '__trophy.png'))
        self.assertEqual(file_attachment.mimetype, 'image/png')
开发者ID:helloconan,项目名称:reviewboard,代码行数:13,代码来源:tests.py

示例9: setUp

    def setUp(self):
        uploaded_file = SimpleUploadedFile(
            'test.txt',
            b'<p>This is a test</p>',
            content_type='text/plain')

        review_request = self.create_review_request(publish=True)

        form = UploadFileForm(review_request, files={
            'path': uploaded_file,
        })
        self.assertTrue(form.is_valid())

        self.file_attachment = form.create()
开发者ID:gongfuPanada,项目名称:reviewboard,代码行数:14,代码来源:tests.py

示例10: update

    def update(self, request, *args, **kwargs):
        try:
            filediff = self.get_object(request, *args, **kwargs)
            review_request_draft = filediff.diffset.review_request_draft.get()
        except ObjectDoesNotExist:
            return DOES_NOT_EXIST

        if not review_request_draft.is_mutable_by(request.user):
            return self._no_access_error(request.user)

        if "dest_attachment_file" in request.FILES:
            if not filediff.binary:
                return (
                    INVALID_FORM_DATA,
                    {
                        "fields": {
                            "dest_attachment_file": [
                                "Cannot upload a file attachment to a " "non-binary file in a diff."
                            ]
                        }
                    },
                )

            try:
                # Check if there's already an attachment. If so, bail.
                attachment = FileAttachment.objects.get_for_filediff(filediff)

                return (
                    INVALID_FORM_DATA,
                    {
                        "fields": {
                            "dest_attachment_file": [
                                "There is already a file attachment associated " "with this binary file."
                            ]
                        }
                    },
                )
            except ObjectDoesNotExist:
                pass

            dest_attachment_file = request.FILES.get("dest_attachment_file")

            form = UploadFileForm({}, {"path": dest_attachment_file})

            if not form.is_valid():
                return INVALID_FORM_DATA, {"fields": self._get_form_errors(form)}

            form.create(dest_attachment_file, review_request_draft.review_request, filediff)

        return 200, {self.item_result_key: filediff}
开发者ID:prodigeni,项目名称:reviewboard,代码行数:50,代码来源:draft_filediff.py

示例11: test_upload_file

    def test_upload_file(self):
        """Testing uploading a file attachment."""
        filename = os.path.join(settings.STATIC_ROOT, "rb", "images", "trophy.png")
        f = open(filename, "r")
        file = SimpleUploadedFile(f.name, f.read(), content_type="image/png")
        f.close()

        form = UploadFileForm(files={"path": file})
        form.is_valid()
        print form.errors
        self.assertTrue(form.is_valid())

        review_request = ReviewRequest.objects.get(pk=1)
        file_attachment = form.create(file, review_request)
        self.assertEqual(os.path.basename(file_attachment.file.name), "trophy.png")
        self.assertEqual(file_attachment.mimetype, "image/png")
开发者ID:JustinTulloss,项目名称:reviewboard,代码行数:16,代码来源:tests.py

示例12: create

    def create(self, request, *args, **kwargs):
        """Creates a new file from a file attachment.

        This accepts any file type and associates it with a draft of a
        review request.

        It is expected that the client will send the data as part of a
        :mimetype:`multipart/form-data` mimetype. The file's name
        and content should be stored in the ``path`` field. A typical request
        may look like::

            -- SoMe BoUnDaRy
            Content-Disposition: form-data; name=path; filename="foo.zip"

            <Content here>
            -- SoMe BoUnDaRy --
        """
        try:
            review_request = \
                resources.review_request.get_object(request, *args, **kwargs)
        except ObjectDoesNotExist:
            return DOES_NOT_EXIST

        if not review_request.is_mutable_by(request.user):
            return self.get_no_access_error(request)

        form_data = request.POST.copy()
        form = UploadFileForm(review_request, form_data, request.FILES)

        if not form.is_valid():
            return INVALID_FORM_DATA, {
                'fields': self._get_form_errors(form),
            }

        try:
            file = form.create()
        except ValueError as e:
            return INVALID_FORM_DATA, {
                'fields': {
                    'path': [six.text_type(e)],
                },
            }

        return 201, {
            self.item_result_key: self.serialize_object(
                file, request=request, *args, **kwargs),
        }
开发者ID:bcbirkhauser,项目名称:reviewboard,代码行数:47,代码来源:base_file_attachment.py


注:本文中的reviewboard.attachments.forms.UploadFileForm类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。