mpeltriaux
87b1da8fdd
* refactors konova/autocompletes.py by splitting into individual files and moving them to fitting apps * autocomplete files now live in APPNAME/autocomplete/...
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
Created on: 18.08.22
|
|
|
|
"""
|
|
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_REGISTRATION_OFFICE_ID
|
|
from codelist.autocomplete.base import KonovaCodeAutocomplete
|
|
|
|
|
|
class RegistrationOfficeCodeAutocomplete(KonovaCodeAutocomplete):
|
|
"""
|
|
Due to limitations of the django dal package, we need to subclass for each code list
|
|
"""
|
|
group_by_related = "parent"
|
|
related_field_name = "long_name"
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.c = CODELIST_REGISTRATION_OFFICE_ID
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def order_by(self, qs):
|
|
return qs.order_by(
|
|
"parent__long_name"
|
|
)
|
|
|
|
|
|
class ConservationOfficeCodeAutocomplete(KonovaCodeAutocomplete):
|
|
"""
|
|
Due to limitations of the django dal package, we need to subclass for each code list
|
|
"""
|
|
group_by_related = "parent"
|
|
related_field_name = "long_name"
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
self.c = CODELIST_CONSERVATION_OFFICE_ID
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def get_result_label(self, result):
|
|
return f"{result.long_name} ({result.short_name})"
|