コード例 #1
0
class PartnerProjectFilter(filters.FilterSet):
    partner = CharFilter(method='get_partner')
    title = CharFilter(method='get_title')
    location = CharFilter(method='get_location')
    status = ChoiceFilter(choices=PARTNER_PROJECT_STATUS)
    start_date = DateFilter(method='get_start_date')
    end_date = DateFilter(method='get_end_date')
    cluster_id = CharFilter(method='get_cluster_id')

    class Meta:
        model = PartnerProject
        fields = ['title', 'location', 'status', 'start_date', 'end_date']

    def get_partner(self, queryset, name, value):
        return queryset.filter(partner_id=value)

    def get_title(self, queryset, name, value):
        return queryset.filter(title__icontains=value)

    def get_location(self, queryset, name, value):
        return queryset.filter(locations__id=value)

    def get_start_date(self, queryset, name, value):
        return queryset.filter(start_date__gte=value)

    def get_end_date(self, queryset, name, value):
        return queryset.filter(end_date__lte=value)

    def get_cluster_id(self, queryset, name, value):
        return queryset.filter(clusters__in=[value])
コード例 #2
0
ファイル: filters.py プロジェクト: stuartquin/soitgoes
class TimeSlipFilter(FilterSet):
    start = DateFilter(field_name="date", lookup_expr="gte")
    end = DateFilter(field_name="date", lookup_expr="lte")
    no_invoice = BooleanFilter(field_name="invoice", lookup_expr="isnull")

    class Meta:
        model = TimeSlip
        fields = ["invoice", "project", "start", "end", "no_invoice"]
コード例 #3
0
ファイル: filters.py プロジェクト: iamrizvan/crm
class OrderFilter(django_filters.FilterSet):
    start_date = DateFilter(field_name="date_created", lookup_expr='gte')
    end_date = DateFilter(field_name="date_created", lookup_expr='lte')
    note = CharFilter(field_name='note', lookup_expr='icontains')

    class Meta:
        model = Order
        fields = '__all__'
        exclude = ['customer', 'date_created']
コード例 #4
0
class ContasFilter(django_filters.FilterSet):
    descricao = django_filters.CharFilter(lookup_expr='icontains')
    data_inicial = DateFilter(field_name="vencimento", lookup_expr='gte')
    data_final = DateFilter(field_name="vencimento", lookup_expr='lte')
    pago = django_filters.TypedChoiceFilter(choices=BOOLEAN_CHOICES,
                                            coerce=strtobool)

    class Meta:
        model = ContaPagamento
        fields = [
            'descricao',
            'centro_de_custo',
            'pago',
            'fornecedor',
        ]
コード例 #5
0
 def test_default_field(self):
     f = DateFilter()
     field = f.field
     self.assertIsInstance(field, forms.DateField)
