Добавил информацию о типе объекта. Просто фиксы
This commit is contained in:
@@ -1205,3 +1205,106 @@ def get_first_param_subquery(field_name: str):
|
||||
... print(obj.first_freq)
|
||||
"""
|
||||
return F(f"parameter_obj__{field_name}")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Number Formatting Functions
|
||||
# ============================================================================
|
||||
|
||||
def format_coordinate(value):
|
||||
"""
|
||||
Format coordinate value to 4 decimal places.
|
||||
|
||||
Args:
|
||||
value: Numeric coordinate value
|
||||
|
||||
Returns:
|
||||
str: Formatted coordinate or '-' if None
|
||||
"""
|
||||
if value is None:
|
||||
return '-'
|
||||
try:
|
||||
return f"{float(value):.4f}"
|
||||
except (ValueError, TypeError):
|
||||
return '-'
|
||||
|
||||
|
||||
def format_frequency(value):
|
||||
"""
|
||||
Format frequency value to 3 decimal places.
|
||||
|
||||
Args:
|
||||
value: Numeric frequency value in MHz
|
||||
|
||||
Returns:
|
||||
str: Formatted frequency or '-' if None
|
||||
"""
|
||||
if value is None:
|
||||
return '-'
|
||||
try:
|
||||
return f"{float(value):.3f}"
|
||||
except (ValueError, TypeError):
|
||||
return '-'
|
||||
|
||||
|
||||
def format_symbol_rate(value):
|
||||
"""
|
||||
Format symbol rate (bod_velocity) to integer.
|
||||
|
||||
Args:
|
||||
value: Numeric symbol rate value
|
||||
|
||||
Returns:
|
||||
str: Formatted symbol rate or '-' if None
|
||||
"""
|
||||
if value is None:
|
||||
return '-'
|
||||
try:
|
||||
return f"{float(value):.0f}"
|
||||
except (ValueError, TypeError):
|
||||
return '-'
|
||||
|
||||
|
||||
def format_coords_display(point):
|
||||
"""
|
||||
Format geographic point coordinates for display.
|
||||
|
||||
Args:
|
||||
point: GeoDjango Point object
|
||||
|
||||
Returns:
|
||||
str: Formatted coordinates as "LAT LON" or '-' if None
|
||||
"""
|
||||
if not point:
|
||||
return '-'
|
||||
try:
|
||||
longitude = point.coords[0]
|
||||
latitude = point.coords[1]
|
||||
lon = f"{abs(longitude):.4f}E" if longitude > 0 else f"{abs(longitude):.4f}W"
|
||||
lat = f"{abs(latitude):.4f}N" if latitude > 0 else f"{abs(latitude):.4f}S"
|
||||
return f"{lat} {lon}"
|
||||
except (AttributeError, IndexError, TypeError):
|
||||
return '-'
|
||||
|
||||
|
||||
def parse_pagination_params(request):
|
||||
"""
|
||||
Parse pagination parameters from request.
|
||||
|
||||
Args:
|
||||
request: Django request object
|
||||
|
||||
Returns:
|
||||
tuple: (page_number, items_per_page)
|
||||
"""
|
||||
page_number = request.GET.get("page", 1)
|
||||
items_per_page = request.GET.get("items_per_page", 50)
|
||||
|
||||
try:
|
||||
items_per_page = int(items_per_page)
|
||||
if items_per_page not in [50, 100, 500, 1000]:
|
||||
items_per_page = 50
|
||||
except (ValueError, TypeError):
|
||||
items_per_page = 50
|
||||
|
||||
return page_number, items_per_page
|
||||
|
||||
Reference in New Issue
Block a user