예제 #1
0
class CountryFilter(django_filters.FilterSet):
    """
    Filter countries list
    """
    region_code = django_filters.NumberFilter(field_name='region__code')
    name = CommaSeparatedCharFilter(field_name='name', lookup_expr='in')
    code = CommaSeparatedCharFilter(field_name='code', lookup_expr='in')

    class Meta:
        model = Country
        fields = ['code', 'name', 'region_code']
예제 #2
0
class LocationFilter(TogetherFilterSet):

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__activity_status',
    )

    organisation_iati_identifier = CommaSeparatedCharFilter(
        lookup_expr='in', field_name='activity__reporting_organisations__ref')

    class Meta:
        model = Location
        fields = ['activity_status']
예제 #3
0
class RelatedActivityFilter(FilterSet):

    related_activity_type = CommaSeparatedCharFilter(lookup_type='in',
                                                     name='type__code')

    class Meta:
        model = RelatedActivity
예제 #4
0
class OrganisationFilter(TogetherFilterSet):
    # naming is according to IATI standard.
    organisation_identifier = CommaSeparatedCharFilter(
        field_name='organisation_identifier',
        lookup_expr='in'
    )
    name = CommaSeparatedCharFilter(
        field_name='primary_name',
        lookup_expr='exact'
    )
    is_reporting_organisation = BooleanFilter(
        field_name='activityreportingorganisation',
        lookup_expr='isnull',
        exclude=True)

    class Meta:
        model = Organisation
        fields = []
예제 #5
0
class LocationFilter(TogetherFilterSet):

    activity_status = CommaSeparatedCharFilter(
        lookup_type='in',
        name='activity__activity_status',)

    class Meta:
        model = Location
        fields = ['activity_status']
예제 #6
0
class PublisherFilter(FilterSet):
    """
    Filter publisher list
    """

    q = SearchQueryFilter()
    no_datasets = BooleanFilter(lookup_expr='isnull',
                                field_name='dataset',
                                distinct=True)
    is_active = BooleanFilter(lookup_expr='isnull',
                              exclude=True,
                              field_name='package_count')
    reporting_organisation_identifier = CommaSeparatedCharFilter(
        field_name='publisher_iati_id', lookup_expr='in')
    display_name = CommaSeparatedCharFilter(field_name='display_name',
                                            lookup_expr='in')
    name = CommaSeparatedCharFilter(field_name='name', lookup_expr='in')

    class Meta:
        model = Publisher
        fields = [
            'id', 'iati_id', 'publisher_iati_id', 'display_name', 'name', 'q',
            'no_datasets'
        ]
예제 #7
0
class ChainNodeFilter(FilterSet):
    chain_includes_activity = CharFilter(
        field_name='chain__chainnode__activity__iati_identifier',
        lookup_expr='exact')
    chain_includes_activity_of_reporting_organisation_identifier = CommaSeparatedCharFilter(  # NOQA: E501
        field_name='chain__chainnode__activity__reporting_organisations__organisation\
              __organisation_identifier',
        lookup_expr='in')
    reporting_organisation_identifier = CharFilter(
        field_name='activity__reporting_organisations__organisation__\
              organisation_identifier',
        lookup_expr='exact')
    reporting_organisation_identifier_not = CharFilter(
        field_name='activity__reporting_organisations__organisation__\
              organisation_identifier',
        lookup_expr='exact',
        exclude=True)
    is_start_node = BooleanFilter(
        field_name='start_link', lookup_expr='isnull', distinct=True)
    tier = NumberFilter(field_name='tier')
    link_end_node_hierarchy = NumberFilter(
        field_name='start_link__end_node__activity__hierarchy',
        lookup_expr='exact')
    hierarchy = CharFilter(
        field_name='activity__hierarchy',
        lookup_expr='exact'
    )
    bol = BooleanFilter(field_name='bol', lookup_expr='exact')
    eol = BooleanFilter(field_name='eol', lookup_expr='exact')
    treated_as_end_node = BooleanFilter(
        field_name='treated_as_end_node', lookup_expr='exact')

    class Meta:
        model = ChainNode
        fields = [
            'chain_includes_activity',
            'chain_includes_activity_of_reporting_organisation_identifier',
            'reporting_organisation_identifier',
            'reporting_organisation_identifier_not',
            'is_start_node',
            'tier',
            'link_end_node_hierarchy',
            'hierarchy',
            'bol',
            'eol',
            'treated_as_end_node',
        ]
예제 #8
0
파일: filters.py 프로젝트: trevorrea/OIPA
class BudgetFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(name='activity__iati_identifier',
                                           lookup_expr='in')

    activity_scope = CommaSeparatedCharFilter(
        name='activity__scope__code',
        lookup_expr='in',
    )

    document_link_category = CommaSeparatedCharFilter(
        lookup_expr='in', name='documentlink__categories')

    planned_start_date_lte = DateFilter(lookup_expr='lte',
                                        name='activity__planned_start')

    planned_start_date_gte = DateFilter(lookup_expr='gte',
                                        name='activity__planned_start')

    actual_start_date_lte = DateFilter(lookup_expr='lte',
                                       name='activity__actual_start')

    actual_start_date_gte = DateFilter(lookup_expr='gte',
                                       name='activity__actual_start')

    planned_end_date_lte = DateFilter(lookup_expr='lte',
                                      name='activity__planned_end')

    planned_end_date_gte = DateFilter(lookup_expr='gte',
                                      name='activity__planned_end')

    actual_end_date_lte = DateFilter(lookup_expr='lte',
                                     name='activity__actual_end')

    actual_end_date_gte = DateFilter(lookup_expr='gte',
                                     name='activity__actual_end')

    end_date_lte = DateFilter(lookup_expr='lte', name='activity__end_date')

    end_date_gte = DateFilter(lookup_expr='gte', name='activity__end_date')

    start_date_lte = DateFilter(lookup_expr='lte', name='activity__start_date')

    start_date_gte = DateFilter(lookup_expr='gte', name='activity__start_date')

    end_date_isnull = BooleanFilter(lookup_expr='isnull',
                                    name='activity__end_date')
    start_date_isnull = BooleanFilter(lookup_expr='isnull',
                                      name='activity__start_date')

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__activity_status',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__hierarchy',
    )

    collaboration_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__collaboration_type',
    )

    default_flow_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__default_flow_type',
    )

    default_aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__default_aid_type',
    )

    default_finance_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__default_finance_type',
    )

    default_tied_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity__default_tied_status',
    )

    budget_period_start = DateFilter(
        lookup_expr='gte',
        name='period_start',
    )

    budget_period_end = DateFilter(lookup_expr='lte', name='period_end')

    related_activity_recipient_country = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_id = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__iati_identifier',
        fk='current_activity',
    )

    related_activity_type = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='type__code',
        fk='current_activity',
    )

    related_activity_recipient_country = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_recipient_region = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_region',
        fk='current_activity',
    )

    related_activity_sector = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector',
        fk='current_activity',
    )

    related_activity_sector_category = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector__category',
        fk='current_activity',
    )

    budget_currency = ToManyFilter(
        qs=Budget,
        lookup_expr='in',
        name='currency__code',
        fk='activity__budget',
    )

    recipient_country = ToManyFilter(
        qs=ActivityRecipientCountry,
        lookup_expr='in',
        name='country__code',
        fk='activity__budget',
    )

    recipient_region = ToManyFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity__budget',
    )

    recipient_region_not = ToManyFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity__budget',
    )

    sector = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__code',
        fk='activity__budget',
    )

    sector_startswith = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='startswith',
        name='sector__code',
        fk='activity',
    )
    sector_vocabulary = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__vocabulary__code',
        fk='activity__budget',
    )

    sector_category = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__category__code',
        fk='activity__budget',
    )

    participating_organisation = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='normalized_ref',
        fk='activity__budget',
    )

    participating_organisation_name = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='primary_name',
        fk='activity__budget',
    )

    participating_organisation_role = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='role__code',
        fk='activity__budget',
    )

    participating_organisation_type = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='type__code',
        fk='activity__budget',
    )

    reporting_organisation_identifier = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        name='organisation__organisation_identifier',
        fk='activity__budget',
    )

    reporting_organisation_identifier_startswith = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='startswith',
        name='organisation__organisation_identifier',
        fk='activity__budget',
    )

    indicator_title = ToManyFilter(
        qs=ResultIndicatorTitle,
        lookup_expr='in',
        name='primary_name',
        fk='result_indicator__result__activity__budget')

    #
    # Transaction filters
    #

    transaction_type = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='transaction_type',
        fk='activity__budget',
    )

    provider_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__primary_name',
        fk='activity__budget',
    )

    receiver_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__primary_name',
        fk='activity__budget',
    )

    transaction_provider_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__narratives__content',
        fk='activity__budget',
    )

    transaction_receiver_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__narratives__content',
        fk='activity__budget',
    )

    transaction_provider_activity = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__provider_activity_ref',
        fk='activity__budget',
    )

    transaction_currency = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='currency',
        fk='activity__budget',
    )

    transaction_date_year = ToManyFilter(qs=Transaction,
                                         lookup_expr='year',
                                         name='transaction_date',
                                         fk='activity__budget')

    #
    # Aggregated values filters
    #

    total_budget_lte = NumberFilter(
        lookup_expr='lte', name='activity__activity_aggregation__budget_value')

    total_budget_gte = NumberFilter(
        lookup_expr='gte', name='activity__activity_aggregation__budget_value')

    total_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_aggregation__disbursement_value')

    total_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_aggregation__disbursement_value')

    total_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_aggregation__incoming_funds_value')

    total_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_aggregation__expenditure_value')

    total_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_aggregation__expenditure_value')

    total_commitment_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_aggregation__commitment_value')

    total_commitment_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_aggregation__commitment_value')

    total_hierarchy_budget_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_plus_child_aggregation__budget_value')

    total_hierarchy_budget_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_plus_child_aggregation__budget_value')

    total_hierarchy_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_commitment_lte = NumberFilter(
        lookup_expr='lte',
        name='activity__activity_plus_child_aggregation__commitment_value')

    total_hierarchy_commitment_gte = NumberFilter(
        lookup_expr='gte',
        name='activity__activity_plus_child_aggregation__commitment_value')

    class Meta:
        model = Budget
        fields = '__all__'