コード例 #6
0
class ProgressReportFilter(django_filters.FilterSet):
    status = CharFilter(method='get_status')
    pd_ref_title = CharFilter(
        field_name='pd ref title',
        method='get_pd_ref_title',
        label='PD/Ref # title',
    )
    due_date = DateFilter(
        field_name='due date',
        method='get_due_date',
        label='Due date',
        input_formats=[settings.PRINT_DATA_FORMAT],
    )
    due = TypedChoiceFilter(
        field_name='due',
        choices=Boolean.CHOICES,
        coerce=strtobool,
        method='get_due_overdue_status',
        label='Show only due or overdue',
    )
    location = CharFilter(
        field_name='location',
        method='get_location',
        label='Location',
    )
    programme_document_ext = CharFilter(
        field_name='programme_document_ext',
        method='get_pd_ext',
        label='programme_document_ext',
    )
    section = CharFilter(field_name='section', method='get_section')
    cp_output = CharFilter(field_name='cp_output', method='get_cp_output')
    report_type = CharFilter(method='get_report_type')
    unicef_focal_points = CharFilter(method='get_unicef_focal_points')

    class Meta:
        model = ProgressReport
        fields = [
            'status', 'pd_ref_title', 'due_date', 'programme_document',
            'programme_document__id', 'programme_document__external_id',
            'section', 'cp_output', 'report_type'
        ]

    def get_unicef_focal_points(self, queryset, name, value):
        return queryset.filter(
            programme_document__unicef_focal_point__email__in=parse.unquote(
                value).split(',')).distinct()

    def get_status(self, queryset, name, value):
        return queryset.filter(status__in=parse.unquote(value).split(','))

    def get_pd_ext(self, queryset, name, value):
        return queryset.filter(programme_document__external_id=value)

    def get_section(self, queryset, name, value):
        return queryset.filter(programme_document__sections__external_id=value)

    def get_cp_output(self, queryset, name, value):
        return queryset.filter(
            programme_document__cp_outputs__external_cp_output_id=value)

    def get_due_overdue_status(self, queryset, name, value):
        if value:
            return queryset.filter(status__in=[
                PROGRESS_REPORT_STATUS.due, PROGRESS_REPORT_STATUS.overdue
            ])
        return queryset

    def get_pd_ref_title(self, queryset, name, value):
        return queryset.filter(
            Q(programme_document__reference_number__icontains=value)
            | Q(programme_document__title__icontains=value))

    def get_due_date(self, queryset, name, value):
        return queryset.filter(due_date__lte=value)

    def get_location(self, queryset, name, value):
        return queryset.filter(
            indicator_reports__indicator_location_data__location=value)

    def get_report_type(self, queryset, name, value):
        return queryset.filter(report_type__in=parse.unquote(value).split(','))
コード例 #7
0
class PermitRequestFilter(django_filters.FilterSet):

    date_end_from = DateFilter(field_name='date_end',
                               lookup_expr='gte',
                               label='Date de fin après le',
                               widget=DatePickerInput(
                                   attrs={"placeholder": "ex: 15/02/2019"},
                                   options={
                                       "format": "DD/MM/YYYY",
                                       "locale": "fr"
                                   }))

    date_end_to = DateFilter(field_name='date_end',
                             lookup_expr='lte',
                             label='Date de fin avant le',
                             widget=DatePickerInput(
                                 attrs={"placeholder": "ex: 15/02/2019"},
                                 options={
                                     "format": "DD/MM/YYYY",
                                     "locale": "fr"
                                 }))

    date_start_from = DateFilter(field_name='date_start',
                                 lookup_expr='gte',
                                 label='Date de début après le',
                                 widget=DatePickerInput(
                                     attrs={"placeholder": "ex: 15/02/2019"},
                                     options={
                                         "format": "DD/MM/YYYY",
                                         "locale": "fr"
                                     }))

    date_start_to = DateFilter(field_name='date_start',
                               lookup_expr='lte',
                               label='Date de début avant le',
                               widget=DatePickerInput(
                                   attrs={"placeholder": "ex: 15/02/2019"},
                                   options={
                                       "format": "DD/MM/YYYY",
                                       "locale": "fr",
                                   }))

    address = CharFilter(field_name='address',
                         lookup_expr='icontains',
                         label='L\'adresse contient le texte',
                         widget=TextInput(attrs={"placeholder": "ex: pesta"}))

    company_name = CharFilter(
        field_name='company__company_name',
        lookup_expr='icontains',
        label='La raison sociale contient le texte',
        widget=TextInput(attrs={"placeholder": "ex: taupe"}))

    project_owner_name = CharFilter(
        field_name='project_owner__name',
        lookup_expr='icontains',
        label='Le nom du maître d\'ouvrage contient le texte',
        widget=TextInput(attrs={"placeholder": "ex: Dupon"}))

    class Meta:
        model = PermitRequest
        fields = {
            'id': ['exact'],
            'address': ['exact'],
            'project_owner_name': ['exact'],
            'company_name': ['exact'],
            'date_end_from': ['gte'],
            'date_end_to': ['gte'],
            'date_start_from': ['gte'],
            'date_start_to': ['gte'],
            'validated': ['exact'],
            'paid': ['exact'],
            'ended': ['exact']
        }

        filter_overrides = {
            models.BooleanField: {
                'filter_class': django_filters.BooleanFilter,
                'extra': lambda f: {
                    'widget': forms.CheckboxInput,
                },
            },
        }
