Exemplo n.º 1
0
def export_search_results(self, userid, request_values, format, report_link):
    from arches.app.search.search_export import SearchResultsExporter
    from arches.app.models.system_settings import settings

    settings.update_from_db()

    create_user_task_record(self.request.id, self.name, userid)
    _user = User.objects.get(id=userid)
    email = request_values["email"]
    export_name = request_values["exportName"][0]
    new_request = HttpRequest()
    new_request.method = "GET"
    new_request.user = _user
    for k, v in request_values.items():
        new_request.GET.__setitem__(k, v[0])
    new_request.path = request_values["path"]
    if format == "tilexl":
        exporter = SearchResultsExporter(search_request=new_request)
        export_files, export_info = exporter.export(format, report_link)
        wb = export_files[0]["outputfile"]
        with NamedTemporaryFile() as tmp:
            wb.save(tmp.name)
            tmp.seek(0)
            stream = tmp.read()
            export_files[0]["outputfile"] = tmp
            exportid = exporter.write_export_zipfile(export_files, export_info)
    else:
        exporter = SearchResultsExporter(search_request=new_request)
        files, export_info = exporter.export(format, report_link)
        exportid = exporter.write_export_zipfile(files, export_info)

    search_history_obj = models.SearchExportHistory.objects.get(pk=exportid)

    return {
        "taskid": self.request.id,
        "msg": _(
            "Your search {} is ready for download. You have 24 hours to access this file, after which we'll automatically remove it."
        ).format(export_name),
        "notiftype_name": "Search Export Download Ready",
        "context": dict(
            greeting=_("Hello,\nYour request to download a set of search results is now ready."),
            link=exportid,
            button_text=_("Download Now"),
            closing=_("Thank you"),
            email=email,
            name=export_name,
            email_link=str(settings.ARCHES_NAMESPACE_FOR_DATA_EXPORT).rstrip("/") + "/files/" + str(search_history_obj.downloadfile),
        ),
    }
Exemplo n.º 2
0
def export_results(request):

    total = int(request.GET.get("total", 0))
    format = request.GET.get("format", "tilecsv")
    download_limit = settings.SEARCH_EXPORT_IMMEDIATE_DOWNLOAD_THRESHOLD
    if total > download_limit and format != "geojson":
        celery_worker_running = task_management.check_if_celery_available()
        if celery_worker_running is True:
            request_values = dict(request.GET)
            request_values["path"] = request.get_full_path()
            result = tasks.export_search_results.apply_async(
                (request.user.id, request_values, format),
                link=tasks.update_user_task_record.s(),
                link_error=tasks.log_error.s())
            message = _("{total} instances have been submitted for export. \
                Click the Bell icon to check for a link to download your data"
                        ).format(**locals())
            return JSONResponse({"success": True, "message": message})
        else:
            message = _(
                "Your search exceeds the {download_limit} instance download limit. Please refine your search"
            ).format(**locals())
            return JSONResponse({"success": False, "message": message})
    elif format == "tilexl":
        exporter = SearchResultsExporter(search_request=request)
        export_files, export_info = exporter.export(format)
        wb = export_files[0]["outputfile"]
        with NamedTemporaryFile() as tmp:
            wb.save(tmp.name)
            tmp.seek(0)
            stream = tmp.read()
            export_files[0]["outputfile"] = tmp
            return zip_utils.zip_response(
                export_files, zip_file_name=f"{settings.APP_NAME}_export.zip")
    else:
        exporter = SearchResultsExporter(search_request=request)
        export_files, export_info = exporter.export(format)

        if len(export_files) == 0 and format == "shp":
            message = _(
                "Either no instances were identified for export or no resources have exportable geometry nodes\
                Please confirm that the models of instances you would like to export have geometry nodes and that\
                those nodes are set as exportable")
            dest = StringIO()
            dest.write(message)
            export_files.append({"name": "error.txt", "outputfile": dest})
        return zip_utils.zip_response(
            export_files, zip_file_name=f"{settings.APP_NAME}_export.zip")