예제 #9
0
class DatasetFilter(FilterSet):
    """
    Filter countries list
    """

    id = CharFilter(lookup_expr='exact', field_name='id')

    name = CharFilter(lookup_expr='icontains', field_name='name')

    title = CharFilter(lookup_expr='icontains', field_name='title')

    filetype = CommaSeparatedCharFilter(lookup_expr='in',
                                        field_name='filetype')

    publisher_id = CharFilter(lookup_expr='exact', field_name='publisher__id')

    publisher_name = CharFilter(lookup_expr='icontains',
                                field_name='publisher__publisher_iati_id')

    publisher_title = CharFilter(lookup_expr='icontains',
                                 field_name='publisher__title')

    note_exception_type = ToManyFilter(qs=DatasetNote,
                                       lookup_expr='in',
                                       field_name='exception_type',
                                       fk='source')

    note_exception_type_contains = ToManyFilter(qs=DatasetNote,
                                                lookup_expr='icontains',
                                                field_name='exception_type',
                                                fk='source')

    note_model = ToManyFilter(qs=DatasetNote,
                              lookup_expr='in',
                              field_name='model',
                              fk='dataset')

    note_model_contains = ToManyFilter(qs=DatasetNote,
                                       lookup_expr='icontains',
                                       field_name='model',
                                       fk='dataset')

    note_field = ToManyFilter(qs=DatasetNote,
                              lookup_expr='in',
                              field_name='field',
                              fk='dataset')

    note_field_contains = ToManyFilter(qs=DatasetNote,
                                       lookup_expr='icontains',
                                       field_name='field',
                                       fk='dataset')

    note_message = ToManyFilter(qs=DatasetNote,
                                lookup_expr='in',
                                field_name='message',
                                fk='dataset')

    note_message_contains = ToManyFilter(qs=DatasetNote,
                                         lookup_expr='icontains',
                                         field_name='message',
                                         fk='dataset')

    note_count_gte = NumberFilter(lookup_expr='gte', field_name='note_count')

    metadata_modified_gte = DateTimeFilter(lookup_expr='gte',
                                           field_name='metadata_modified')

    q = SearchQueryFilter()

    class Meta:
        model = Dataset
        fields = '__all__'
