Skip to content

Commit

Permalink
Merge pull request #952 from ImageMarkup/django-51-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna authored Aug 28, 2024
2 parents 1d6ad59 + 9eead09 commit 2aad400
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 79 deletions.
3 changes: 1 addition & 2 deletions isic/core/templates/core/collection_detail.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends 'core/base.html' %}
{% load localtime %}
{% load spurl %}
{% load get_key %}
{% load humanize %}

Expand Down Expand Up @@ -129,7 +128,7 @@
</span>
</div>
<div class="flex-none">
<button class="btn btn-sm btn-ghost" @click="resetImages('{% spurl base=request.get_full_path remove_query_param="image_removal_mode" %}')">Abort</button>
<button class="btn btn-sm btn-ghost" @click="resetImages('{% url 'core/collection-detail' collection.id %}')">Abort</button>
<button class="btn btn-sm btn-error" @click="deleteImages()">Remove</button>
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions isic/core/templates/core/collection_list.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% extends 'core/base.html' %}
{% load humanize %}
{% load get_key %}
{% load spurl %}

{% block content %}
<div class="mb-5 flex flex-col justify-between">
Expand All @@ -13,20 +12,20 @@
</div>
<div class="my-4">
{% url 'core/collection-list' as base %}
<a class="text-white" href="{% spurl base=base query="pinned=true" %}">
<a class="text-white" href="{% querystring pinned="true" shared_with_me=None mine=None %}">
<button class="btn btn-secondary primary gap-2">
Pinned
<div class="badge badge-accent">{{ counts.pinned }}</div>
</button>
</a>
{% if request.user.is_authenticated %}
<a class="text-white" href="{% spurl base=base query="shared_with_me=true" %}">
<a class="text-white" href="{% querystring pinned=None shared_with_me="true" mine=None %}">
<button class="btn btn-secondary primary gap-2">
Shared with Me
<div class="badge badge-accent">{{ counts.shared_with_me }}</div>
</button>
</a>
<a class="text-white" href="{% spurl base=base query="mine=true" %}">
<a class="text-white" href="{% querystring pinned=None shared_with_me=None mine="true" %}">
<button class="btn btn-secondary primary gap-2">
Mine
<div class="badge badge-accent">{{ counts.mine }}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% load spurl %}

<div class="relative inline-block text-left" x-data="{open: false}">
<div>
<button @click.away="open = false" @click="open = !open" type="button"
Expand Down Expand Up @@ -33,7 +31,7 @@
class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem"
tabindex="-1" id="menu-item-0">Edit Collection</a>
{% if not image_removal_mode %}
<a href="{% spurl base=request.get_full_path set_query=" image_removal_mode=1" %}"
<a href="{% querystring image_removal_mode="1" %}"
class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem"
tabindex="-1" id="menu-item-0">Remove Images</a>
{% endif %}
Expand Down
10 changes: 1 addition & 9 deletions isic/ingest/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ class AccessionAdmin(StaffReadonlyAdmin):
def human_original_blob_size(self, obj):
return filesizeformat(obj.original_blob_size)

@admin.display(ordering="cohort")
def cohort(self, obj):
return obj.cohort

@admin.display()
def thumbnail_image(self, obj):
return mark_safe(f'<img src="{obj.thumbnail_256.url}" />') # noqa: S308
Expand All @@ -239,14 +235,10 @@ def thumbnail_image(self, obj):
@admin.register(AccessionReview)
class AccessionReviewAdmin(StaffReadonlyAdmin):
list_select_related = ["accession", "creator", "accession__cohort"]
list_display = ["id", "cohort", "accession", "creator", "reviewed_at", "value"]
list_display = ["id", "accession__cohort", "accession", "creator", "reviewed_at", "value"]

autocomplete_fields = ["accession", "creator"]

@admin.display(description="Cohort")
def cohort(self, obj):
return obj.accession.cohort


@admin.register(ZipUpload)
class ZipAdmin(DjangoObjectActions, StaffReadonlyAdmin):
Expand Down
4 changes: 1 addition & 3 deletions isic/ingest/templates/ingest/partials/cohort_actions.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{% load spurl %}

