Refactor test utilities and enhance ASGI settings

- 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.
This commit is contained in:
pacnpal
2025-08-20 19:51:59 -04:00
parent 69c07d1381
commit 66ed4347a9
230 changed files with 15094 additions and 11578 deletions

View File

@@ -1,137 +1,218 @@
from django.contrib import admin
from django.contrib.gis.admin import GISModelAdmin
from django.utils.html import format_html
from .models import Park, ParkArea, ParkLocation, Company, CompanyHeadquarters
class ParkLocationInline(admin.StackedInline):
"""Inline admin for ParkLocation"""
model = ParkLocation
extra = 0
fields = (
('city', 'state', 'country'),
'street_address',
'postal_code',
'point',
('highway_exit', 'best_arrival_time'),
'parking_notes',
'seasonal_notes',
('osm_id', 'osm_type'),
("city", "state", "country"),
"street_address",
"postal_code",
"point",
("highway_exit", "best_arrival_time"),
"parking_notes",
"seasonal_notes",
("osm_id", "osm_type"),
)
class ParkLocationAdmin(GISModelAdmin):
"""Admin for standalone ParkLocation management"""
list_display = ('park', 'city', 'state', 'country', 'latitude', 'longitude')
list_filter = ('country', 'state')
search_fields = ('park__name', 'city', 'state', 'country', 'street_address')
readonly_fields = ('latitude', 'longitude', 'coordinates')
list_display = (
"park",
"city",
"state",
"country",
"latitude",
"longitude",
)
list_filter = ("country", "state")
search_fields = (
"park__name",
"city",
"state",
"country",
"street_address",
)
readonly_fields = ("latitude", "longitude", "coordinates")
fieldsets = (
('Park', {
'fields': ('park',)
}),
('Address', {
'fields': ('street_address', 'city', 'state', 'country', 'postal_code')
}),
('Geographic Coordinates', {
'fields': ('point', 'latitude', 'longitude', 'coordinates'),
'description': 'Set coordinates by clicking on the map or entering latitude/longitude'
}),
('Travel Information', {
'fields': ('highway_exit', 'best_arrival_time', 'parking_notes', 'seasonal_notes'),
'classes': ('collapse',)
}),
('OpenStreetMap Integration', {
'fields': ('osm_id', 'osm_type'),
'classes': ('collapse',)
}),
("Park", {"fields": ("park",)}),
(
"Address",
{
"fields": (
"street_address",
"city",
"state",
"country",
"postal_code",
)
},
),
(
"Geographic Coordinates",
{
"fields": ("point", "latitude", "longitude", "coordinates"),
"description": "Set coordinates by clicking on the map or entering latitude/longitude",
},
),
(
"Travel Information",
{
"fields": (
"highway_exit",
"best_arrival_time",
"parking_notes",
"seasonal_notes",
),
"classes": ("collapse",),
},
),
(
"OpenStreetMap Integration",
{"fields": ("osm_id", "osm_type"), "classes": ("collapse",)},
),
)
def latitude(self, obj):
return obj.latitude
latitude.short_description = 'Latitude'
latitude.short_description = "Latitude"
def longitude(self, obj):
return obj.longitude
longitude.short_description = 'Longitude'
longitude.short_description = "Longitude"
class ParkAdmin(admin.ModelAdmin):
list_display = ('name', 'formatted_location', 'status', 'operator', 'property_owner', 'created_at', 'updated_at')
list_filter = ('status', 'location__country', 'location__state')
search_fields = ('name', 'description', 'location__city', 'location__state', 'location__country')
readonly_fields = ('created_at', 'updated_at')
prepopulated_fields = {'slug': ('name',)}
list_display = (
"name",
"formatted_location",
"status",
"operator",
"property_owner",
"created_at",
"updated_at",
)
list_filter = ("status", "location__country", "location__state")
search_fields = (
"name",
"description",
"location__city",
"location__state",
"location__country",
)
readonly_fields = ("created_at", "updated_at")
prepopulated_fields = {"slug": ("name",)}
inlines = [ParkLocationInline]
def formatted_location(self, obj):
"""Display formatted location string"""
return obj.formatted_location
formatted_location.short_description = 'Location'
formatted_location.short_description = "Location"
class ParkAreaAdmin(admin.ModelAdmin):
list_display = ('name', 'park', 'created_at', 'updated_at')
list_filter = ('park',)
search_fields = ('name', 'description', 'park__name')
readonly_fields = ('created_at', 'updated_at')
prepopulated_fields = {'slug': ('name',)}
list_display = ("name", "park", "created_at", "updated_at")
list_filter = ("park",)
search_fields = ("name", "description", "park__name")
readonly_fields = ("created_at", "updated_at")
prepopulated_fields = {"slug": ("name",)}
class CompanyHeadquartersInline(admin.StackedInline):
"""Inline admin for CompanyHeadquarters"""
model = CompanyHeadquarters
extra = 0
fields = (
('city', 'state_province', 'country'),
'street_address',
'postal_code',
'mailing_address',
("city", "state_province", "country"),
"street_address",
"postal_code",
"mailing_address",
)
class CompanyHeadquartersAdmin(admin.ModelAdmin):
"""Admin for standalone CompanyHeadquarters management"""
list_display = ('company', 'location_display', 'city', 'country', 'created_at')
list_filter = ('country', 'state_province')
search_fields = ('company__name', 'city', 'state_province', 'country', 'street_address')
readonly_fields = ('created_at', 'updated_at')
list_display = (
"company",
"location_display",
"city",
"country",
"created_at",
)
list_filter = ("country", "state_province")
search_fields = (
"company__name",
"city",
"state_province",
"country",
"street_address",
)
readonly_fields = ("created_at", "updated_at")
fieldsets = (
('Company', {
'fields': ('company',)
}),
('Address', {
'fields': ('street_address', 'city', 'state_province', 'country', 'postal_code')
}),
('Additional Information', {
'fields': ('mailing_address',),
'classes': ('collapse',)
}),
('Metadata', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
}),
("Company", {"fields": ("company",)}),
(
"Address",
{
"fields": (
"street_address",
"city",
"state_province",
"country",
"postal_code",
)
},
),
(
"Additional Information",
{"fields": ("mailing_address",), "classes": ("collapse",)},
),
(
"Metadata",
{"fields": ("created_at", "updated_at"), "classes": ("collapse",)},
),
)
class CompanyAdmin(admin.ModelAdmin):
"""Enhanced Company admin with headquarters inline"""
list_display = ('name', 'roles_display', 'headquarters_location', 'website', 'founded_year')
list_filter = ('roles',)
search_fields = ('name', 'description')
readonly_fields = ('created_at', 'updated_at')
prepopulated_fields = {'slug': ('name',)}
list_display = (
"name",
"roles_display",
"headquarters_location",
"website",
"founded_year",
)
list_filter = ("roles",)
search_fields = ("name", "description")
readonly_fields = ("created_at", "updated_at")
prepopulated_fields = {"slug": ("name",)}
inlines = [CompanyHeadquartersInline]
def roles_display(self, obj):
"""Display roles as a formatted string"""
return ', '.join(obj.roles) if obj.roles else 'No roles'
roles_display.short_description = 'Roles'
return ", ".join(obj.roles) if obj.roles else "No roles"
roles_display.short_description = "Roles"
def headquarters_location(self, obj):
"""Display headquarters location if available"""
if hasattr(obj, 'headquarters'):
if hasattr(obj, "headquarters"):
return obj.headquarters.location_display
return 'No headquarters'
headquarters_location.short_description = 'Headquarters'
return "No headquarters"
headquarters_location.short_description = "Headquarters"
# Register the models with their admin classes