예제 #10
0
class ActivityFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(name='id', lookup_expr='in')

    iati_identifier = CommaSeparatedCharFilter(name='iati_identifier',
                                               lookup_expr='in')

    activity_scope = CommaSeparatedCharFilter(
        name='scope__code',
        lookup_expr='in',
    )

    budget_not_provided = CommaSeparatedCharFilter(
        name='budget_not_provided',
        lookup_expr='in',
    )

    is_secondary_reporter = BooleanFilter(
        name='reporting_organisations__secondary_reporter',
        widget=BooleanWidget())

    has_crs_add = IsNullBooleanFilter(name='crsadd',
                                      lookup_expr='isnull',
                                      distinct=True,
                                      widget=BooleanWidget())

    has_other_identifier = IsNullBooleanFilter(name='otheridentifier',
                                               lookup_expr='isnull',
                                               distinct=True,
                                               widget=BooleanWidget())

    has_contact_info = IsNullBooleanFilter(name='contactinfo',
                                           lookup_expr='isnull',
                                           distinct=True,
                                           widget=BooleanWidget())

    has_activity_scope = IsNullBooleanFilter(name='scope',
                                             lookup_expr='isnull',
                                             distinct=True,
                                             widget=BooleanWidget())

    has_recipient_country = IsNullBooleanFilter(
        name='activityrecipientcountry',
        lookup_expr='isnull',
        distinct=True,
        widget=BooleanWidget())

    has_recipient_region = IsNullBooleanFilter(name='activityrecipientregion',
                                               lookup_expr='isnull',
                                               distinct=True,
                                               widget=BooleanWidget())

    has_location = IsNullBooleanFilter(name='location',
                                       lookup_expr='isnull',
                                       distinct=True,
                                       widget=BooleanWidget())

    has_sector = IsNullBooleanFilter(name='activitysector',
                                     lookup_expr='isnull',
                                     distinct=True,
                                     widget=BooleanWidget())

    has_tag = IsNullBooleanFilter(name='activitytag',
                                  lookup_expr='isnull',
                                  distinct=True,
                                  widget=BooleanWidget())

    has_country_budget_item = IsNullBooleanFilter(name='country_budget_items',
                                                  lookup_expr='isnull',
                                                  distinct=True,
                                                  widget=BooleanWidget())

    has_humanitarian_scope = IsNullBooleanFilter(name='humanitarianscope',
                                                 lookup_expr='isnull',
                                                 distinct=True,
                                                 widget=BooleanWidget())

    has_policy_marker = IsNullBooleanFilter(name='activitypolicymarker',
                                            lookup_expr='isnull',
                                            distinct=True,
                                            widget=BooleanWidget())

    has_collaboration_type = IsNullBooleanFilter(name='collaboration_type',
                                                 lookup_expr='isnull',
                                                 distinct=True,
                                                 widget=BooleanWidget())

    has_default_flow_type = IsNullBooleanFilter(name='default_flow_type',
                                                lookup_expr='isnull',
                                                distinct=True,
                                                widget=BooleanWidget())

    has_default_finance_type = IsNullBooleanFilter(name='default_finance_type',
                                                   lookup_expr='isnull',
                                                   distinct=True,
                                                   widget=BooleanWidget())

    has_default_aid_type = IsNullBooleanFilter(name='default_aid_types',
                                               lookup_expr='isnull',
                                               distinct=True,
                                               widget=BooleanWidget())

    has_default_tied_status = IsNullBooleanFilter(name='default_tied_status',
                                                  lookup_expr='isnull',
                                                  distinct=True,
                                                  widget=BooleanWidget())

    has_budget = IsNullBooleanFilter(name='budget',
                                     lookup_expr='isnull',
                                     distinct=True,
                                     widget=BooleanWidget())

    has_planned_disbursement = IsNullBooleanFilter(name='planneddisbursement',
                                                   lookup_expr='isnull',
                                                   distinct=True,
                                                   widget=BooleanWidget())

    has_capital_spend = IsNullBooleanFilter(name='capital_spend',
                                            lookup_expr='isnull',
                                            distinct=True,
                                            widget=BooleanWidget())

    has_document_link = IsNullBooleanFilter(name='documentlink',
                                            lookup_expr='isnull',
                                            distinct=True,
                                            widget=BooleanWidget())

    has_related_activity = IsNullBooleanFilter(name='relatedactivity',
                                               lookup_expr='isnull',
                                               distinct=True,
                                               widget=BooleanWidget())

    has_legacy_data = IsNullBooleanFilter(name='legacydata',
                                          lookup_expr='isnull',
                                          distinct=True,
                                          widget=BooleanWidget())

    has_condition = IsNullBooleanFilter(
        name='conditions',
        lookup_expr=
        'isnull',  # related name of Foreign Key for `activity` is `conditions` # NOQA: E501
        distinct=True,
        widget=BooleanWidget())
    has_result = IsNullBooleanFilter(name='result',
                                     lookup_expr='isnull',
                                     distinct=True,
                                     widget=BooleanWidget())

    has_fss = IsNullBooleanFilter(name='fss',
                                  lookup_expr='isnull',
                                  distinct=True,
                                  widget=BooleanWidget())

    document_link_category = ToManyFilter(
        qs=DocumentLink,
        lookup_expr='in',
        name='categories',
        fk='activity',
    )

    last_updated_datetime_gt = DateTimeFilter(lookup_expr='gt',
                                              name='last_updated_datetime')

    planned_start_date_lte = DateFilter(lookup_expr='lte',
                                        name='planned_start')

    planned_start_date_gte = DateFilter(lookup_expr='gte',
                                        name='planned_start')

    actual_start_date_lte = DateFilter(lookup_expr='lte', name='actual_start')

    actual_start_date_gte = DateFilter(lookup_expr='gte', name='actual_start')

    planned_end_date_lte = DateFilter(lookup_expr='lte', name='planned_end')

    planned_end_date_gte = DateFilter(lookup_expr='gte', name='planned_end')

    actual_end_date_lte = DateFilter(lookup_expr='lte', name='actual_end')

    actual_end_date_gte = DateFilter(lookup_expr='gte', name='actual_end')

    end_date_lte = DateFilter(lookup_expr='lte', name='end_date')

    end_date_gte = DateFilter(lookup_expr='gte', name='end_date')

    start_date_lte = DateFilter(lookup_expr='lte', name='start_date')

    start_date_gte = DateFilter(lookup_expr='gte', name='start_date')

    end_date_isnull = BooleanFilter(lookup_expr='isnull', name='end_date')
    start_date_isnull = BooleanFilter(lookup_expr='isnull', name='start_date')

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity_status',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='hierarchy',
    )

    collaboration_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='collaboration_type',
    )

    default_flow_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_flow_type',
    )

    default_aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_aid_types__aid_type__code',
    )

    default_finance_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_finance_type',
    )

    default_tied_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_tied_status',
    )

    budget_period_start = DateFilter(
        lookup_expr='gte',
        name='budget__period_start',
    )

    budget_period_end = DateFilter(lookup_expr='lte',
                                   name='budget__period_end')

    humanitarian = TypedChoiceFilter(choices=(('0', 'False'), ('1', 'True')),
                                     coerce=strtobool)

    humanitarian_scope_type = ToManyFilter(
        qs=HumanitarianScope,
        lookup_expr='in',
        name='type__code',
        fk='activity',
    )

    related_activity_id = ToManyFilter(
        qs=RelatedActivity,
        fk='current_activity',
        lookup_expr='in',
        name='ref_activity__normalized_iati_identifier',
    )

    related_activity_type = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='type__code',
        fk='current_activity',
    )

    related_activity_type_not = CommaSeparatedCharFilter(
        lookup_expr='in', name='relatedactivity__type__code', exclude=True)

    related_activity_transaction_receiver_organisation_name = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name=
        'ref_activity__transaction__receiver_organisation__narratives__content',  # NOQA: E501
        fk='current_activity',
    )

    related_activity_recipient_country = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_recipient_region = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_region',
        fk='current_activity',
    )

    related_activity_sector = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector',
        fk='current_activity',
    )

    related_activity_sector_category = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector__category',
        fk='current_activity',
    )

    budget_currency = ToManyFilter(
        qs=Budget,
        lookup_expr='in',
        name='currency__code',
        fk='activity',
    )

    recipient_country = ToManyFilter(
        qs=ActivityRecipientCountry,
        lookup_expr='in',
        name='country__code',
        fk='activity',
    )

    recipient_region = ToManyFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity',
    )

    recipient_region_not = ToManyNotInFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity',
    )

    sector = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__code',
        fk='activity',
    )

    sector_startswith = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='startswith',
        name='sector__code',
        fk='activity',
    )

    sector_vocabulary = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='vocabulary__code',
        fk='activity',
    )

    sector_category = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__category__code',
        fk='activity',
    )

    sector_startswith_in = StartsWithInCommaSeparatedCharFilter(
        lookup_expr='startswith',
        name='sector__code',
    )

    policy_marker = ToManyFilter(
        qs=ActivityPolicyMarker,
        lookup_expr='in',
        name='code',
        fk='activity',
    )

    participating_organisation = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='normalized_ref',
        fk='activity',
    )

    participating_organisation_name = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='primary_name',
        fk='activity',
    )

    participating_organisation_role = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='role__code',
        fk='activity',
    )

    participating_organisation_type = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='type__code',
        fk='activity',
    )

    reporting_organisation_identifier = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        name='organisation__organisation_identifier',
        fk='activity',
    )

    reporting_organisation_type = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        name='type',
        fk='activity')

    reporting_organisation_identifier_startswith = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='startswith',
        name='organisation__organisation_identifier',
        fk='activity',
    )

    result_title = ToManyFilter(
        qs=Result,
        lookup_expr='in',
        name='resulttitle__narratives__content',
        fk='activity',
    )

    indicator_title = ToManyFilter(qs=ResultIndicatorTitle,
                                   lookup_expr='in',
                                   name='primary_name',
                                   fk='result_indicator__result__activity')

    indicator_period_end_year = ToManyFilter(
        qs=ResultIndicatorPeriod,
        lookup_expr='year',
        name='period_end',
        fk='result_indicator__result__activity')

    other_identifier = ToManyFilter(
        qs=OtherIdentifier,
        lookup_expr='in',
        name='identifier',
        fk='activity',
    )

    #
    # Publisher meta filters
    #
    dataset_id = ToManyFilter(qs=Dataset,
                              lookup_expr='in',
                              name='id',
                              fk='activity')

    dataset_iati_id = ToManyFilter(qs=Dataset,
                                   lookup_expr='in',
                                   name='iati_id',
                                   fk='activity')

    publisher_id = ToManyFilter(qs=Publisher,
                                lookup_expr='in',
                                name='id',
                                fk='activity')

    publisher_iati_id = ToManyFilter(qs=Publisher,
                                     lookup_expr='in',
                                     name='iati_id',
                                     fk='activity')

    publisher_organisation_identifier = ToManyFilter(qs=Publisher,
                                                     lookup_expr='in',
                                                     name='publisher_iati_id',
                                                     fk='activity')

    #
    # Transaction filters
    #

    transaction_type = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='transaction_type',
        fk='activity',
    )

    provider_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__primary_name',
        fk='activity',
    )

    receiver_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__primary_name',
        fk='activity',
    )

    transaction_provider_organisation = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__ref',
        fk='activity',
    )

    transaction_receiver_organisation = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__ref',
        fk='activity',
    )

    transaction_provider_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__narratives__content',
        fk='activity',
    )

    transaction_receiver_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__narratives__content',
        fk='activity',
    )

    transaction_provider_activity = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__provider_activity_ref',
        fk='activity',
    )

    transaction_receiver_activity = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__receiver_activity_ref',
        fk='activity',
    )

    transaction_provider_activity_reporting_org = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name=
        'provider_organisation__provider_activity__reporting_organisations__ref',  # NOQA: E501
        fk='activity',
    )

    transaction_currency = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='currency',
        fk='activity',
    )

    transaction_date_year = ToManyFilter(qs=Transaction,
                                         lookup_expr='year',
                                         name='transaction_date',
                                         fk='activity')

    #
    # Aggregated values filters
    #

    total_budget_lte = NumberFilter(lookup_expr='lte',
                                    name='activity_aggregation__budget_value')

    total_budget_gte = NumberFilter(lookup_expr='gte',
                                    name='activity_aggregation__budget_value')

    total_disbursement_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__disbursement_value')

    total_disbursement_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__disbursement_value')

    total_incoming_funds_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__incoming_funds_value')

    total_expenditure_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__expenditure_value')

    total_expenditure_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__expenditure_value')

    total_commitment_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__commitment_value')

    total_commitment_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__commitment_value')

    total_hierarchy_budget_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_budget_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_commitment_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__commitment_value')

    total_hierarchy_commitment_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__commitment_value')

    #
    # Related to publishing
    #
    def filter_ready_to_publish(self, queryset, name, value):
        return queryset.filter(Q(ready_to_publish=True))

    ready_to_publish = CharFilter(name='ready_to_publish',
                                  method='filter_ready_to_publish')

    def filter_modified_ready_to_publish(self, queryset, name, value):
        return queryset.filter(Q(modified=True) & Q(ready_to_publish=True))

    modified_ready_to_publish = CharFilter(
        method='filter_modified_ready_to_publish')

    def filter_modified(self, queryset, name, value):
        return queryset.filter(Q(modified=True))

    modified = CharFilter(method='filter_modified')

    def filter_published(self, queryset, name, value):
        if value == "true":
            return queryset.filter(Q(published=True))
        else:
            return queryset.filter(Q(published=False))

    published = CharFilter(method='filter_published')

    class Meta:
        model = Activity
        together_exclusive = [('budget_period_start', 'budget_period_end')]
        fields = '__all__'
