filter fixes
This commit is contained in:
@@ -46,9 +46,14 @@ class ClustersFilter(django_filters.FilterSet):
|
||||
|
||||
|
||||
class ContentIdeasFilter(django_filters.FilterSet):
|
||||
"""Custom filter for ContentIdeas with date range support"""
|
||||
"""Custom filter for ContentIdeas with date range support.
|
||||
Uses CharFilter for content_type and content_structure to accept any value
|
||||
(database may have legacy values not in current model choices).
|
||||
"""
|
||||
created_at__gte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='gte')
|
||||
created_at__lte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='lte')
|
||||
content_type = django_filters.CharFilter(field_name='content_type')
|
||||
content_structure = django_filters.CharFilter(field_name='content_structure')
|
||||
|
||||
class Meta:
|
||||
model = ContentIdeas
|
||||
@@ -1378,6 +1383,8 @@ class ClusterViewSet(SiteSectorModelViewSet):
|
||||
'mapped': 'Mapped',
|
||||
}
|
||||
status_options = [
|
||||
{'value': '', 'label': 'All Status'},
|
||||
] + [
|
||||
{'value': s, 'label': status_labels.get(s, s.title())}
|
||||
for s in statuses
|
||||
]
|
||||
@@ -1428,6 +1435,8 @@ class ClusterViewSet(SiteSectorModelViewSet):
|
||||
5: '5 - Very Hard',
|
||||
}
|
||||
difficulty_options = [
|
||||
{'value': '', 'label': 'All Difficulty'},
|
||||
] + [
|
||||
{'value': str(d), 'label': difficulty_labels[d]}
|
||||
for d in sorted(difficulty_levels)
|
||||
]
|
||||
@@ -1669,6 +1678,8 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
'completed': 'Completed',
|
||||
}
|
||||
status_options = [
|
||||
{'value': '', 'label': 'All Status'},
|
||||
] + [
|
||||
{'value': s, 'label': status_labels.get(s, s.title())}
|
||||
for s in statuses
|
||||
]
|
||||
@@ -1690,6 +1701,8 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
'taxonomy': 'Taxonomy',
|
||||
}
|
||||
content_type_options = [
|
||||
{'value': '', 'label': 'All Types'},
|
||||
] + [
|
||||
{'value': t, 'label': type_labels.get(t, t.title())}
|
||||
for t in content_types
|
||||
]
|
||||
@@ -1713,6 +1726,8 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
'tag_archive': 'Tag Archive', 'attribute_archive': 'Attribute Archive',
|
||||
}
|
||||
content_structure_options = [
|
||||
{'value': '', 'label': 'All Structures'},
|
||||
] + [
|
||||
{'value': s, 'label': structure_labels.get(s, s.replace('_', ' ').title())}
|
||||
for s in structures
|
||||
]
|
||||
@@ -1731,6 +1746,8 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
))
|
||||
clusters = Clusters.objects.filter(id__in=cluster_ids).values('id', 'name').order_by('name')
|
||||
cluster_options = [
|
||||
{'value': '', 'label': 'All Clusters'},
|
||||
] + [
|
||||
{'value': str(c['id']), 'label': c['name']}
|
||||
for c in clusters
|
||||
]
|
||||
|
||||
@@ -27,9 +27,14 @@ from igny8_core.business.billing.exceptions import InsufficientCreditsError
|
||||
|
||||
# Custom FilterSets with date range filtering support
|
||||
class TasksFilter(django_filters.FilterSet):
|
||||
"""Custom filter for Tasks with date range support"""
|
||||
"""Custom filter for Tasks with date range support.
|
||||
Uses CharFilter for content_type and content_structure to accept any value
|
||||
(database may have legacy values not in current model choices).
|
||||
"""
|
||||
created_at__gte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='gte')
|
||||
created_at__lte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='lte')
|
||||
content_type = django_filters.CharFilter(field_name='content_type')
|
||||
content_structure = django_filters.CharFilter(field_name='content_structure')
|
||||
|
||||
class Meta:
|
||||
model = Tasks
|
||||
@@ -47,9 +52,14 @@ class ImagesFilter(django_filters.FilterSet):
|
||||
|
||||
|
||||
class ContentFilter(django_filters.FilterSet):
|
||||
"""Custom filter for Content with date range support"""
|
||||
"""Custom filter for Content with date range support.
|
||||
Uses CharFilter for content_type and content_structure to accept any value
|
||||
(database may have legacy values not in current model choices).
|
||||
"""
|
||||
created_at__gte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='gte')
|
||||
created_at__lte = django_filters.IsoDateTimeFilter(field_name='created_at', lookup_expr='lte')
|
||||
content_type = django_filters.CharFilter(field_name='content_type')
|
||||
content_structure = django_filters.CharFilter(field_name='content_structure')
|
||||
|
||||
class Meta:
|
||||
model = Content
|
||||
@@ -318,6 +328,8 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
'failed': 'Failed',
|
||||
}
|
||||
status_options = [
|
||||
{'value': '', 'label': 'All Status'},
|
||||
] + [
|
||||
{'value': s, 'label': status_labels.get(s, s.title())}
|
||||
for s in statuses
|
||||
]
|
||||
@@ -339,6 +351,8 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
'taxonomy': 'Taxonomy',
|
||||
}
|
||||
content_type_options = [
|
||||
{'value': '', 'label': 'All Types'},
|
||||
] + [
|
||||
{'value': t, 'label': type_labels.get(t, t.title())}
|
||||
for t in content_types
|
||||
]
|
||||
@@ -362,6 +376,8 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
'tag_archive': 'Tag Archive', 'attribute_archive': 'Attribute Archive',
|
||||
}
|
||||
content_structure_options = [
|
||||
{'value': '', 'label': 'All Structures'},
|
||||
] + [
|
||||
{'value': s, 'label': structure_labels.get(s, s.replace('_', ' ').title())}
|
||||
for s in structures
|
||||
]
|
||||
@@ -381,6 +397,8 @@ class TasksViewSet(SiteSectorModelViewSet):
|
||||
))
|
||||
clusters = Clusters.objects.filter(id__in=cluster_ids).values('id', 'name').order_by('name')
|
||||
cluster_options = [
|
||||
{'value': '', 'label': 'All Clusters'},
|
||||
] + [
|
||||
{'value': str(c['id']), 'label': c['name']}
|
||||
for c in clusters
|
||||
]
|
||||
@@ -959,14 +977,21 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
|
||||
# Get filter parameters for cascading
|
||||
status_filter = request.query_params.get('status', '')
|
||||
status_in_filter = request.query_params.get('status__in', '') # Comma-separated list of statuses
|
||||
site_status_filter = request.query_params.get('site_status', '')
|
||||
content_type_filter = request.query_params.get('content_type', '')
|
||||
content_structure_filter = request.query_params.get('content_structure', '')
|
||||
source_filter = request.query_params.get('source', '')
|
||||
search = request.query_params.get('search', '')
|
||||
|
||||
# Apply search to base queryset
|
||||
# Apply base status__in filter to restrict entire result set (e.g., for Approved page)
|
||||
base_qs = queryset
|
||||
if status_in_filter:
|
||||
status_list = [s.strip() for s in status_in_filter.split(',') if s.strip()]
|
||||
if status_list:
|
||||
base_qs = base_qs.filter(status__in=status_list)
|
||||
|
||||
# Apply search to base queryset
|
||||
if search:
|
||||
base_qs = base_qs.filter(
|
||||
Q(title__icontains=search) | Q(summary__icontains=search)
|
||||
@@ -991,6 +1016,8 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
'published': 'Published',
|
||||
}
|
||||
status_options = [
|
||||
{'value': '', 'label': 'All Content Status'},
|
||||
] + [
|
||||
{'value': s, 'label': status_labels.get(s, s.title())}
|
||||
for s in statuses
|
||||
]
|
||||
@@ -1015,6 +1042,8 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
'failed': 'Failed',
|
||||
}
|
||||
site_status_options = [
|
||||
{'value': '', 'label': 'All Site Status'},
|
||||
] + [
|
||||
{'value': s, 'label': site_status_labels.get(s, s.replace('_', ' ').title())}
|
||||
for s in site_statuses
|
||||
]
|
||||
@@ -1038,6 +1067,8 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
'taxonomy': 'Taxonomy',
|
||||
}
|
||||
content_type_options = [
|
||||
{'value': '', 'label': 'All Types'},
|
||||
] + [
|
||||
{'value': t, 'label': type_labels.get(t, t.title())}
|
||||
for t in content_types
|
||||
]
|
||||
@@ -1063,6 +1094,8 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
'tag_archive': 'Tag Archive', 'attribute_archive': 'Attribute Archive',
|
||||
}
|
||||
content_structure_options = [
|
||||
{'value': '', 'label': 'All Structures'},
|
||||
] + [
|
||||
{'value': s, 'label': structure_labels.get(s, s.replace('_', ' ').title())}
|
||||
for s in structures
|
||||
]
|
||||
@@ -1084,6 +1117,8 @@ class ContentViewSet(SiteSectorModelViewSet):
|
||||
'wordpress': 'WordPress',
|
||||
}
|
||||
source_options = [
|
||||
{'value': '', 'label': 'All Sources'},
|
||||
] + [
|
||||
{'value': s, 'label': source_labels.get(s, s.title())}
|
||||
for s in sources
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user