<div class="relative inline-block text-left" x-data="{open: false}">
<div>
<button @click.away="open = false" @click="open = !open" type="button" class="inline-flex justify-center w-full rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500" id="menu-button" aria-expanded="true" aria-haspopup="true">
Expand All @@ -17,7 +15,7 @@
<div class="py-1" role="none">
{% url 'cohort-review' cohort.pk as review_url %}
<a href="{{ review_url }}" class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">Review Cohort</a>
<a href="{% spurl base=review_url add_query="grouped_by_lesion=1" %}" class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">Review Cohort by Lesion</a>
<a href="{{ review_url }}{% querystring grouped_by_lesion="1" %}" class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">Review Cohort by Lesion</a>
</div>
<div class="py-1" role="none">
<a href="{% url 'upload/cohort-files' cohort.pk %}" class="hover:bg-gray-100 hover:text-gray-900 text-gray-700 block px-4 py-2 text-sm" role="menuitem" tabindex="-1" id="menu-item-0">Add additional files</a>
Expand Down
12 changes: 2 additions & 10 deletions isic/login/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class UserAdmin(BaseUserAdmin, StaffReadonlyAdmin):
"email",
"first_name",
"last_name",
"girder_id",
"hash_id",
"profile__girder_id",
"profile__hash_id",
"is_staff",
]
search_fields = [
Expand All @@ -27,14 +27,6 @@ class UserAdmin(BaseUserAdmin, StaffReadonlyAdmin):
search_help_text = "Search by names, email addresses, girder_id, or hash_id."
ordering = ["-date_joined"]

@admin.display(ordering="profile__hash_id")
def hash_id(self, obj):
return obj.profile.hash_id

@admin.display(ordering="profile__girder_id")
def girder_id(self, obj):
return obj.profile.girder_id


admin.site.unregister(User)
admin.site.register(User, UserAdmin)
1 change: 0 additions & 1 deletion isic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def mutate_configuration(configuration: ComposedConfiguration) -> None:
"s3_file_field",
"django_object_actions",
"django_json_widget",
"spurl",
"widget_tweaks",
]

Expand Down
6 changes: 1 addition & 5 deletions isic/stats/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def queryset(self, request, queryset):

@admin.register(ImageDownload)
class ImageDownloadAdmin(StaffReadonlyAdmin):
list_display = ["isic_id", "download_time", "ip_address"]
list_display = ["image__isic__id", "download_time", "ip_address"]
list_select_related = ["image"]
search_fields = ["image__isic__id", "ip_address", "user_agent"]
search_help_text = "Search by ISIC ID, IP Address, or User Agent."
Expand All @@ -40,7 +40,3 @@ def get_queryset(self, request):
# .annotate adds a join to the COUNT query which slows down the whole page.
# .select_related only adds a join to the data selection query.
return qs.select_related("image")

@admin.display(ordering="isic_id")
def isic_id(self, obj: ImageDownload):
return obj.image.isic_id
18 changes: 12 additions & 6 deletions isic/studies/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Any

from django.contrib import admin
from django.db.models import Count, Exists, OuterRef
from django.db.models.expressions import F
from django.db.models.query import QuerySet
from django.http import HttpRequest
from girder_utils.admin import ReadonlyTabularInline

from isic.core.admin import StaffReadonlyAdmin
Expand Down Expand Up @@ -79,13 +83,15 @@ def responded(self, obj):

@admin.register(Response)
class ResponseAdmin(StaffReadonlyAdmin):
list_display = ["study", "annotator", "question", "choice"]

def study(self, obj):
return obj.annotation.study
list_display = ["annotation__study", "annotation__annotator", "question", "choice"]

def annotator(self, obj):
return obj.annotation.annotator
def get_queryset(self, request: HttpRequest) -> QuerySet[Any]:
return (
super()
.get_queryset(request)
.select_related("annotation__study", "annotation__annotator")
.select_related("question", "choice")
)


@admin.register(Annotation)
Expand Down
9 changes: 4 additions & 5 deletions isic/studies/templates/studies/partials/pagination.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{% load humanize %}
{% load spurl %}

<div class="pagination flex justify-end">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="{% spurl base=request.get_full_path set_query="page=1" %}">&laquo; first</a>
<a href="{% spurl base=request.get_full_path set_query="page={{ page_obj.previous_page_number }}" %}">previous</a>
<a href="{% querystring page=1 %}">&laquo; first</a>
<a href="{% querystring page=page_obj.previous_page_number %}">previous</a>
{% endif %}

<span class="current">
Page {{ page_obj.number|intcomma }} of {{ page_obj.paginator.num_pages|intcomma }}
</span>