예제 #11
0
class ActivityFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(name='id', lookup_type='in')

    activity_scope = CommaSeparatedCharFilter(name='scope__code',
                                              lookup_type='in')

    recipient_country = CommaSeparatedCharFilter(lookup_type='in',
                                                 name='recipient_country')

    recipient_region = CommaSeparatedCharFilter(lookup_type='in',
                                                name='recipient_region')

    recipient_region_not_in = CommaSeparatedCharFilter(lookup_type='in',
                                                       name='recipient_region',
                                                       exclude=True)

    planned_start_date_lte = DateFilter(lookup_type='lte',
                                        name='planned_start')

    planned_start_date_gte = DateFilter(lookup_type='gte',
                                        name='planned_start')

    actual_start_date_lte = DateFilter(lookup_type='lte', name='actual_start')

    actual_start_date_gte = DateFilter(lookup_type='gte', name='actual_start')

    planned_end_date_lte = DateFilter(lookup_type='lte', name='planned_end')

    planned_end_date_gte = DateFilter(lookup_type='gte', name='planned_end')

    actual_end_date_lte = DateFilter(lookup_type='lte', name='actual_end')

    actual_end_date_gte = DateFilter(lookup_type='gte', name='actual_end')

    end_date_lte = DateFilter(lookup_type='lte', name='end_date')

    end_date_gte = DateFilter(lookup_type='gte', name='end_date')

    start_date_lte = DateFilter(lookup_type='lte', name='start_date')

    start_date_gte = DateFilter(lookup_type='gte', name='start_date')

    end_date_isnull = BooleanFilter(name='end_date__isnull')
    start_date_isnull = BooleanFilter(name='start_date__isnull')

    sector = CommaSeparatedCharFilter(lookup_type='in', name='sector')

    sector_category = CommaSeparatedCharFilter(
        lookup_type='in', name='activitysector__sector__category__code')

    participating_organisation = CommaSeparatedCharFilter(
        lookup_type='in', name='participating_organisations__ref')

    participating_organisation_name = CommaSeparatedCharFilter(
        lookup_type='in', name='participating_organisations__primary_name')

    participating_organisation_role = CommaSeparatedCharFilter(
        lookup_type='in', name='participating_organisations__role__code')

    reporting_organisation = CommaSeparatedCharFilter(
        lookup_type='in', name='reporting_organisations__ref')

    xml_source_ref = CommaSeparatedCharFilter(lookup_type='in',
                                              name='xml_source_ref')

    activity_status = CommaSeparatedCharFilter(lookup_type='in',
                                               name='activity_status',
                                               distinct=True)

    hierarchy = CommaSeparatedCharFilter(lookup_type='in', name='hierarchy')

    related_activity_id = CommaSeparatedCharFilter(
        lookup_type='in',
        name='relatedactivity__ref_activity__id',
        distinct=True)

    related_activity_type = CommaSeparatedCharFilter(
        lookup_type='in', name='relatedactivity__type__code', distinct=True)

    related_activity_recipient_country = CommaSeparatedCharFilter(
        lookup_type='in',
        name='relatedactivity__ref_activity__recipient_country',
        distinct=True)

    related_activity_recipient_region = CommaSeparatedCharFilter(
        lookup_type='in',
        name='relatedactivity__ref_activity__recipient_region',
        distinct=True)

    related_activity_sector = CommaSeparatedCharFilter(
        lookup_type='in',
        name='relatedactivity__ref_activity__sector',
        distinct=True)

    related_activity_sector_category = CommaSeparatedCharFilter(
        lookup_type='in',
        name='relatedactivity__ref_activity__sector__category',
        distinct=True)

    budget_period_start = DateFilter(lookup_type='gte',
                                     name='budget__period_start')

    budget_period_end = DateFilter(lookup_type='lte',
                                   name='budget__period_end')

    budget_currency = CommaSeparatedCharFilter(lookup_type='in',
                                               name='budget__currency__code')

    transaction_provider_activity = CommaSeparatedCharFilter(
        lookup_type='in',
        name='transaction__provider_organisation__provider_activity_ref',
        distinct=True)

    transaction_date_year = NumberFilter(lookup_type='year',
                                         name='transaction__transaction_date',
                                         distinct=True)

    activity_aggregation_budget_value_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__budget_value')

    activity_aggregation_budget_value_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__budget_value')

    activity_aggregation_disbursement_value_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__disbursement_value')

    activity_aggregation_disbursement_value_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__disbursement_value')

    activity_aggregation_incoming_fund_value_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__incoming_funds_value')

    activity_aggregation_incoming_fund_value_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__incoming_funds_value')

    activity_aggregation_expenditure_value_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__expenditure_value')

    activity_aggregation_expenditure_value_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__expenditure_value')

    activity_aggregation_commitment_value_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__commitment_value')

    activity_aggregation_commitment_value_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__commitment_value')

    activity_plus_child_aggregation_budget_value_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__budget_value')

    activity_plus_child_aggregation_budget_value_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__budget_value')

    activity_plus_child_aggregation_disbursement_value_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__disbursement_value')

    activity_plus_child_aggregation_disbursement_value_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__disbursement_value')

    activity_plus_child_aggregation_incoming_fund_value_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    activity_plus_child_aggregation_incoming_fund_value_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    activity_plus_child_aggregation_expenditure_value_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__expenditure_value')

    activity_plus_child_aggregation_expenditure_value_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__expenditure_value')

    activity_plus_child_aggregation_commitment_value_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__commitment_value')

    activity_plus_child_aggregation_commitment_value_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__commitment_value')

    class Meta:
        model = Activity
        together_exclusive = [('budget_period_start', 'budget_period_end')]
