Skip to content

Commit

Permalink
fixes collation
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 22, 2024
1 parent d6468a9 commit 5a908ea
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/aurora/api/serializers/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
class RecordSerializer(serializers.ModelSerializer):
registration_url = serializers.SerializerMethodField()
registrar = serializers.CharField()
project = serializers.ReadOnlyField(source='registration.project.pk')
organization = serializers.ReadOnlyField(source='registration.project.organization.pk')
project_slug = serializers.ReadOnlyField(source='registration.project.slug')
organization_slug = serializers.ReadOnlyField(source='registration.project.organization.slug')
project = serializers.ReadOnlyField(source="registration.project.pk")
organization = serializers.ReadOnlyField(source="registration.project.organization.pk")
project_slug = serializers.ReadOnlyField(source="registration.project.slug")
organization_slug = serializers.ReadOnlyField(source="registration.project.organization.slug")

class Meta:
model = Record
Expand Down
2 changes: 1 addition & 1 deletion src/aurora/api/viewsets/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RecordFilter(filters.FilterSet):

class Meta:
model = Record
fields = ["registration", "after", "id", "registration__project", "registration__project__organization"]
fields = ["registration", "after", "id", "registration__project", "registration__project__organization"]


class RecordPaginator(CursorPagination):
Expand Down
1 change: 0 additions & 1 deletion src/aurora/config/fragments/smart_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .. import env

SMART_ADMIN_SECTIONS = {
"Registration": ["registration", "dbtemplates", "flatpages"],
Expand Down
11 changes: 10 additions & 1 deletion src/aurora/core/admin/custom_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.admin import register
from django.core.cache import caches
from django.db.models import JSONField
from django.db.models.functions import Collate

from admin_extra_buttons.decorators import button
from jsoneditor.forms import JSONEditor
Expand All @@ -24,11 +25,19 @@ class CustomFieldTypeAdmin(SmartModelAdmin):
"base_type",
"attrs",
)
search_fields = ("name",)
search_fields = ("name_deterministic",)
formfield_overrides = {
JSONField: {"widget": JSONEditor},
}

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.annotate(name_deterministic=Collate("name", "und-x-icu"))
.select_related("flex_form")
)

@button()
def test(self, request, pk):
ctx = self.get_common_context(request, pk)
Expand Down
10 changes: 8 additions & 2 deletions src/aurora/core/admin/flex_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.admin import register
from django.core.cache import caches
from django.db.models import JSONField
from django.db.models.functions import Collate

from admin_extra_buttons.decorators import button, view
from admin_ordering.admin import OrderableAdmin
Expand Down Expand Up @@ -42,7 +43,7 @@ def clean(self):

