コード例 #1
0
ファイル: views.py プロジェクト: rodneylubwama/commcare-hq
    def post(self, request, *args, **kwargs):
        upload = request.FILES.get('bulk_upload_file')
        if not upload:
            messages.error(request, _('no file uploaded'))
            return self.get(request, *args, **kwargs)
        if not args:
            messages.error(request, _('no domain specified'))
            return self.get(request, *args, **kwargs)
        if upload.content_type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
            messages.error(
                request,
                _("Invalid file-format. Please upload a valid xlsx file."))
            return self.get(request, *args, **kwargs)

        domain = args[0]

        # stash this in soil to make it easier to pass to celery
        ONE_HOUR = 1 * 60 * 60
        file_ref = expose_cached_download(
            upload.read(),
            expiry=ONE_HOUR,
            file_extension=file_extention_from_filename(upload.name),
        )
        task = import_locations_async.delay(
            domain,
            file_ref.download_id,
        )
        # put the file_ref.download_id in cache to lookup from elsewhere
        cache.set(import_locations_task_key(domain), file_ref.download_id,
                  ONE_HOUR)
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(LocationImportStatusView.urlname,
                    args=[domain, file_ref.download_id]))
コード例 #2
0
ファイル: views.py プロジェクト: ekush/commcare-hq
    def post(self, request, *args, **kwargs):
        upload = request.FILES.get('bulk_upload_file')
        if not upload:
            messages.error(request, _('no file uploaded'))
            return self.get(request, *args, **kwargs)
        if not args:
            messages.error(request, _('no domain specified'))
            return self.get(request, *args, **kwargs)

        domain = args[0]

        # stash this in soil to make it easier to pass to celery
        file_ref = expose_cached_download(upload.read(),
                                   expiry=1*60*60)
        task = import_locations_async.delay(
            domain,
            file_ref.download_id,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                LocationImportStatusView.urlname,
                args=[domain, file_ref.download_id]
            )
        )
コード例 #3
0
    def post(self, request, *args, **kwargs):
        upload = request.FILES.get('bulk_upload_file')
        if not upload:
            messages.error(request, _('no file uploaded'))
            return self.get(request, *args, **kwargs)
        if not args:
            messages.error(request, _('no domain specified'))
            return self.get(request, *args, **kwargs)
        if upload.content_type != 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
            messages.error(request, _("Invalid file-format. Please upload a valid xlsx file."))
            return self.get(request, *args, **kwargs)

        domain = args[0]

        # stash this in soil to make it easier to pass to celery
        ONE_HOUR = 1*60*60
        file_ref = expose_cached_download(
            upload.read(),
            expiry=ONE_HOUR,
            file_extension=file_extention_from_filename(upload.name),
        )
        task = import_locations_async.delay(
            domain,
            file_ref.download_id,
        )
        # put the file_ref.download_id in cache to lookup from elsewhere
        cache.set(import_locations_task_key(domain), file_ref.download_id, ONE_HOUR)
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                LocationImportStatusView.urlname,
                args=[domain, file_ref.download_id]
            )
        )
コード例 #4
0
ファイル: views.py プロジェクト: rigambhir/commcare-hq
    def post(self, request, *args, **kwargs):
        upload = request.FILES.get('locs')
        if not upload:
            return HttpResponse(_('no file uploaded'))
        if not args:
            return HttpResponse(_('no domain specified'))

        domain = args[0]

        update_existing = bool(request.POST.get('update'))

        # stash this in soil to make it easier to pass to celery
        file_ref = expose_download(upload.read(),
                                   expiry=1*60*60)
        task = import_locations_async.delay(
            domain,
            file_ref.download_id,
            update_existing
        )
        file_ref.set_task(task)

        return HttpResponseRedirect(
            reverse(
                LocationImportStatusView.urlname,
                args=[domain, file_ref.download_id]
            )
        )
コード例 #5
0
    def post(self, request, *args, **kwargs):
        upload = request.FILES.get('bulk_upload_file')
        if not upload:
            messages.error(request, _('no file uploaded'))
            return self.get(request, *args, **kwargs)
        if not args:
            messages.error(request, _('no domain specified'))
            return self.get(request, *args, **kwargs)

        domain = args[0]

        # stash this in soil to make it easier to pass to celery
        file_ref = expose_download(upload.read(),
                                   expiry=1*60*60)
        task = import_locations_async.delay(
            domain,
            file_ref.download_id,
        )
        file_ref.set_task(task)
        return HttpResponseRedirect(
            reverse(
                LocationImportStatusView.urlname,
                args=[domain, file_ref.download_id]
            )
        )
コード例 #6
0
ファイル: views.py プロジェクト: birdsarah/core-hq
def location_import(request, domain):
    if request.method == "POST":
        upload = request.FILES.get('locs')
        if not upload:
            return HttpResponse('no file uploaded')

        # stash this in soil to make it easier to pass to celery
        file_ref = expose_download(upload.read(),
                                   expiry=1*60*60)
        download_id = uuid.uuid4().hex
        import_locations_async.delay(download_id, domain, file_ref.download_id)
        return _async_in_progress(request, domain, download_id)

    return HttpResponse("""
<form method="post" action="" enctype="multipart/form-data">
  <div><input type="file" name="locs" /></div>
  <div><button type="submit">Import locations</button></div>
</form>
""")
コード例 #7
0
ファイル: views.py プロジェクト: tsinkala/commcare-hq
def location_import(request, domain):
    if request.method == "POST":
        upload = request.FILES.get('locs')
        if not upload:
            return HttpResponse('no file uploaded')
        update_existing = bool(request.POST.get('update'))

        # stash this in soil to make it easier to pass to celery
        file_ref = expose_download(upload.read(), expiry=1 * 60 * 60)
        download_id = uuid.uuid4().hex
        import_locations_async.delay(download_id, domain, file_ref.download_id,
                                     update_existing)
        return _async_in_progress(request, domain, download_id)

    return HttpResponse("""
<form method="post" action="" enctype="multipart/form-data">
  <div><input type="file" name="locs" /></div>
  <div><input id="update" type="checkbox" name="update" /> <label for="update">Update existing?</label></div>
  <div><button type="submit">Import locations</button></div>
</form>
""")