예제 #12
0
class TransactionFilter(FilterSet):
    """
    Transaction filter class
    """

    transaction_type = CommaSeparatedCharFilter(
        field_name='transaction_type',
        lookup_expr='in')

    currency = CommaSeparatedCharFilter(
        field_name='currency',
        lookup_expr='in')

    transaction_date_year = NumberFilter(
        lookup_expr='year',
        field_name='transaction_date'
    )

    transaction_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='transaction_date')

    transaction_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='transaction_date')

    min_value = NumberFilter(field_name='value', lookup_expr='gte')
    max_value = NumberFilter(field_name='value', lookup_expr='lte')

    value = NumberFilter(
        lookup_expr='exact', field_name='value'
    )

    value_not = NumberFilter(
        lookup_expr='exact', field_name='value', exclude=True
    )

    xdr_value_not = NumberFilter(
        lookup_expr='exact', field_name='xdr_value', exclude=True)
    usd_value_not = NumberFilter(
        lookup_expr='exact', field_name='usd_value', exclude=True)
    eur_value_not = NumberFilter(
        lookup_expr='exact', field_name='eur_value', exclude=True)
    gbp_value_not = NumberFilter(
        lookup_expr='exact', field_name='gbp_value', exclude=True)
    jpy_value_not = NumberFilter(
        lookup_expr='exact', field_name='jpy_value', exclude=True)
    cad_value_not = NumberFilter(
        lookup_expr='exact', field_name='cad_value', exclude=True)

    provider_activity = ToManyFilter(
        qs=TransactionProvider,
        lookup_expr='in',
        field_name='provider_activity_ref',
        fk='transaction',
    )

    has_provider_activity = BooleanFilter(
        field_name='provider_organisation__provider_activity',
        lookup_expr='isnull',
        exclude=True)

    provider_activity_reporting_org = ToManyFilter(
        qs=TransactionProvider,
        lookup_expr='in',
        field_name='provider_activity__reporting_organisations__organisation__\
              organisation_identifier',
        fk='transaction',
    )

    aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='aid_type__code',
    )

    provider_organisation_primary_name = ToManyFilter(
        qs=TransactionProvider,
        lookup_expr='in',
        field_name='primary_name',
        fk='transaction',
    )

    provider_organisation_name = ToManyFilter(
        qs=TransactionProvider,
        lookup_expr='in',
        field_name='narratives__content',
        fk='transaction',
    )

    receiver_organisation_primary_name = ToManyFilter(
        qs=TransactionReceiver,
        lookup_expr='in',
        field_name='primary_name',
        fk='transaction',
    )

    receiver_organisation_name = ToManyFilter(
        qs=TransactionReceiver,
        lookup_expr='in',
        field_name='narratives__content',
        fk='transaction',
    )

    #
    # Activity filters...
    #

    activity_id = CommaSeparatedCharFilter(
        field_name='activity__id',
        lookup_expr='in')

    iati_identifier = CommaSeparatedCharFilter(
        field_name='activity__iati_identifier',
        lookup_expr='in')

    activity_scope = CommaSeparatedCharFilter(
        field_name='activity__scope__code',
        lookup_expr='in',)

    planned_start_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__planned_start')

    planned_start_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__planned_start')

    actual_start_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__actual_start')

    actual_start_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__actual_start')

    planned_end_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__planned_end')

    planned_end_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__planned_end')

    actual_end_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__actual_end')

    actual_end_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__actual_end')

    end_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__end_date')

    end_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__end_date')

    start_date_lte = DateFilter(
        lookup_expr='lte',
        field_name='activity__start_date')

    start_date_gte = DateFilter(
        lookup_expr='gte',
        field_name='activity__start_date')

    end_date_isnull = BooleanFilter(field_name='activity__end_date__isnull')
    start_date_isnull = BooleanFilter(
        field_name='activity__start_date__isnull'
    )

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__activity_status',)

    document_link_category = ToManyFilter(
        main_fk='activity',
        qs=DocumentLink,
        fk='activity',
        lookup_expr='in',
        field_name='categories__code',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__hierarchy',)

    collaboration_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__collaboration_type',)

    default_flow_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_flow_type',)

    default_aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_aid_types__aid_type__code',)

    default_finance_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_finance_type',)

    default_tied_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_tied_status',)

    budget_period_start = DateFilter(
        lookup_expr='gte',
        field_name='activity__budget__period_start',)

    budget_period_end = DateFilter(
        lookup_expr='lte',
        field_name='activity__budget__period_end')

    related_activity_id = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        fk='current_activity',
        lookup_expr='in',
        field_name='ref_activity__iati_identifier',
    )

    related_activity_type = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        field_name='type__code',
        fk='current_activity',
    )

    related_activity_recipient_country = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        field_name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_recipient_region = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        field_name='ref_activity__recipient_region',
        fk='current_activity',
    )

    related_activity_sector = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        field_name='ref_activity__sector',
        fk='current_activity',
    )

    related_activity_sector_category = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        lookup_expr='in',
        field_name='ref_activity__sector__category',
        fk='current_activity',
    )

    budget_currency = ToManyFilter(
        main_fk='activity',
        qs=Budget,
        lookup_expr='in',
        field_name='currency__code',
        fk='activity',
    )

    # makes no
    # TO DO: check if this also influences other filters
    # for example, sector_category should probably filter through
    # transactionsector__sector__category in the transaction endpoint

    recipient_country = ToManyFilter(
        main_fk='activity',
        qs=ActivityRecipientCountry,
        lookup_expr='in',
        field_name='country__code',
        fk='activity',
    )

    recipient_region = ToManyFilter(
        main_fk='activity',
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        field_name='region__code',
        fk='activity',
    )

    recipient_region_not = ToManyNotInFilter(
        main_fk='activity',
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        field_name='region__code',
        fk='activity',
    )

    sector = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__code',
        fk='activity',
    )

    sector_startswith = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='startswith',
        field_name='sector__code',
        fk='activity',
    )

    sector_vocabulary = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__vocabulary__code',
        fk='activity',
    )

    transaction_recipient_country = ToManyFilter(
        qs=TransactionRecipientCountry,
        lookup_expr='in',
        field_name='country__code',
        fk='transaction',
    )

    transaction_recipient_region = ToManyFilter(
        qs=TransactionRecipientRegion,
        lookup_expr='in',
        field_name='region__code',
        fk='transaction',
    )

    transaction_sector = ToManyFilter(
        qs=TransactionSector,
        lookup_expr='in',
        field_name='sector__code',
        fk='transaction',
    )

    sector_category = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__category__code',
        fk='activity',
    )

    participating_organisation_ref = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='normalized_ref',
        fk='activity',
    )

    participating_organisation_name = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='primary_name',
        fk='activity',
    )

    participating_organisation_role = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='role__code',
        fk='activity',
    )

    participating_organisation_type = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='type__code',
        fk='activity',
    )

    reporting_organisation_identifier = ToManyFilter(
        main_fk='activity',
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        field_name='organisation__organisation_identifier',
        fk='activity',
    )

    result_title = ToManyFilter(
        main_fk='activity',
        qs=Result,
        lookup_expr='in',
        field_name='resulttitle__narratives__content',
        fk='activity',
    )

    reporting_organisation_identifier_startswith = ToManyFilter(
        main_fk='activity',
        qs=ActivityReportingOrganisation,
        lookup_expr='startswith',
        field_name='organisation__organisation_identifier',
        fk='activity',
    )

    # activity aggregation filters
    total_budget_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__budget_value')

    total_budget_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__budget_value')

    total_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__disbursement_value')

    total_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__disbursement_value')

    total_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__incoming_funds_value')

    total_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__expenditure_value')

    total_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__expenditure_value')

    total_commitment_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__commitment_value')

    total_commitment_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__commitment_value')

    total_hierarchy_budget_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_plus_child_aggregation__budget_value')

    total_hierarchy_budget_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_plus_child_aggregation__budget_value')

    total_hierarchy_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_plus_child_aggregation__disbursement_value')  # NOQA: E501

    total_hierarchy_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_plus_child_aggregation__disbursement_value')  # NOQA: E501

    total_hierarchy_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_plus_child_aggregation__incoming_funds_value')  # NOQA: E501

    total_hierarchy_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_plus_child_aggregation__incoming_funds_value')  # NOQA: E501

    total_hierarchy_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_plus_child_aggregation__expenditure_value')  # NOQA: E501

    total_hierarchy_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_plus_child_aggregation__expenditure_value')  # NOQA: E501

    total_hierarchy_commitment_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_plus_child_aggregation__commitment_value')  # NOQA: E501

    total_hierarchy_commitment_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_plus_child_aggregation__commitment_value')  # NOQA: E501

    class Meta:
        model = Transaction
        fields = [
            'id',
            'transaction_type',
            'value',
            'min_value',
            'max_value',
        ]