@register(FlexFormField)
class FlexFormFieldAdmin(LoadDumpMixin, SyncMixin, ConcurrencyVersionAdmin, OrderableAdmin, SmartModelAdmin):
search_fields = ("name", "label")
search_fields = ("name_deterministic", "label")
list_display = ("label", "name", "flex_form", "field_type", "required", "enabled")
list_editable = ["required", "enabled"]
list_filter = (
Expand All @@ -61,7 +62,12 @@ class FlexFormFieldAdmin(LoadDumpMixin, SyncMixin, ConcurrencyVersionAdmin, Orde
readonly_fields = ("version", "last_update_date")

def get_queryset(self, request):
return super().get_queryset(request).select_related("flex_form")
return (
super()
.get_queryset(request)
.annotate(name_deterministic=Collate("name", "und-x-icu"))
.select_related("flex_form")
)

# change_list_template = "reversion/change_list.html"
def get_readonly_fields(self, request, obj=None):
Expand Down
4 changes: 3 additions & 1 deletion src/aurora/core/admin/flex_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib import messages
from django.contrib.admin import register, TabularInline
from django.core.cache import caches
from django.db.models.functions import Collate

from admin_extra_buttons.decorators import button, view
from admin_ordering.admin import OrderableAdmin
Expand Down Expand Up @@ -85,7 +86,7 @@ class FlexFormAdmin(SyncMixin, ConcurrencyVersionAdmin, SmartModelAdmin):
("formset", UsedInRFormset),
("formset__parent", UsedInRFormset),
)
search_fields = ("name",)
search_fields = ("name_deterministic",)
readonly_fields = ("version", "last_update_date")
autocomplete_fields = ("validator", "project")
ordering = ("name",)
Expand All @@ -95,6 +96,7 @@ def get_queryset(self, request):
return (
super()
.get_queryset(request)
.annotate(name_deterministic=Collate("name", "und-x-icu"))
.prefetch_related("registration_set")
.select_related(
"project",
Expand Down
6 changes: 5 additions & 1 deletion src/aurora/core/admin/optionset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib.admin import register
from django.core.cache import caches
from django.db.models.functions import Collate
from django.urls import NoReverseMatch

from admin_extra_buttons.decorators import button, link
Expand All @@ -28,13 +29,16 @@ class OptionSetAdmin(LoadDumpMixin, SyncMixin, ConcurrencyVersionAdmin, SmartMod
"comment",
"pk_col",
)
search_fields = ("name",)
search_fields = ("name_deterministic",)
list_filter = (("data", ValueFilter.factory(lookup_name="icontains")),)
save_as = True
readonly_fields = ("version", "last_update_date")
object_history_template = "reversion-compare/object_history.html"
exclude = ("columns",)

def get_queryset(self, request):
return super().get_queryset(request).annotate(name_deterministic=Collate("name", "und-x-icu"))

@button()
def display_data(self, request, pk):
ctx = self.get_common_context(request, pk, title="Data")
Expand Down
12 changes: 11 additions & 1 deletion src/aurora/core/admin/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib.admin import register
from django.core.cache import caches
from django.db.models.functions import Collate

from adminfilters.mixin import AdminAutoCompleteSearchMixin
from mptt.admin import MPTTModelAdmin
Expand All @@ -21,10 +22,19 @@ class OrganizationAdmin(SyncMixin, AdminAutoCompleteSearchMixin, LinkedObjectsMi
list_display = ("name",)
mptt_level_indent = 20
mptt_indent_field = "name"
search_fields = ("name",)
search_fields = ("name_deterministic",)
protocol_class = AuroraSyncOrganizationProtocol
change_list_template = "admin/core/organization/change_list.html"

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.annotate(
name_deterministic=Collate("name", "und-x-icu"),
)
)

def admin_sync_show_inspect(self):
return True

Expand Down
15 changes: 10 additions & 5 deletions src/aurora/core/admin/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from django.contrib.admin import register
from django.core.cache import caches
from django.db.models.functions import Collate

from adminfilters.mixin import AdminAutoCompleteSearchMixin
from django.db.models.functions import Collate
from mptt.admin import MPTTModelAdmin
from smart_admin.mixins import LinkedObjectsMixin

Expand All @@ -23,14 +23,19 @@ class ProjectAdmin(SyncMixin, AdminAutoCompleteSearchMixin, LinkedObjectsMixin,
list_filter = ("organization",)
mptt_level_indent = 20
mptt_indent_field = "name"
search_fields = ("name",)
search_fields = ("name_deterministic",)
protocol_class = AuroraSyncProjectProtocol
autocomplete_fields = "parent, "

def get_queryset(self, request):
return super().get_queryset(request).annotate(
name_deterministic=Collate("name", "und-x-icu"),
).select_related("organization")
return (
super()
.get_queryset(request)
.annotate(
name_deterministic=Collate("name", "und-x-icu"),
)
.select_related("organization")
)

#
# def get_search_results(self, request, queryset, search_term):
Expand Down
1 change: 0 additions & 1 deletion src/aurora/core/fields/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .datetime import SmartDateWidget
from .editor import JavascriptEditor
from .image import ImageWidget

# from .multi_checkbox import MultiCheckboxWidget
from .number import NumberWidget
from .radio import RadioWidget, YesNoRadioWidget
Expand Down
2 changes: 1 addition & 1 deletion src/aurora/core/templatetags/matomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def matomo_site():

@register.simple_tag()
def matomo_id():
return getattr(settings, 'MATOMO_ID', '')
return getattr(settings, "MATOMO_ID", "")
29 changes: 17 additions & 12 deletions src/aurora/registration/admin/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ class RegistrationAdmin(ConcurrencyVersionAdmin, AdminAutoCompleteSearchMixin, S
protocol_class = AuroraSyncRegistrationProtocol

def get_queryset(self, request):
return super().get_queryset(request).annotate(
name_deterministic=Collate("name", "und-x-icu"),
).select_related("project", "project__organization")
return (
super()
.get_queryset(request)
.annotate(
name_deterministic=Collate("name", "und-x-icu"),
)
.select_related("project", "project__organization")
)

# def get_search_results(self, request, queryset, search_term):
# queryset, may_have_duplicates = super().get_search_results(request, queryset, search_term)
Expand Down Expand Up @@ -146,15 +151,15 @@ def media(self):
extra = "" if settings.DEBUG else ".min"
base = super().media
return (
VersionMedia(
js=[
"admin/js/vendor/jquery/jquery%s.js" % extra,
"admin/js/jquery.init.js",
"jquery.compat%s.js" % extra,
"clipboard%s.js" % extra,
]
)
+ base
VersionMedia(
js=[
"admin/js/vendor/jquery/jquery%s.js" % extra,
"admin/js/jquery.init.js",
"jquery.compat%s.js" % extra,
"clipboard%s.js" % extra,
]
)
+ base
)

@view(permission=can_export_data)
Expand Down
2 changes: 0 additions & 2 deletions src/aurora/web/middlewares/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from constance import config

from aurora.core.utils import is_root

logger = logging.getLogger(__name__)


Expand Down

0 comments on commit 5a908ea

Please sign in to comment.