it_manager: сортировка локаций по коду и полный список в селекте.
Аптеки А1…А70/П… вместо сортировки по адресу; убрать лимит 50 в searchable-select. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -71,6 +71,37 @@ def pharmacy_search_text(pharmacy) -> str:
|
||||
return ' '.join(parts)
|
||||
|
||||
|
||||
# Порядок юрлиц в селектах IT: А…, П…, Т…, Г…, Л…, прочие
|
||||
_OBJECT_LETTER_ORDER = {'а': 0, 'п': 1, 'т': 2, 'г': 3, 'л': 4}
|
||||
_OBJECT_CODE_RE = re.compile(r'^([АAПPТTГGЛL])(\d+)$', re.I)
|
||||
|
||||
|
||||
def location_sort_key(location) -> tuple:
|
||||
"""Сортировка локаций: офис/склад, затем аптеки по коду А1…А70, П1…"""
|
||||
loc_type = getattr(location, 'location_type', '') or ''
|
||||
if loc_type == 'office':
|
||||
return (0, 0, 0, (getattr(location, 'address', None) or '').casefold())
|
||||
if loc_type == 'warehouse':
|
||||
return (0, 1, 0, (getattr(location, 'address', None) or '').casefold())
|
||||
|
||||
pharmacy = None
|
||||
try:
|
||||
pharmacy = location.pharmacy
|
||||
except Exception:
|
||||
pharmacy = None
|
||||
code = pharmacy_object_code(pharmacy) if pharmacy else ''
|
||||
m = _OBJECT_CODE_RE.match(code)
|
||||
if m:
|
||||
letter = m.group(1).upper().translate(_LAT_TO_CYR).lower()
|
||||
return (1, _OBJECT_LETTER_ORDER.get(letter, 9), int(m.group(2)), code)
|
||||
if code.startswith('№'):
|
||||
try:
|
||||
return (1, 8, int(code[1:]), code)
|
||||
except ValueError:
|
||||
pass
|
||||
return (1, 9, 0, (getattr(location, 'address', None) or code or '').casefold())
|
||||
|
||||
|
||||
class LocationManager(models.Manager):
|
||||
|
||||
def active(self):
|
||||
|
||||
Reference in New Issue
Block a user