예제 #13
0
파일: filters.py 프로젝트: HatimKH/OIPA
class ActivityFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(name='id', lookup_type='in')

    activity_scope = CommaSeparatedCharFilter(
        name='scope__code',
        lookup_type='in',
    )

    document_link_category = ToManyFilter(
        qs=DocumentLink,
        lookup_type='in',
        name='categories',
        fk='activity',
    )

    planned_start_date_lte = DateFilter(lookup_type='lte',
                                        name='planned_start')

    planned_start_date_gte = DateFilter(lookup_type='gte',
                                        name='planned_start')

    actual_start_date_lte = DateFilter(lookup_type='lte', name='actual_start')

    actual_start_date_gte = DateFilter(lookup_type='gte', name='actual_start')

    planned_end_date_lte = DateFilter(lookup_type='lte', name='planned_end')

    planned_end_date_gte = DateFilter(lookup_type='gte', name='planned_end')

    actual_end_date_lte = DateFilter(lookup_type='lte', name='actual_end')

    actual_end_date_gte = DateFilter(lookup_type='gte', name='actual_end')

    end_date_lte = DateFilter(lookup_type='lte', name='end_date')

    end_date_gte = DateFilter(lookup_type='gte', name='end_date')

    start_date_lte = DateFilter(lookup_type='lte', name='start_date')

    start_date_gte = DateFilter(lookup_type='gte', name='start_date')

    end_date_isnull = BooleanFilter(lookup_type='isnull', name='end_date')
    start_date_isnull = BooleanFilter(lookup_type='isnull', name='start_date')

    xml_source_ref = CommaSeparatedCharFilter(
        lookup_type='in',
        name='xml_source_ref',
    )

    activity_status = CommaSeparatedCharFilter(
        lookup_type='in',
        name='activity_status',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_type='in',
        name='hierarchy',
    )

    collaboration_type = CommaSeparatedCharFilter(
        lookup_type='in',
        name='collaboration_type',
    )

    default_flow_type = CommaSeparatedCharFilter(
        lookup_type='in',
        name='default_flow_type',
    )

    default_aid_type = CommaSeparatedCharFilter(
        lookup_type='in',
        name='default_aid_type',
    )

    default_finance_type = CommaSeparatedCharFilter(
        lookup_type='in',
        name='default_finance_type',
    )

    default_tied_status = CommaSeparatedCharFilter(
        lookup_type='in',
        name='default_tied_status',
    )

    budget_period_start = DateFilter(
        lookup_type='gte',
        name='budget__period_start',
    )

    budget_period_end = DateFilter(lookup_type='lte',
                                   name='budget__period_end')

    humanitarian = TypedChoiceFilter(choices=(('0', 'False'), ('1', 'True')),
                                     coerce=strtobool)

    humanitarian_scope_type = ToManyFilter(
        qs=HumanitarianScope,
        lookup_type='in',
        name='type__code',
        fk='activity',
    )

    related_activity_id = ToManyFilter(
        qs=RelatedActivity,
        fk='current_activity',
        lookup_type='in',
        name='ref_activity__id',
    )

    related_activity_type = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name='type__code',
        fk='current_activity',
    )

    related_activity_transaction_receiver_organisation_name = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name=
        'ref_activity__transaction__receiver_organisation__narratives__content',
        fk='current_activity',
    )

    related_activity_recipient_country = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_recipient_region = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name='ref_activity__recipient_region',
        fk='current_activity',
    )

    related_activity_sector = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name='ref_activity__sector',
        fk='current_activity',
    )

    related_activity_sector_category = ToManyFilter(
        qs=RelatedActivity,
        lookup_type='in',
        name='ref_activity__sector__category',
        fk='current_activity',
    )

    budget_currency = ToManyFilter(
        qs=Budget,
        lookup_type='in',
        name='currency__code',
        fk='activity',
    )

    recipient_country = ToManyFilter(
        qs=ActivityRecipientCountry,
        lookup_type='in',
        name='country__code',
        fk='activity',
    )

    recipient_region = ToManyFilter(
        qs=ActivityRecipientRegion,
        lookup_type='in',
        name='region__code',
        fk='activity',
    )

    sector = ToManyFilter(
        qs=ActivitySector,
        lookup_type='in',
        name='sector__code',
        fk='activity',
    )

    sector_category = ToManyFilter(
        qs=ActivitySector,
        lookup_type='in',
        name='sector__category__code',
        fk='activity',
    )

    policy_marker = ToManyFilter(
        qs=ActivityPolicyMarker,
        lookup_type='in',
        name='code',
        fk='activity',
    )

    participating_organisation = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_type='in',
        name='normalized_ref',
        fk='activity',
    )

    participating_organisation_name = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_type='in',
        name='primary_name',
        fk='activity',
    )

    participating_organisation_role = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_type='in',
        name='role__code',
        fk='activity',
    )

    participating_organisation_type = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_type='in',
        name='type__code',
        fk='activity',
    )

    reporting_organisation = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_type='in',
        name='normalized_ref',
        fk='activity',
    )

    reporting_organisation_startswith = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_type='startswith',
        name='normalized_ref',
        fk='activity',
    )

    result_title = ToManyFilter(
        qs=Result,
        lookup_type='in',
        name='resulttitle__narratives__content',
        fk='activity',
    )

    indicator_title = ToManyFilter(qs=ResultIndicatorTitle,
                                   lookup_type='in',
                                   name='primary_name',
                                   fk='result_indicator__result__activity')

    indicator_period_end_year = ToManyFilter(
        qs=ResultIndicatorPeriod,
        lookup_type='year',
        name='period_end',
        fk='result_indicator__result__activity')

    #
    # Transaction filters
    #

    transaction_type = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='transaction_type',
        fk='activity',
    )

    provider_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='provider_organisation__primary_name',
        fk='activity',
    )

    receiver_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='receiver_organisation__primary_name',
        fk='activity',
    )

    transaction_provider_organisation = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='provider_organisation__ref',
        fk='activity',
    )

    transaction_receiver_organisation = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='receiver_organisation__ref',
        fk='activity',
    )

    transaction_provider_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='provider_organisation__narratives__content',
        fk='activity',
    )

    transaction_receiver_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='receiver_organisation__narratives__content',
        fk='activity',
    )

    transaction_provider_activity = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='provider_organisation__provider_activity_ref',
        fk='activity',
    )

    transaction_receiver_activity = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='receiver_organisation__receiver_activity_ref',
        fk='activity',
    )

    transaction_provider_activity_reporting_org = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name=
        'provider_organisation__provider_activity__reporting_organisations__ref',
        fk='activity',
    )

    transaction_currency = ToManyFilter(
        qs=Transaction,
        lookup_type='in',
        name='currency',
        fk='activity',
    )

    transaction_date_year = ToManyFilter(qs=Transaction,
                                         lookup_type='year',
                                         name='transaction_date',
                                         fk='activity')

    #
    # Aggregated values filters
    #

    total_budget_lte = NumberFilter(lookup_type='lte',
                                    name='activity_aggregation__budget_value')

    total_budget_gte = NumberFilter(lookup_type='gte',
                                    name='activity_aggregation__budget_value')

    total_disbursement_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__disbursement_value')

    total_disbursement_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__disbursement_value')

    total_incoming_funds_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__incoming_funds_value')

    total_expenditure_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__expenditure_value')

    total_expenditure_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__expenditure_value')

    total_commitment_lte = NumberFilter(
        lookup_type='lte', name='activity_aggregation__commitment_value')

    total_commitment_gte = NumberFilter(
        lookup_type='gte', name='activity_aggregation__commitment_value')

    total_hierarchy_budget_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_budget_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_disbursement_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_disbursement_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_incoming_funds_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_incoming_funds_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_expenditure_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_expenditure_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_commitment_lte = NumberFilter(
        lookup_type='lte',
        name='activity_plus_child_aggregation__commitment_value')

    total_hierarchy_commitment_gte = NumberFilter(
        lookup_type='gte',
        name='activity_plus_child_aggregation__commitment_value')

    class Meta:
        model = Activity
        together_exclusive = [('budget_period_start', 'budget_period_end')]
