Skip to content

Commit

Permalink
Don't repeat max files in different places
Browse files Browse the repository at this point in the history
  • Loading branch information
knabar committed Dec 14, 2023
1 parent a806cc6 commit bdbfed6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions omeroweb/webclient/controller/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def getFileName(self):
" {order_by}"
)

def getFilesByObject(self, parent_type=None, parent_ids=None):
def getFilesByObject(self, parent_type=None, parent_ids=None, offset=0, limit=100):
me = (
(not self.canUseOthersAnns()) and self.conn.getEventContext().userId or None
)
Expand Down Expand Up @@ -609,7 +609,7 @@ def getFilesByObject(self, parent_type=None, parent_ids=None):

# Perform the full query and limit the results so that we don't get
# overwhelmed
params.page(0, 500) # offset, limit
params.page(offset, limit)
columns = "fa.id, ofile.name"
order_by = "ORDER BY ofile.name, fa.id DESC"
query = self.FILES_BY_OBJECT_QUERY.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1>{% trans "Upload a new file" %}:</h1>
<h1>And/or attach an existing File:</h1>
<span>
Select the attachments to add
(total: {{ total_files }}{% if total_files > 500 %}, showing 500{% endif %})
(total: {{ total_files }}{% if total_files > max_files %}, showing {{ max_files }}{% endif %})
</span>

<div>{{ form_file.files }}</div>
Expand Down
18 changes: 15 additions & 3 deletions omeroweb/webclient/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,8 @@ def batch_annotate(request, conn=None, **kwargs):
return context


MAX_FILES_IN_FILE_ANNOTATION_DIALOG = 500

@login_required()
@render_response()
def annotate_file(request, conn=None, **kwargs):
Expand Down Expand Up @@ -2385,15 +2387,21 @@ def annotate_file(request, conn=None, **kwargs):
return handlerInternalError(request, x)

if manager is not None:
total_files, files = manager.getFilesByObject()
total_files, files = manager.getFilesByObject(
offset=0,
limit=MAX_FILES_IN_FILE_ANNOTATION_DIALOG,
)
else:
manager = BaseContainer(conn)
for dtype, objs in oids.items():
if len(objs) > 0:
# NB: we only support a single data-type now. E.g. 'image' OR
# 'dataset' etc.
total_files, files = manager.getFilesByObject(
parent_type=dtype, parent_ids=[o.getId() for o in objs]
parent_type=dtype,
parent_ids=[o.getId() for o in objs],
offset=0,
limit=MAX_FILES_IN_FILE_ANNOTATION_DIALOG,
)
break

Expand Down Expand Up @@ -2421,7 +2429,11 @@ def annotate_file(request, conn=None, **kwargs):

else:
form_file = FilesAnnotationForm(initial=initial)
context = {"form_file": form_file, "total_files": total_files}
context = {
"form_file": form_file,
"total_files": total_files,
"max_files": MAX_FILES_IN_FILE_ANNOTATION_DIALOG,
}
template = "webclient/annotations/files_form.html"
context["template"] = template
return context
Expand Down

0 comments on commit bdbfed6

Please sign in to comment.