Пример #1
0
    def post(self, request):
        replace = 'replace' in request.POST

        file_ref = expose_cached_download(
            request.file.read(),
            file_extension=file_extention_from_filename(request.file.name),
            expiry=1*60*60,
        )

        # catch basic validation in the synchronous UI
        try:
            validate_fixture_file_format(file_ref.get_filename())
        except FixtureUploadError as e:
            messages.error(
                request, _('Please fix the following formatting issues in your Excel file: %s') %
                '<ul><li>{}</li></ul>'.format('</li><li>'.join(e.errors)),
                extra_tags='html'
            )
            return HttpResponseRedirect(fixtures_home(self.domain))

        # hand off to async
        task = fixture_upload_async.delay(
            self.domain,
            file_ref.download_id,
            replace,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                FixtureUploadStatusView.urlname,
                args=[self.domain, file_ref.download_id]
            )
        )
Пример #2
0
    def post(self, request):
        replace = 'replace' in request.POST

        file_ref = expose_download(request.file.read(),
                                   expiry=1*60*60)

        # catch basic validation in the synchronous UI
        try:
            validate_file_format(file_ref.get_filename())
        except FixtureUploadError as e:
            messages.error(request, unicode(e))
            return HttpResponseRedirect(fixtures_home(self.domain))

        # hand off to async
        task = fixture_upload_async.delay(
            self.domain,
            file_ref.download_id,
            replace,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                FixtureUploadStatusView.urlname,
                args=[self.domain, file_ref.download_id]
            )
        )
Пример #3
0
    def post(self, request):
        replace = 'replace' in request.POST

        file_ref = expose_cached_download(
            request.file.read(),
            file_extension=file_extention_from_filename(request.file.name),
            expiry=1*60*60,
        )

        # catch basic validation in the synchronous UI
        try:
            validate_fixture_file_format(file_ref.get_filename())
        except FixtureUploadError as e:
            messages.error(
                request, _(u'Please fix the following formatting issues in your excel file: %s') %
                '<ul><li>{}</li></ul>'.format('</li><li>'.join(e.errors)),
                extra_tags='html'
            )
            return HttpResponseRedirect(fixtures_home(self.domain))

        # hand off to async
        task = fixture_upload_async.delay(
            self.domain,
            file_ref.download_id,
            replace,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                FixtureUploadStatusView.urlname,
                args=[self.domain, file_ref.download_id]
            )
        )
Пример #4
0
    def post(self, request):
        replace = 'replace' in request.POST

        file_ref = expose_cached_download(request.file.read(),
                                   expiry=1*60*60)

        # catch basic validation in the synchronous UI
        try:
            validate_file_format(file_ref.get_filename())
        except (FixtureUploadError, JSONReaderError, HeaderValueError) as e:
            messages.error(request, _(u'Upload unsuccessful: %s') % e)
            return HttpResponseRedirect(fixtures_home(self.domain))

        # hand off to async
        task = fixture_upload_async.delay(
            self.domain,
            file_ref.download_id,
            replace,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                FixtureUploadStatusView.urlname,
                args=[self.domain, file_ref.download_id]
            )
        )
Пример #5
0
    def post(self, request):
        replace = 'replace' in request.POST

        file_ref = expose_cached_download(
            request.file.read(),
            file_extension=file_extention_from_filename(request.file.name),
            expiry=1*60*60,
        )

        # catch basic validation in the synchronous UI
        try:
            validate_file_format(file_ref.get_filename())
        except (FixtureUploadError, JSONReaderError, HeaderValueError) as e:
            messages.error(request, _(u'Upload unsuccessful: %s') % e)
            return HttpResponseRedirect(fixtures_home(self.domain))

        # hand off to async
        task = fixture_upload_async.delay(
            self.domain,
            file_ref.download_id,
            replace,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                FixtureUploadStatusView.urlname,
                args=[self.domain, file_ref.download_id]
            )
        )
Пример #6
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace, is_async = _get_fixture_upload_args_from_request(request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', six.text_type(e))

    with excel_file as filename:

        if is_async:
            with open(filename, 'r') as f:
                file_ref = expose_cached_download(
                    f.read(),
                    file_extension=file_extention_from_filename(filename),
                    expiry=1 * 60 * 60,
                )
                download_id = file_ref.download_id
                task = fixture_upload_async.delay(
                    domain,
                    download_id,
                    replace,
                )
                file_ref.set_task(task)

                status_url = "{}{}".format(
                    get_url_base(),
                    reverse('fixture_api_status', args=(domain, download_id))
                )

                curl_command = "curl -v --digest {} -u {}".format(
                    status_url, request.user.username
                )

                return UploadFixtureAPIResponse('success', {
                    "download_id": download_id,
                    "status_url": status_url,
                    "curl_command": curl_command,
                    "message": _("File uploaded successfully.")
                })

        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _('Please fix the following formatting issues in your Excel file: %s')
                % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())
Пример #7
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace, is_async, skip_orm, email = _get_fixture_upload_args_from_request(
            request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', str(e))

    with excel_file as filename:

        if is_async:
            with open(filename, 'rb') as f:
                file_ref = expose_cached_download(
                    f.read(),
                    file_extension=file_extention_from_filename(filename),
                    expiry=1 * 60 * 60,
                )
                download_id = file_ref.download_id
                task = fixture_upload_async.delay(domain,
                                                  download_id,
                                                  replace,
                                                  skip_orm,
                                                  user_email=email)
                file_ref.set_task(task)

                status_url = "{}{}".format(
                    get_url_base(),
                    reverse('fixture_api_status', args=(domain, download_id)))

                return AsyncUploadFixtureAPIResponse(
                    'success',
                    _("File has been uploaded successfully and is queued for processing."
                      ), download_id, status_url)

        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _('Please fix the following formatting issues in your Excel file: %s'
                  ) % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())