예제 #14
0
파일: filters.py 프로젝트: punkch/OIPA
class ResultFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(
        field_name='activity__iati_identifier', lookup_expr='in')

    result_title = CommaSeparatedStickyCharFilter(
        field_name='resulttitle__primary_name',
        lookup_expr='in',
    )

    indicator_title = CommaSeparatedStickyCharFilter(
        field_name='resultindicator__resultindicatortitle__primary_name',
        lookup_expr='in',
    )

    indicator_period_actual_null = StickyBooleanFilter(
        lookup_expr='isnull',
        field_name='resultindicator__resultindicatorperiod__actual')

    result_indicator_period_end_year = StickyCharFilter(
        field_name='resultindicator__resultindicatorperiod__period_end',
        lookup_expr='year')

    # default filters
    activity_scope = CommaSeparatedCharFilter(
        field_name='activity__scope__code',
        lookup_expr='in',
    )

    planned_start_date_lte = DateFilter(lookup_expr='lte',
                                        field_name='activity__planned_start')

    planned_start_date_gte = DateFilter(lookup_expr='gte',
                                        field_name='activity__planned_start')

    actual_start_date_lte = DateFilter(lookup_expr='lte',
                                       field_name='activity__actual_start')

    actual_start_date_gte = DateFilter(lookup_expr='gte',
                                       field_name='activity__actual_start')

    planned_end_date_lte = DateFilter(lookup_expr='lte',
                                      field_name='activity__planned_end')

    planned_end_date_gte = DateFilter(lookup_expr='gte',
                                      field_name='activity__planned_end')

    actual_end_date_lte = DateFilter(lookup_expr='lte',
                                     field_name='activity__actual_end')

    actual_end_date_gte = DateFilter(lookup_expr='gte',
                                     field_name='activity__actual_end')

    end_date_lte = DateFilter(lookup_expr='lte',
                              field_name='activity__end_date')

    end_date_gte = DateFilter(lookup_expr='gte',
                              field_name='activity__end_date')

    start_date_lte = DateFilter(lookup_expr='lte',
                                field_name='activity__start_date')

    start_date_gte = DateFilter(lookup_expr='gte',
                                field_name='activity__start_date')

    end_date_isnull = BooleanFilter(field_name='activity__end_date__isnull')
    start_date_isnull = BooleanFilter(
        field_name='activity__start_date__isnull')

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__activity_status',
    )

    document_link_category = ToManyFilter(
        main_fk='activity',
        qs=DocumentLink,
        fk='activity',
        lookup_expr='in',
        field_name='categories__code',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__hierarchy',
    )

    collaboration_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__collaboration_type',
    )

    default_flow_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_flow_type',
    )

    default_aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_aid_type',
    )

    default_finance_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_finance_type',
    )

    default_tied_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        field_name='activity__default_tied_status',
    )

    budget_period_start = DateFilter(
        lookup_expr='gte',
        field_name='activity__budget__period_start',
    )

    budget_period_end = DateFilter(lookup_expr='lte',
                                   field_name='activity__budget__period_end')

    recipient_country = ToManyFilter(
        main_fk='activity',
        qs=ActivityRecipientCountry,
        lookup_expr='in',
        field_name='country__code',
        fk='activity',
    )

    recipient_region = ToManyFilter(
        main_fk='activity',
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        field_name='region__code',
        fk='activity',
    )

    sector = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__code',
        fk='activity',
    )

    sector_vocabulary = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__vocabulary__code',
        fk='activity',
    )

    sector_category = ToManyFilter(
        main_fk='activity',
        qs=ActivitySector,
        lookup_expr='in',
        field_name='sector__category__code',
        fk='activity',
    )

    participating_organisation = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='normalized_ref',
        fk='activity',
    )

    participating_organisation_name = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='primary_name',
        fk='activity',
    )

    participating_organisation_role = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='role__code',
        fk='activity',
    )

    participating_organisation_type = ToManyFilter(
        main_fk='activity',
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        field_name='type__code',
        fk='activity',
    )

    reporting_organisation_identifier = ToManyFilter(
        main_fk='activity',
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        field_name='organisation__organisation_identifier',
        fk='activity',
    )

    related_activity_id = ToManyFilter(
        main_fk='activity',
        qs=RelatedActivity,
        fk='current_activity',
        lookup_expr='in',
        field_name='ref_activity__iati_identifier',
    )

    total_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        field_name='activity__activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        field_name='activity__activity_aggregation__incoming_funds_value')

    class Meta:
        model = Result
        fields = '__all__'
