Skip to content

Commit

Permalink
Merge branch 'warden/main' into ph_62370_merge_main_GUI_alignment_for…
Browse files Browse the repository at this point in the history
…matting
  • Loading branch information
csmith-he committed Jan 23, 2024
2 parents 47453ef + 7c4b0c8 commit e049d3c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
3 changes: 2 additions & 1 deletion arches/app/media/js/views/resource/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ require([
BaseManagerView.prototype.initialize.call(this, options);

if (location.search.indexOf('print') > 0) {
this.viewModel.loading(true);
var self = this
self.viewModel.loading(true);
setTimeout(
function() {
self.viewModel.loading(false);
Expand Down
25 changes: 23 additions & 2 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,36 @@ def get_relations(resourceinstanceid, start, limit, resourceinstance_graphid=Non
limit=limit,
resourceinstance_graphid=resourceinstance_graphid,
)

missing_related_resource = []
valid_relations = []
for resource_relation in resource_relations["relations"]:

to_resource = None
from_resource = None

try:
to_resource = resource_relation.resourceinstanceidto
from_resource = resource_relation.resourceinstanceidfrom
valid_relations.append(resource_relation)
except:
missing_related_resource.append(resource_relation.pk)

resource_relations["total"] = len(valid_relations)
resource_relations["relations"] = valid_relations

if len(missing_related_resource) > 0:
logger.warning(f"Broken resource relation records (relation primary key): {missing_related_resource}")


resource_relations["relations"] = list(
filter(lambda x: user_can_read_resource(user, x.resourceinstanceidto), resource_relations["relations"])
filter(lambda x: user_can_read_resource(user, x.resourceinstanceidto.pk), resource_relations["relations"])
)

resource_relations["relations"] = list(
filter(lambda x: user_can_read_resource(user, x.resourceinstanceidfrom), resource_relations["relations"])
filter(lambda x: user_can_read_resource(user, x.resourceinstanceidfrom.pk), resource_relations["relations"])
)


resource_relations["total"] = len(resource_relations["relations"])
ret["total"] = resource_relations["total"]
Expand Down
18 changes: 12 additions & 6 deletions arches/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def export_search_results(self, userid, request_values, format, report_link):
from arches.app.models.system_settings import settings
from arches.app.utils.message_contexts import return_message_context

logger = logging.getLogger(__name__)
settings.update_from_db()

create_user_task_record(self.request.id, self.name, userid)
Expand All @@ -71,12 +72,17 @@ def export_search_results(self, userid, request_values, format, report_link):
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, export_name)
try:
with NamedTemporaryFile(delete=False) 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, export_name)
except OSError:
logger.error("Temp file could not be created.")
raise
os.unlink(tmp.name)
else:
exporter = SearchResultsExporter(search_request=new_request)
files, export_info = exporter.export(format, report_link)
Expand Down
18 changes: 12 additions & 6 deletions arches/app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,18 @@ def export_results(request):
exporter = SearchResultsExporter(search_request=request)
export_files, export_info = exporter.export(format, report_link)
wb = export_files[0]["outputfile"]
with NamedTemporaryFile(dir=settings.TILE_EXCEL_EXPORT_TEMP_DIRECTORY,delete=settings.TILE_EXCEL_EXPORT_TEMP_FILE_DELETE) 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")
try:
with NamedTemporaryFile(delete=False) as tmp:
wb.save(tmp.name)
tmp.seek(0)
stream = tmp.read()
export_files[0]["outputfile"] = tmp
result = zip_utils.zip_response(export_files, zip_file_name=f"{settings.APP_NAME}_export.zip")
except OSError:
logger.error("Temp file could not be created.")
raise
os.unlink(tmp.name)
return result
else:
exporter = SearchResultsExporter(search_request=request)
export_files, export_info = exporter.export(format, report_link)
Expand Down

0 comments on commit e049d3c

Please sign in to comment.