|
19 | 19 |
|
20 | 20 | from .admin_classes import RegionRestrictedAdmin |
21 | 21 | from api.models import Country |
| 22 | +from deployments.models import SectorTag |
22 | 23 | from .models import ( |
23 | 24 | FormData, |
24 | 25 | FormArea, |
25 | 26 | FormComponent, |
26 | 27 | FormQuestion, |
27 | 28 | FormAnswer, |
| 29 | + OrganizationTypes, |
28 | 30 | OpsLearning, |
29 | 31 | Overview, |
30 | 32 | NiceDocument, |
|
67 | 69 | PerPrioritizationFilter, |
68 | 70 | PerWorkPlanFilter, |
69 | 71 | ) |
| 72 | +from django_filters.widgets import CSVWidget |
70 | 73 | from .custom_renderers import NarrowCSVRenderer |
71 | 74 |
|
72 | 75 |
|
@@ -370,12 +373,64 @@ def get_queryset(self): |
370 | 373 | return self.get_filtered_queryset(self.request, queryset, dispatch=0) |
371 | 374 |
|
372 | 375 |
|
| 376 | +class OpsLearningFilter(filters.FilterSet): |
| 377 | + type_validated = filters.NumberFilter(field_name='type_validated', lookup_expr='exact') |
| 378 | + appeal_document_id = filters.NumberFilter(field_name='appeal_document_id', lookup_expr='exact') |
| 379 | + organization_validated__in = filters.ModelMultipleChoiceFilter( |
| 380 | + label='validated_organizations', |
| 381 | + field_name='organization_validated', |
| 382 | + help_text='Organization GO identifiers, comma separated', |
| 383 | + widget=CSVWidget, |
| 384 | + queryset=OrganizationTypes.objects.all(), |
| 385 | + ) |
| 386 | + sector_validated__in = filters.ModelMultipleChoiceFilter( |
| 387 | + label='validated_sectors', |
| 388 | + field_name='sector_validated', |
| 389 | + help_text='Sector identifiers, comma separated', |
| 390 | + widget=CSVWidget, |
| 391 | + queryset=SectorTag.objects.all(), |
| 392 | + ) |
| 393 | + per_component_validated__in = filters.ModelMultipleChoiceFilter( |
| 394 | + label='validated_per_components', |
| 395 | + field_name='per_component_validated', |
| 396 | + help_text='PER Component identifiers, comma separated', |
| 397 | + widget=CSVWidget, |
| 398 | + queryset=FormComponent.objects.all(), |
| 399 | + ) |
| 400 | + |
| 401 | + class Meta: |
| 402 | + model = OpsLearning |
| 403 | + fields = { |
| 404 | + 'id': ('exact', 'in'), |
| 405 | + 'created_at': ('exact', 'gt', 'gte', 'lt', 'lte'), |
| 406 | + 'modified_at': ('exact', 'gt', 'gte', 'lt', 'lte'), |
| 407 | + 'is_validated': ('exact',), |
| 408 | + 'learning': ('exact', 'icontains'), |
| 409 | + 'learning_validated': ('exact', 'icontains'), |
| 410 | + 'organization_validated': ('exact',), |
| 411 | + 'sector_validated': ('exact',), |
| 412 | + 'per_component_validated': ('exact',), |
| 413 | + 'appeal_code': ('exact', 'in'), |
| 414 | + 'appeal_code__code': ('exact', 'icontains', 'in'), |
| 415 | + 'appeal_code__num_beneficiaries': ('exact', 'gt', 'gte', 'lt', 'lte'), |
| 416 | + 'appeal_code__start_date': ('exact', 'gt', 'gte', 'lt', 'lte'), |
| 417 | + 'appeal_code__dtype': ('exact', 'in'), |
| 418 | + 'appeal_code__country': ('exact', 'in'), |
| 419 | + 'appeal_code__country__name': ('exact', 'in'), |
| 420 | + 'appeal_code__country__iso': ('exact', 'in'), |
| 421 | + 'appeal_code__country__iso3': ('exact', 'in'), |
| 422 | + 'appeal_code__region': ('exact', 'in'), |
| 423 | + } |
| 424 | + |
| 425 | + |
373 | 426 | class OpsLearningViewset(viewsets.ModelViewSet): |
374 | 427 | """ |
375 | 428 | A simple ViewSet for viewing and editing OpsLearning records. |
376 | 429 | """ |
377 | 430 | queryset = OpsLearning.objects.all() |
378 | 431 | permission_classes = [OpsLearningPermission] |
| 432 | + filterset_class = OpsLearningFilter |
| 433 | + search_fields = ('learning', 'learning_validated', 'appeal_code__code', 'appeal_code__name', 'appeal_code__name_en', 'appeal_code__name_es', 'appeal_code__name_fr', 'appeal_code__name_ar') |
379 | 434 |
|
380 | 435 | def get_renderers(self): |
381 | 436 | serializer = self.get_serializer() |
|
0 commit comments