예제 #15
0
class ActivityFilter(TogetherFilterSet):

    activity_id = CommaSeparatedCharFilter(name='normalized_iati_identifier',
                                           lookup_expr='in')

    activity_scope = CommaSeparatedCharFilter(
        name='scope__code',
        lookup_expr='in',
    )

    document_link_category = ToManyFilter(
        qs=DocumentLink,
        lookup_expr='in',
        name='categories',
        fk='activity',
    )

    planned_start_date_lte = DateFilter(lookup_expr='lte',
                                        name='planned_start')

    planned_start_date_gte = DateFilter(lookup_expr='gte',
                                        name='planned_start')

    actual_start_date_lte = DateFilter(lookup_expr='lte', name='actual_start')

    actual_start_date_gte = DateFilter(lookup_expr='gte', name='actual_start')

    planned_end_date_lte = DateFilter(lookup_expr='lte', name='planned_end')

    planned_end_date_gte = DateFilter(lookup_expr='gte', name='planned_end')

    actual_end_date_lte = DateFilter(lookup_expr='lte', name='actual_end')

    actual_end_date_gte = DateFilter(lookup_expr='gte', name='actual_end')

    end_date_lte = DateFilter(lookup_expr='lte', name='end_date')

    end_date_gte = DateFilter(lookup_expr='gte', name='end_date')

    start_date_lte = DateFilter(lookup_expr='lte', name='start_date')

    start_date_gte = DateFilter(lookup_expr='gte', name='start_date')

    end_date_isnull = BooleanFilter(lookup_expr='isnull', name='end_date')
    start_date_isnull = BooleanFilter(lookup_expr='isnull', name='start_date')

    activity_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='activity_status',
    )

    hierarchy = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='hierarchy',
    )

    collaboration_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='collaboration_type',
    )

    default_flow_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_flow_type',
    )

    default_aid_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_aid_type',
    )

    default_finance_type = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_finance_type',
    )

    default_tied_status = CommaSeparatedCharFilter(
        lookup_expr='in',
        name='default_tied_status',
    )

    budget_period_start = DateFilter(
        lookup_expr='gte',
        name='budget__period_start',
    )

    budget_period_end = DateFilter(lookup_expr='lte',
                                   name='budget__period_end')

    humanitarian = TypedChoiceFilter(choices=(('0', 'False'), ('1', 'True')),
                                     coerce=strtobool)

    humanitarian_scope_type = ToManyFilter(
        qs=HumanitarianScope,
        lookup_expr='in',
        name='type__code',
        fk='activity',
    )

    related_activity_id = ToManyFilter(
        qs=RelatedActivity,
        fk='current_activity',
        lookup_expr='in',
        name='ref_activity__normalized_iati_identifier',
    )

    related_activity_type = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='type__code',
        fk='current_activity',
    )

    related_activity_type_not = CommaSeparatedCharFilter(
        lookup_expr='in', name='relatedactivity__type__code', exclude=True)

    related_activity_transaction_receiver_organisation_name = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name=
        'ref_activity__transaction__receiver_organisation__narratives__content',
        fk='current_activity',
    )

    related_activity_recipient_country = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_country',
        fk='current_activity',
    )

    related_activity_recipient_region = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__recipient_region',
        fk='current_activity',
    )

    related_activity_sector = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector',
        fk='current_activity',
    )

    related_activity_sector_category = ToManyFilter(
        qs=RelatedActivity,
        lookup_expr='in',
        name='ref_activity__sector__category',
        fk='current_activity',
    )

    budget_currency = ToManyFilter(
        qs=Budget,
        lookup_expr='in',
        name='currency__code',
        fk='activity',
    )

    recipient_country = ToManyFilter(
        qs=ActivityRecipientCountry,
        lookup_expr='in',
        name='country__code',
        fk='activity',
    )

    recipient_region = ToManyFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity',
    )

    recipient_region_not = ToManyNotInFilter(
        qs=ActivityRecipientRegion,
        lookup_expr='in',
        name='region__code',
        fk='activity',
    )

    sector = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__code',
        fk='activity',
    )

    sector_vocabulary = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__vocabulary__code',
        fk='activity',
    )

    sector_category = ToManyFilter(
        qs=ActivitySector,
        lookup_expr='in',
        name='sector__category__code',
        fk='activity',
    )

    policy_marker = ToManyFilter(
        qs=ActivityPolicyMarker,
        lookup_expr='in',
        name='code',
        fk='activity',
    )

    participating_organisation = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='normalized_ref',
        fk='activity',
    )

    participating_organisation_name = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='primary_name',
        fk='activity',
    )

    participating_organisation_role = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='role__code',
        fk='activity',
    )

    participating_organisation_type = ToManyFilter(
        qs=ActivityParticipatingOrganisation,
        lookup_expr='in',
        name='type__code',
        fk='activity',
    )

    reporting_organisation_identifier = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='in',
        name='organisation__organisation_identifier',
        fk='activity',
    )

    reporting_organisation_identifier_startswith = ToManyFilter(
        qs=ActivityReportingOrganisation,
        lookup_expr='startswith',
        name='organisation__organisation_identifier',
        fk='activity',
    )

    result_title = ToManyFilter(
        qs=Result,
        lookup_expr='in',
        name='resulttitle__narratives__content',
        fk='activity',
    )

    indicator_title = ToManyFilter(qs=ResultIndicatorTitle,
                                   lookup_expr='in',
                                   name='primary_name',
                                   fk='result_indicator__result__activity')

    indicator_period_end_year = ToManyFilter(
        qs=ResultIndicatorPeriod,
        lookup_expr='year',
        name='period_end',
        fk='result_indicator__result__activity')

    #
    # Transaction filters
    #

    transaction_type = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='transaction_type',
        fk='activity',
    )

    provider_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__primary_name',
        fk='activity',
    )

    receiver_organisation_primary_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__primary_name',
        fk='activity',
    )

    transaction_provider_organisation = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__ref',
        fk='activity',
    )

    transaction_receiver_organisation = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__ref',
        fk='activity',
    )

    transaction_provider_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__narratives__content',
        fk='activity',
    )

    transaction_receiver_organisation_name = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__narratives__content',
        fk='activity',
    )

    transaction_provider_activity = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='provider_organisation__provider_activity_ref',
        fk='activity',
    )

    transaction_receiver_activity = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='receiver_organisation__receiver_activity_ref',
        fk='activity',
    )

    transaction_provider_activity_reporting_org = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name=
        'provider_organisation__provider_activity__reporting_organisations__ref',
        fk='activity',
    )

    transaction_currency = ToManyFilter(
        qs=Transaction,
        lookup_expr='in',
        name='currency',
        fk='activity',
    )

    transaction_date_year = ToManyFilter(qs=Transaction,
                                         lookup_expr='year',
                                         name='transaction_date',
                                         fk='activity')

    #
    # Aggregated values filters
    #

    total_budget_lte = NumberFilter(lookup_expr='lte',
                                    name='activity_aggregation__budget_value')

    total_budget_gte = NumberFilter(lookup_expr='gte',
                                    name='activity_aggregation__budget_value')

    total_disbursement_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__disbursement_value')

    total_disbursement_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__disbursement_value')

    total_incoming_funds_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__incoming_funds_value')

    total_incoming_funds_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__incoming_funds_value')

    total_expenditure_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__expenditure_value')

    total_expenditure_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__expenditure_value')

    total_commitment_lte = NumberFilter(
        lookup_expr='lte', name='activity_aggregation__commitment_value')

    total_commitment_gte = NumberFilter(
        lookup_expr='gte', name='activity_aggregation__commitment_value')

    total_hierarchy_budget_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_budget_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__budget_value')

    total_hierarchy_disbursement_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_disbursement_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__disbursement_value')

    total_hierarchy_incoming_funds_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_incoming_funds_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__incoming_funds_value')

    total_hierarchy_expenditure_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_expenditure_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__expenditure_value')

    total_hierarchy_commitment_lte = NumberFilter(
        lookup_expr='lte',
        name='activity_plus_child_aggregation__commitment_value')

    total_hierarchy_commitment_gte = NumberFilter(
        lookup_expr='gte',
        name='activity_plus_child_aggregation__commitment_value')

    #
    # Related to publishing
    #
    def filter_ready_to_publish(self, queryset, name, value):
        return queryset.filter(Q(ready_to_publish=True))

    ready_to_publish = CharFilter(name='ready_to_publish',
                                  method='filter_ready_to_publish')

    def filter_modified_ready_to_publish(self, queryset, name, value):
        return queryset.filter(Q(modified=True) & Q(ready_to_publish=True))

    modified_ready_to_publish = CharFilter(
        method='filter_modified_ready_to_publish')

    def filter_modified(self, queryset, name, value):
        return queryset.filter(Q(modified=True))

    modified = CharFilter(method='filter_modified')

    def filter_published(self, queryset, name, value):
        if value == "true":
            return queryset.filter(Q(published=True))
        else:
            return queryset.filter(Q(published=False))

    published = CharFilter(method='filter_published')

    # modified = BooleanFilter(name='modified')
    # start_date_isnull = BooleanFilter(lookup_expr='isnull', name='start_date')

    class Meta:
        model = Activity
        together_exclusive = [('budget_period_start', 'budget_period_end')]
        fields = '__all__'
예제 #16
0
class DatasetFilter(FilterSet):
    """
    Filter countries list
    """

    id = CharFilter(lookup_type='exact', name='id')

    ref = CharFilter(lookup_type='icontains', name='ref')

    title = CharFilter(lookup_type='icontains', name='title')

    source_type = CommaSeparatedCharFilter(lookup_type='in', name='type')

    publisher_id = CharFilter(lookup_type='exact', name='publisher__id')

    publisher_ref = CharFilter(lookup_type='icontains',
                               name='publisher__org_id')

    publisher_name = CharFilter(lookup_type='icontains',
                                name='publisher__org_name')

    note_exception_type = ToManyFilter(qs=IatiXmlSourceNote,
                                       lookup_type='in',
                                       name='exception_type',
                                       fk='source')

    note_exception_type_contains = ToManyFilter(qs=IatiXmlSourceNote,
                                                lookup_type='icontains',
                                                name='exception_type',
                                                fk='source')

    note_model = ToManyFilter(qs=IatiXmlSourceNote,
                              lookup_type='in',
                              name='model',
                              fk='source')

    note_model_contains = ToManyFilter(qs=IatiXmlSourceNote,
                                       lookup_type='icontains',
                                       name='model',
                                       fk='source')

    note_field = ToManyFilter(qs=IatiXmlSourceNote,
                              lookup_type='in',
                              name='field',
                              fk='source')

    note_field_contains = ToManyFilter(qs=IatiXmlSourceNote,
                                       lookup_type='icontains',
                                       name='field',
                                       fk='source')

    note_message = ToManyFilter(qs=IatiXmlSourceNote,
                                lookup_type='in',
                                name='field',
                                fk='source')

    note_message_contains = ToManyFilter(qs=IatiXmlSourceNote,
                                         lookup_type='icontains',
                                         name='field',
                                         fk='source')

    note_count_gte = NumberFilter(lookup_type='gte', name='note_count')

    date_updated_gte = DateTimeFilter(lookup_type='gte', name='date_updated')

    class Meta:
        model = IatiXmlSource