{% if page_obj.has_next %}
<a href="{% spurl base=request.get_full_path set_query="page={{ page_obj.next_page_number }}" %}">next</a>
<a href="{% spurl base=request.get_full_path set_query="page={{ page_obj.paginator.num_pages }}" %}">last &raquo;</a>
<a href="{% querystring page=page_obj.next_page_number %}">next</a>
<a href="{% querystring page=page_obj.paginator.num_pages %}">last &raquo;</a>
{% endif %}
</span>
</div>
56 changes: 27 additions & 29 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,37 @@ asgiref==3.8.1
asttokens==2.4.1
bcrypt==4.2.0
billiard==4.2.0
boto3==1.34.148
botocore==1.34.148
boto3==1.35.7
botocore==1.35.7
Brotli==1.1.0
cachetools==5.4.0
cachetools==5.5.0
celery==5.4.0
certifi==2024.7.4
cffi==1.16.0
cffi==1.17.0
charset-normalizer==3.3.2
click==8.1.7
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
cryptography==43.0.0
deepdiff==7.0.1
deepdiff==8.0.0
dj-database-url==2.2.0
dj-email-url==1.0.6
Django==5.0.7
django-allauth==0.63.6
Django==5.1
django-allauth==64.1.0
django-auth-style==0.8.1
django-click==2.4.0
django-composed-configuration==0.25.0
django-configurations==2.5.1
django-cors-headers==4.4.0
django-extensions==3.2.3
django-filter==24.2
django-filter==24.3
django-girder-utils==0.13.1
django-json-widget==2.0.1
django-ninja==1.2.2
django-ninja==1.3.0
django-oauth-toolkit==1.7.1
django-object-actions==4.2.0
django-s3-file-field==1.0.1
django-spurl==0.6.8
django-storages==1.14.4
django-widget-tweaks==1.5.0
djangorestframework==3.15.2
Expand All @@ -48,35 +47,35 @@ drf-yasg==1.21.7
Events==0.5
executing==2.0.1
GDAL==3.10.0
google-analytics-data==0.18.9
google-api-core==2.19.1
google-auth==2.32.0
googleapis-common-protos==1.63.2
grpcio==1.65.1
grpcio-status==1.65.1
gunicorn==22.0.0
google-analytics-data==0.18.11
google-api-core==2.19.2
google-auth==2.34.0
googleapis-common-protos==1.65.0
grpcio==1.66.0
grpcio-status==1.66.0
gunicorn==23.0.0
hashids==1.3.1
httplib2==0.22.0
idna==3.7
idna==3.8
inflection==0.5.1
isic-metadata==2.1.0
jaro-winkler==2.0.3
jmespath==1.0.1
jwcrypto==1.5.6
kombu==5.3.7
kombu==5.4.0
markdown-it-py==3.0.0
mdurl==0.1.2
numpy==2.0.1
numpy==2.1.0
oauth2client==4.1.3
oauthlib==3.2.2
opensearch-py==2.6.0
ordered-set==4.1.0
opensearch-py==2.7.1
orderly-set==5.2.1
packaging==24.1
pandas==2.2.2
pillow==10.4.0
prompt_toolkit==3.0.47
proto-plus==1.24.0
protobuf==5.27.2
protobuf==5.27.4
psycopg==3.2.1
pure_eval==0.2.3
pyasn1==0.6.0
Expand All @@ -87,24 +86,23 @@ pydantic==2.8.2
pydantic_core==2.20.1
Pygments==2.18.0
pymongo==4.8.0
pyparsing==3.1.2
pyparsing==3.1.4
python-dateutil==2.9.0.post0
python-magic==0.4.27
pytz==2024.1
PyYAML==6.0.1
PyYAML==6.0.2
requests==2.32.3
rich==13.7.1
rich==13.8.0
rsa==4.9
s3transfer==0.10.2
sentry-sdk==2.11.0
sentry-sdk==2.13.0
six==1.16.0
sqlparse==0.5.1
tenacity==8.5.0
tenacity==9.0.0
typing_extensions==4.12.2
tzdata==2024.1
uritemplate==4.1.1
urllib3==2.2.2
URLObject==2.4.3
vine==5.1.0
wcwidth==0.2.13
whitenoise==6.7.0
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"bcrypt",
"celery>=5.4.0",
"deepdiff",
"django>5,<6",
"django>=5.1,<6",
"django-allauth>=0.56.0",
"django-click",
"django-configurations[database,email]",
Expand All @@ -57,7 +57,6 @@
# https://github.com/jazzband/django-oauth-toolkit/pull/1124
"django-oauth-toolkit<2.0.0",
"django-object-actions",
"django-spurl",
"django-storages>1.14.2",
"django-widget-tweaks",
"gdal",
Expand Down

0 comments on commit 2aad400

Please sign in to comment.