Exemplo n.º 3
0
def export_results(request):

    total = int(request.GET.get("total", 0))
    format = request.GET.get("format", "tilecsv")
    download_limit = settings.SEARCH_EXPORT_IMMEDIATE_DOWNLOAD_THRESHOLD
    if total > download_limit:
        celery_worker_running = task_management.check_if_celery_available()
        if celery_worker_running:
            req_dict = dict(request.GET)
            result = tasks.export_search_results.apply_async(
                (request.user.id, req_dict, format),
                link=tasks.update_user_task_record.s(),
                link_error=tasks.log_error.s())
            # if os.path.exists("result"): # this might not exist until after write_zip_file in task is done ?
            message = _(f"{total} instances have been submitted for export. \
                Click the bell icon to check for a notification once your export is completed and ready for download"
                        )
            return JSONResponse({"success": True, "message": message})
        else:
            message = _(
                f"Your search exceeds the {download_limit} instance download limit. Please refine your search"
            )
            return JSONResponse({"success": False, "message": message})
    else:
        exporter = SearchResultsExporter(search_request=request)
        export_files = exporter.export(format)
        return zip_utils.zip_response(
            export_files, zip_file_name=f"{settings.APP_NAME}_export.zip")
Exemplo n.º 4
0
def export_search_results(self, userid, request_values, format):
    from arches.app.search.search_export import SearchResultsExporter
    from arches.app.models.system_settings import settings

    settings.update_from_db()

    create_user_task_record(self.request.id, self.name, userid)
    _user = User.objects.get(id=userid)
    email = request_values["email"]
    export_name = request_values["exportName"][0]
    new_request = HttpRequest()
    new_request.method = "GET"
    new_request.user = _user
    for k, v in request_values.items():
        new_request.GET.__setitem__(k, v[0])
    new_request.path = request_values["path"]
    exporter = SearchResultsExporter(search_request=new_request)
    files, export_info = exporter.export(format)
    exportid = exporter.write_export_zipfile(files, export_info)

    return {
        "taskid": self.request.id,
        "msg": _(
            "Your search {} is ready for download. You have 24 hours to access this file, after which we'll automatically remove it."
        ).format(export_name),
        "notiftype_name": "Search Export Download Ready",
        "context": dict(
            greeting=_("Hello,\nYour request to download a set of search results is now ready."),
            link=exportid,
            button_text=_("Download Now"),
            closing=_("Thank you"),
            email=email,
            name=export_name,
        ),
    }
Exemplo n.º 5
0
def export_search_results(self, userid, request_dict, format):
    create_user_task_record(self.request.id, self.name, userid)
    _user = User.objects.get(id=userid)
    new_req = HttpRequest()
    new_req.method = "GET"
    new_req.user = _user
    for k, v in request_dict.items():
        new_req.GET.__setitem__(k, v[0])

    exporter = SearchResultsExporter(search_request=new_req)
    url = zip_utils.write_zip_file(exporter.export(format),
                                   return_relative_url=True)
    notif = f"<a download href='{url}'><button class='btn btn-notifs-download btn-labeled btn-sm fa fa-download'>Download File</button></a>"
    response = {"taskid": self.request.id, "notif": notif}

    return response
Exemplo n.º 6
0
def export_search_results(self, userid, request_values, format):

    from arches.app.models.system_settings import settings

    settings.update_from_db()

    create_user_task_record(self.request.id, self.name, userid)
    _user = User.objects.get(id=userid)
    email = request_values["email"]
    export_name = request_values["exportName"][0]
    new_request = HttpRequest()
    new_request.method = "GET"
    new_request.user = _user
    for k, v in request_values.items():
        new_request.GET.__setitem__(k, v[0])
    new_request.path = request_values["path"]
    exporter = SearchResultsExporter(search_request=new_request)
    files, export_info = exporter.export(format)
    exportid = exporter.write_export_zipfile(files, export_info)

    context = dict(
        greeting=
        "Hello,\nYour request to download a set of search results is now ready.",
        link=exportid,
        button_text="Download Now",
        closing="Thank you",
        email=email,
        name=export_name,
    )
    response = {
        "taskid": self.request.id,
        "msg": export_name,
        "notiftype_name": "Search Export Download Ready",
        "context": context
    }

    return response
Exemplo n.º 7
0
def export_results(request):
    exporter = SearchResultsExporter(search_request=request)
    resourceexporter = ResourceExporter(format="tilecsv")
    return resourceexporter.zip_response(exporter.export(), zip_file_name="temp.zip")
    return JSONResponse(exporter.export(), indent=4)