コード例 #8
0
class AutoresPossiveisFilterSet(FilterSet):
    data_relativa = DateFilter(method='filter_data_relativa')
    tipo = MethodFilter()

    class Meta:
        model = Autor
        fields = ['data_relativa', 'tipo', ]

    def filter_data_relativa(self, queryset, name, value):
        return queryset

    def filter_tipo(self, queryset, value):
        try:
            tipo = TipoAutor.objects.get(pk=value)
        except:
            raise serializers.ValidationError(_('Tipo de Autor inexistente.'))

        qs = queryset.filter(tipo=tipo)

        return qs

    @property
    def qs(self):
        qs = super().qs

        data_relativa = self.form.cleaned_data['data_relativa'] \
            if 'data_relativa' in self.form.cleaned_data else None

        tipo = self.form.cleaned_data['tipo'] \
            if 'tipo' in self.form.cleaned_data else None

        if not tipo and not data_relativa:
            return qs

        if tipo:
            # não precisa de try except, já foi validado em filter_tipo
            tipo = TipoAutor.objects.get(pk=tipo)
            if not tipo.content_type:
                return qs

        filter_for_model = 'filter_%s' % tipo.content_type.model

        if not hasattr(self, filter_for_model):
            return qs

        if not data_relativa:
            data_relativa = timezone.now()

        return getattr(self, filter_for_model)(qs, data_relativa).distinct()

    def filter_parlamentar(self, queryset, data_relativa):
        # não leva em conta afastamentos
        legislatura_relativa = Legislatura.objects.filter(
            data_inicio__lte=data_relativa,
            data_fim__gte=data_relativa).first()

        q = Q(
            parlamentar_set__mandato__data_inicio_mandato__lte=data_relativa,
            parlamentar_set__mandato__data_fim_mandato__isnull=True) | Q(
            parlamentar_set__mandato__data_inicio_mandato__lte=data_relativa,
            parlamentar_set__mandato__data_fim_mandato__gte=data_relativa)

        if legislatura_relativa.atual():
            q = q & Q(parlamentar_set__ativo=True)

        return queryset.filter(q)

    def filter_comissao(self, queryset, data_relativa):
        return queryset.filter(
            Q(comissao_set__data_extincao__isnull=True,
              comissao_set__data_fim_comissao__isnull=True) |
            Q(comissao_set__data_extincao__gte=data_relativa,
              comissao_set__data_fim_comissao__isnull=True) |
            Q(comissao_set__data_extincao__gte=data_relativa,
              comissao_set__data_fim_comissao__isnull=True) |
            Q(comissao_set__data_extincao__isnull=True,
              comissao_set__data_fim_comissao__gte=data_relativa) |
            Q(comissao_set__data_extincao__gte=data_relativa,
              comissao_set__data_fim_comissao__gte=data_relativa),
            comissao_set__data_criacao__lte=data_relativa)

    def filter_frente(self, queryset, data_relativa):
        return queryset.filter(
            Q(frente_set__data_extincao__isnull=True) |
            Q(frente_set__data_extincao__gte=data_relativa),
            frente_set__data_criacao__lte=data_relativa)

    def filter_bancada(self, queryset, data_relativa):
        return queryset.filter(
            Q(bancada_set__data_extincao__isnull=True) |
            Q(bancada_set__data_extincao__gte=data_relativa),
            bancada_set__data_criacao__lte=data_relativa)

    def filter_bloco(self, queryset, data_relativa):
        return queryset.filter(
            Q(bloco_set__data_extincao__isnull=True) |
            Q(bloco_set__data_extincao__gte=data_relativa),
            bloco_set__data_criacao__lte=data_relativa)

    def filter_orgao(self, queryset, data_relativa):
        # na implementação, não havia regras a implementar para orgao
        return queryset