mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 02:31:08 -05:00
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""Core forms and form components."""
|
|
|
|
from django.conf import settings
|
|
from django.core.exceptions import PermissionDenied
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from autocomplete import Autocomplete
|
|
|
|
|
|
class BaseAutocomplete(Autocomplete):
|
|
"""Base autocomplete class for consistent autocomplete behavior across the project.
|
|
|
|
This class extends django-htmx-autocomplete's base Autocomplete class to provide:
|
|
- Project-wide defaults for autocomplete behavior
|
|
- Translation strings
|
|
- Authentication enforcement
|
|
- Sensible search configuration
|
|
"""
|
|
|
|
# Search configuration
|
|
minimum_search_length = 2 # More responsive than default 3
|
|
max_results = 10 # Reasonable limit for performance
|
|
|
|
# UI text configuration using gettext for i18n
|
|
no_result_text = _("No matches found")
|
|
narrow_search_text = _(
|
|
"Showing %(page_size)s of %(total)s matches. Please refine your search."
|
|
)
|
|
type_at_least_n_characters = _("Type at least %(n)s characters...")
|
|
|
|
# Project-wide component settings
|
|
placeholder = _("Search...")
|
|
|
|
@staticmethod
|
|
def auth_check(request):
|
|
"""Enforce authentication by default.
|
|
|
|
This can be overridden in subclasses if public access is needed.
|
|
Configure AUTOCOMPLETE_BLOCK_UNAUTHENTICATED in settings to disable.
|
|
"""
|
|
block_unauth = getattr(settings, "AUTOCOMPLETE_BLOCK_UNAUTHENTICATED", True)
|
|
if block_unauth and not request.user.is_authenticated:
|
|
raise PermissionDenied(_("Authentication required"))
|