Add operators and property owners functionality

- Implemented OperatorListView and OperatorDetailView for managing operators.
- Created corresponding templates for operator listing and detail views.
- Added PropertyOwnerListView and PropertyOwnerDetailView for managing property owners.
- Developed templates for property owner listing and detail views.
- Established relationships between parks and operators, and parks and property owners in the models.
- Created migrations to reflect the new relationships and fields in the database.
- Added admin interfaces for PropertyOwner management.
- Implemented tests for operators and property owners.
This commit is contained in:
pacnpal
2025-07-04 14:49:36 -04:00
parent 8360f3fd43
commit 751cd86a31
80 changed files with 2943 additions and 2358 deletions

View File

@@ -4,32 +4,32 @@ from django.core.exceptions import ValidationError
from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D
from .models import Location
from companies.models import Company
from operators.models import Operator
from parks.models import Park
class LocationModelTests(TestCase):
def setUp(self):
# Create test company
self.company = Company.objects.create(
name='Test Company',
self.operator = Operator.objects.create(
name='Test Operator',
website='http://example.com'
)
# Create test park
self.park = Park.objects.create(
name='Test Park',
owner=self.company,
owner=self.operator,
status='OPERATING'
)
# Create test location for company
self.company_location = Location.objects.create(
content_type=ContentType.objects.get_for_model(Company),
object_id=self.company.pk,
name='Test Company HQ',
self.operator_location = Location.objects.create(
content_type=ContentType.objects.get_for_model(Operator),
object_id=self.operator.pk,
name='Test Operator HQ',
location_type='business',
street_address='123 Company St',
city='Company City',
street_address='123 Operator St',
city='Operator City',
state='CS',
country='Test Country',
postal_code='12345',
@@ -53,14 +53,14 @@ class LocationModelTests(TestCase):
def test_location_creation(self):
"""Test location instance creation and field values"""
# Test company location
self.assertEqual(self.company_location.name, 'Test Company HQ')
self.assertEqual(self.company_location.location_type, 'business')
self.assertEqual(self.company_location.street_address, '123 Company St')
self.assertEqual(self.company_location.city, 'Company City')
self.assertEqual(self.company_location.state, 'CS')
self.assertEqual(self.company_location.country, 'Test Country')
self.assertEqual(self.company_location.postal_code, '12345')
self.assertIsNotNone(self.company_location.point)
self.assertEqual(self.operator_location.name, 'Test Operator HQ')
self.assertEqual(self.operator_location.location_type, 'business')
self.assertEqual(self.operator_location.street_address, '123 Operator St')
self.assertEqual(self.operator_location.city, 'Operator City')
self.assertEqual(self.operator_location.state, 'CS')
self.assertEqual(self.operator_location.country, 'Test Country')
self.assertEqual(self.operator_location.postal_code, '12345')
self.assertIsNotNone(self.operator_location.point)
# Test park location
self.assertEqual(self.park_location.name, 'Test Park Location')
@@ -74,23 +74,23 @@ class LocationModelTests(TestCase):
def test_location_str_representation(self):
"""Test string representation of location"""
expected_company_str = 'Test Company HQ (Company City, Test Country)'
self.assertEqual(str(self.company_location), expected_company_str)
expected_company_str = 'Test Operator HQ (Operator City, Test Country)'
self.assertEqual(str(self.operator_location), expected_company_str)
expected_park_str = 'Test Park Location (Park City, Test Country)'
self.assertEqual(str(self.park_location), expected_park_str)
def test_get_formatted_address(self):
"""Test get_formatted_address method"""
expected_address = '123 Company St, Company City, CS, 12345, Test Country'
self.assertEqual(self.company_location.get_formatted_address(), expected_address)
expected_address = '123 Operator St, Operator City, CS, 12345, Test Country'
self.assertEqual(self.operator_location.get_formatted_address(), expected_address)
def test_point_coordinates(self):
"""Test point coordinates"""
# Test company location point
self.assertIsNotNone(self.company_location.point)
self.assertAlmostEqual(self.company_location.point.y, 34.0522, places=4) # latitude
self.assertAlmostEqual(self.company_location.point.x, -118.2437, places=4) # longitude
self.assertIsNotNone(self.operator_location.point)
self.assertAlmostEqual(self.operator_location.point.y, 34.0522, places=4) # latitude
self.assertAlmostEqual(self.operator_location.point.x, -118.2437, places=4) # longitude
# Test park location point
self.assertIsNotNone(self.park_location.point)
@@ -99,7 +99,7 @@ class LocationModelTests(TestCase):
def test_coordinates_property(self):
"""Test coordinates property"""
company_coords = self.company_location.coordinates
company_coords = self.operator_location.coordinates
self.assertIsNotNone(company_coords)
self.assertAlmostEqual(company_coords[0], 34.0522, places=4) # latitude
self.assertAlmostEqual(company_coords[1], -118.2437, places=4) # longitude
@@ -111,7 +111,7 @@ class LocationModelTests(TestCase):
def test_distance_calculation(self):
"""Test distance_to method"""
distance = self.company_location.distance_to(self.park_location)
distance = self.operator_location.distance_to(self.park_location)
self.assertIsNotNone(distance)
self.assertGreater(distance, 0)
@@ -119,17 +119,17 @@ class LocationModelTests(TestCase):
"""Test nearby_locations method"""
# Create another location near the company location
nearby_location = Location.objects.create(
content_type=ContentType.objects.get_for_model(Company),
object_id=self.company.pk,
content_type=ContentType.objects.get_for_model(Operator),
object_id=self.operator.pk,
name='Nearby Location',
location_type='business',
street_address='789 Nearby St',
city='Company City',
city='Operator City',
country='Test Country',
point=Point(-118.2438, 34.0523) # Very close to company location
)
nearby = self.company_location.nearby_locations(distance_km=1)
nearby = self.operator_location.nearby_locations(distance_km=1)
self.assertEqual(nearby.count(), 1)
self.assertEqual(nearby.first(), nearby_location)
@@ -137,10 +137,10 @@ class LocationModelTests(TestCase):
"""Test generic relations work correctly"""
# Test company location relation
company_location = Location.objects.get(
content_type=ContentType.objects.get_for_model(Company),
object_id=self.company.pk
content_type=ContentType.objects.get_for_model(Operator),
object_id=self.operator.pk
)
self.assertEqual(company_location, self.company_location)
self.assertEqual(company_location, self.operator_location)
# Test park location relation
park_location = Location.objects.get(
@@ -152,19 +152,19 @@ class LocationModelTests(TestCase):
def test_location_updates(self):
"""Test location updates"""
# Update company location
self.company_location.street_address = 'Updated Address'
self.company_location.city = 'Updated City'
self.company_location.save()
self.operator_location.street_address = 'Updated Address'
self.operator_location.city = 'Updated City'
self.operator_location.save()
updated_location = Location.objects.get(pk=self.company_location.pk)
updated_location = Location.objects.get(pk=self.operator_location.pk)
self.assertEqual(updated_location.street_address, 'Updated Address')
self.assertEqual(updated_location.city, 'Updated City')
def test_point_sync_with_lat_lon(self):
"""Test point synchronization with latitude/longitude fields"""
location = Location.objects.create(
content_type=ContentType.objects.get_for_model(Company),
object_id=self.company.pk,
content_type=ContentType.objects.get_for_model(Operator),
object_id=self.operator.pk,
name='Test Sync Location',
location_type='business',
latitude=34.0522,