class RateFilterAPI(RateFilter, FilterSet): source = ChoiceFilter(choices=mch.SOURCE_CHOICES) currency = ChoiceFilter(choices=mch.CURRENCY_CHOICES) filter_choices = [ ('exact', 'Equals'), ('gt', 'Greater than'), ('gte', 'Greater than equals'), ('lt', 'Less than'), ('lte', 'Less than equals'), ] buy = django_filters.LookupChoiceFilter( field_class=forms.DecimalField, lookup_choices=filter_choices, ) sale = django_filters.LookupChoiceFilter( field_class=forms.DecimalField, lookup_choices=filter_choices, ) class Meta: model = Rate fields = [ 'buy', 'sale', ]
class PersonListFilter(django_filters.FilterSet): name = django_filters.CharFilter( lookup_expr='icontains', help_text=Person._meta.get_field('name').help_text, label=Person._meta.get_field('name').verbose_name) belongs_to_institution = django_filters.ModelMultipleChoiceFilter( queryset=Institution.objects.all(), help_text=Person._meta.get_field('belongs_to_institution').help_text, label=Person._meta.get_field('belongs_to_institution').verbose_name) place_of_birth = django_filters.ModelMultipleChoiceFilter( queryset=Place.objects.filter(is_birthplace__isnull=False).distinct(), help_text=Person._meta.get_field('place_of_birth').help_text, label=Person._meta.get_field('place_of_birth').verbose_name, ) place_of_death = django_filters.ModelMultipleChoiceFilter( queryset=Place.objects.filter(is_deathplace__isnull=False).distinct(), help_text=Person._meta.get_field('place_of_death').help_text, label=Person._meta.get_field('place_of_death').verbose_name, ) date_of_birth = django_filters.LookupChoiceFilter( field_class=forms.DateField, lookup_choices=DATE_LOOKUP_CHOICES, help_text=Person._meta.get_field('date_of_birth').help_text, ) date_of_death = django_filters.LookupChoiceFilter( field_class=forms.DateField, lookup_choices=DATE_LOOKUP_CHOICES, help_text=Person._meta.get_field('date_of_death').help_text, ) class Meta: model = Person fields = "__all__"
class SecretFilter(filters.FilterSet): name = django_filters.LookupChoiceFilter(field_class=forms.CharField, field_name='name', lookup_choices=char_choices) value = django_filters.LookupChoiceFilter(field_class=forms.CharField, field_name='value', lookup_choices=char_choices) class Meta: model = Secret fields = ('name', 'value')
class HapaBelegListFilter(django_filters.FilterSet): zotero_id = django_filters.ModelMultipleChoiceFilter( queryset=ZotItem.objects.all(), help_text=HapaBeleg._meta.get_field('zotero_id').help_text, label=HapaBeleg._meta.get_field('zotero_id').verbose_name, widget=autocomplete.Select2Multiple(url="bib:zotitem-autocomplete", )) tags = django_filters.ModelMultipleChoiceFilter(queryset=Tag.objects.all(), help_text='Tags', label='Tags') text = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaBeleg._meta.get_field('text').help_text, label=HapaBeleg._meta.get_field('text').verbose_name, ) short_quote = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaBeleg._meta.get_field('short_quote').help_text, label=HapaBeleg._meta.get_field('short_quote').verbose_name) full_quote = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaBeleg._meta.get_field('full_quote').help_text, label=HapaBeleg._meta.get_field('full_quote').verbose_name) comment = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaBeleg._meta.get_field('comment').help_text, label=HapaBeleg._meta.get_field('comment').verbose_name) internal_comment = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaBeleg._meta.get_field('internal_comment').help_text, label=HapaBeleg._meta.get_field('internal_comment').verbose_name) class Meta: model = HapaBeleg fields = [ 'id', 'zotero_id', 'text', 'page_nr', 'short_quote', 'full_quote', 'time_of_origin_start', 'time_of_origin_end', 'tags', ]
class TextListFilter(django_filters.FilterSet): legacy_id = django_filters.LookupChoiceFilter( field_class=forms.CharField, lookup_choices=LOOKUP_CHOICES, help_text=Text._meta.get_field('legacy_id').help_text, label=Text._meta.get_field('legacy_id').verbose_name) class Meta: model = Text fields = "__all__"
class Calidad(django_filters.FilterSet): id = django_filters.ModelChoiceFilter(queryset=Quality.objects.values_list('id', flat=True).order_by('-value')) value = django_filters.LookupChoiceFilter( field_class=forms.FloatField, lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Lower than'), ] ) class Meta: model = Quality fields = ['id','value',]
class PostDPOFilter(django_filters.FilterSet): name = django_filters.CharFilter(lookup_expr='icontains') alamat = django_filters.CharFilter(lookup_expr='icontains') created_at = django_filters.NumberFilter(lookup_expr='year') reward = django_filters.LookupChoiceFilter(lookup_choices=[ ('exact', 'Sama Dengan (=)'), ('gt', 'Lebih Besar (>)'), ('lt', 'Lebih Kecil (<)'), ]) class Meta: model = PostCari fields = ['name', 'umur', 'reward', 'created_at', 'alamat', 'gender']
class AssignmentListFilter(django_filters.FilterSet): title = django_filters.LookupChoiceFilter( field_class=forms.CharField, lookup_choices=LOOKUP_CHOICES, help_text=Assignment._meta.get_field('title').help_text, label=Assignment._meta.get_field('title').verbose_name) description = django_filters.CharFilter( lookup_expr='icontains', help_text=Assignment._meta.get_field('description').help_text, label=Assignment._meta.get_field('description').verbose_name) class Meta: model = Assignment fields = "__all__"
class CallbackFilter(filters.FilterSet): ip = django_filters.LookupChoiceFilter(field_class=forms.CharField, field_name='sourceip', lookup_choices=char_choices) port = django_filters.LookupChoiceFilter(field_class=forms.IntegerField, field_name='serverport', lookup_choices=number_choices) timestamp = django_filters.DateTimeFromToRangeFilter( field_name='timestamp', ) fingerprint = django_filters.ModelChoiceFilter( queryset=Fingerprint.objects.all()) data = django_filters.LookupChoiceFilter(field_class=forms.CharField, field_name='datahex', lookup_choices=char_choices) def __init__(self, *args, **kwargs): super(CallbackFilter, self).__init__(*args, **kwargs) if self.request.method == 'GET': if 'data' in self.request.GET: data = self.request.GET.get('data') if is_hex(data) is False: hex = binascii.hexlify(data.encode()).decode() logger.info("Converted search '{}' term to '{}'".format( data, hex)) self.request.query_params._mutable = True self.request.query_params['data'] = hex class Meta: model = Callback fields = ( 'ip', 'port', 'protocol', 'timestamp', 'fingerprint', 'data', )
class HapaPlaceNameListFilter(django_filters.FilterSet): tags = django_filters.ModelMultipleChoiceFilter(queryset=Tag.objects.all(), help_text='Tags', label='Tags') name = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('name').help_text, label=HapaPlaceName._meta.get_field('name').verbose_name, ) alternative_names = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('alternative_names').help_text, label=HapaPlaceName._meta.get_field('alternative_names').verbose_name) historic_names = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('historic_names').help_text, label=HapaPlaceName._meta.get_field('historic_names').verbose_name) geonames = django_filters.ModelMultipleChoiceFilter( queryset=GeoNamesPlace.objects.all(), help_text=HapaPlaceName._meta.get_field('geonames').help_text, label=HapaPlaceName._meta.get_field('geonames').verbose_name, widget=autocomplete.Select2Multiple( url="gn_places-ac:geonamesplace-autocomplete", )) beleg = django_filters.ModelMultipleChoiceFilter( queryset=HapaBeleg.objects.all(), help_text=HapaPlaceName._meta.get_field('beleg').help_text, label=HapaPlaceName._meta.get_field('beleg').verbose_name, widget=autocomplete.Select2Multiple( url="archiv-ac:hapabeleg-autocomplete", )) beleg__zotero_id = django_filters.ModelMultipleChoiceFilter( queryset=ZotItem.objects.all(), help_text='Bibliographischer Eintrag', label='Bibliographischer Eintrag', widget=autocomplete.Select2Multiple(url="bib:zotitem-autocomplete", )) orig_sprache = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.filter(collection__name="orig_sprache"), help_text=HapaPlaceName._meta.get_field('orig_sprache').help_text, label=HapaPlaceName._meta.get_field('orig_sprache').verbose_name, widget=autocomplete.Select2Multiple( url="archiv-ac:orig-sprache", attrs={ 'data-placeholder': 'Autocomplete ...', 'data-minimum-input-length': 2, }, )) adm_unit = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.filter(collection__name="adm_unit"), help_text=HapaPlaceName._meta.get_field('adm_unit').help_text, label=HapaPlaceName._meta.get_field('adm_unit').verbose_name, widget=autocomplete.Select2Multiple( url='archiv-ac:adm-units', attrs={ 'data-placeholder': 'Autocomplete ...', 'data-minimum-input-length': 2, }, )) wortbildung = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('wortbildung').help_text, label=HapaPlaceName._meta.get_field('wortbildung').verbose_name) etymology = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('etymology').help_text, label=HapaPlaceName._meta.get_field('etymology').verbose_name) syntax = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('syntax').help_text, label=HapaPlaceName._meta.get_field('syntax').verbose_name) comment = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('comment').help_text, label=HapaPlaceName._meta.get_field('comment').verbose_name) internal_comment = django_filters.LookupChoiceFilter( lookup_choices=CHAR_LOOKUP_CHOICES, help_text=HapaPlaceName._meta.get_field('internal_comment').help_text, label=HapaPlaceName._meta.get_field('internal_comment').verbose_name) id = django_filters.NumberFilter(field_name='id') class Meta: model = HapaPlaceName exclude = [ 'point', 'fuzzy_geom', 'lat', 'long', 'orig_data_csv', ]
class TextVersionListFilter(django_filters.FilterSet): legacy_id = django_filters.LookupChoiceFilter( field_class=forms.CharField, lookup_choices=LOOKUP_CHOICES, help_text=TextVersion._meta.get_field('legacy_id').help_text, label=TextVersion._meta.get_field('legacy_id').verbose_name) text_id__participant_id = django_filters.ModelMultipleChoiceFilter( queryset=Participant.objects.all(), help_text=Text._meta.get_field('participant_id').help_text, label=Text._meta.get_field('participant_id').verbose_name) text_id__participant_id__learner_id__gender = django_filters.ChoiceFilter( choices=GENDER_CHOICES, help_text="Gender", label="Gender") text_id__participant_id__institution_level = django_filters.ChoiceFilter( choices=[(x[0], x[0]) for x in list( set(Participant.objects.all().values_list('institution_level')))], help_text="Institution Level", label="Institution Level") text_id__participant_id__clil = django_filters.ChoiceFilter( choices=YES_NO_OTHER, help_text="clil", label="clil") text_id__participant_id__learner_id__nationality = django_filters.ModelMultipleChoiceFilter( queryset=Place.objects.all(), help_text="Nationality", label="Nationality") text_id__participant_id__learner_id__lang_l = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_lang_l_of=None), help_text="mother tongue", label="mother tongue") text_id__participant_id__learner_id__lang_mother = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_mother_lang_of=None), help_text="lang mother", label="lang mother") text_id__participant_id__learner_id__lang_father = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_father_lang_of=None), help_text="lang father", label="lang father") text_id__participant_id__learner_id__lang_second = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_second_lang_of=None), help_text="second language", label="second language ≠ foreign language") text_id__participant_id__learner_id__lang_third = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_third_lang_of=None), help_text="third language", label="third language ≠ foreign language") text_id__participant_id__learner_profile_id__lang_spoken_home = django_filters.ChoiceFilter( choices=[(x[0], x[0]) for x in list( set(LearnerProfile.objects.all().values_list('lang_spoken_home'))) ], help_text= "(if more than one language is spoken, provide the % of use of each language)\ format: Bosnian: 50% Slovenian: 50%", label="description of language use at home") text_id__participant_id__learner_profile_id__lang_instruction_primary = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.exclude(is_lang_instruction_primary=None), help_text="Language of instruction in primary school", label="Language of instruction in primary school") text_id__participant_id__learner_profile_id__proficiency_level = django_filters.ChoiceFilter( choices=[(x[0], x[0]) for x in list( set(LearnerProfile.objects.all().values_list('proficiency_level'))) ], help_text="A1;A2;B1;B2;C1;C2", label="Latest CEF score/placement") text_id__grade = django_filters.RangeFilter() text_id__medium = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.filter( scheme__dc_title__icontains="text_medium"), help_text=Text._meta.get_field('medium').help_text, label=Text._meta.get_field('medium').verbose_name, widget=forms.CheckboxSelectMultiple( attrs={'class': 'chbx-select-multi'})) text_id__mode = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.filter( scheme__dc_title__icontains="text_mode"), help_text=Text._meta.get_field('mode').help_text, label=Text._meta.get_field('mode').verbose_name, widget=forms.CheckboxSelectMultiple( attrs={'class': 'chbx-select-multi'})) text_id__text_type = django_filters.ModelMultipleChoiceFilter( queryset=SkosConcept.objects.filter( scheme__dc_title__icontains="text_type"), help_text=Text._meta.get_field('text_type').help_text, label=Text._meta.get_field('text_type').verbose_name, widget=forms.CheckboxSelectMultiple( attrs={'class': 'chbx-select-multi'})) text_id__clil_text = django_filters.ChoiceFilter( choices=[ (x[0], x[0]) for x in list(set(Text.objects.all().values_list('clil_text'))) ], help_text= "(if more than one language is spoken, provide the % of use of each language)\ format: Bosnian: 50% Slovenian: 50%", label="description of language use at home") text_id__assignment_id = django_filters.ModelMultipleChoiceFilter( queryset=Assignment.objects, help_text=Assignment._meta.get_field('title').help_text, label='Select Assignment Title', widget=forms.CheckboxSelectMultiple( attrs={'class': 'chbx-select-multi'})) text_id__assignment_id__title = django_filters.LookupChoiceFilter( field_class=forms.CharField, lookup_choices=LOOKUP_CHOICES, help_text=Assignment._meta.get_field('title').help_text, label=Assignment._meta.get_field('title').verbose_name) class Meta: model = TextVersion fields = "__all__"
class TaskFilter(django_filters.FilterSet): """ This class creates an object filter for filtering a task model for its fields :param django_filters.FIlterSet: Django library needed for the filter to work """ #Nom de la tache. Si l'utilisateur cherche des lettre de la tache name = django_filters.CharFilter(field_name='name', lookup_expr='icontains', label='Nom', widget=forms.TextInput(attrs={'title': 'Nom de la tâche', 'placeholder': "Écrire entièrement ou partiellement le nom de la tâche..."})) # TODO(Nicola): borner la choix de field assignée aux utilisateurs du projet #Assignée field, lorsque un utilisateur est selectionné assignee = django_filters.ModelMultipleChoiceFilter(queryset=User.objects.all(), field_name='assignee', label='Assignée à') #Date de debut. On cherche les date après (gt) la date selectionnée start_date = django_filters.DateFilter(field_name='start_date', lookup_expr='gt', label='À faire après', widget=forms.DateInput(attrs={'type': 'date', 'title': 'Date de début', 'placeholder': "..."})) #Date de debut. On cherche les date avant (lt) la date selectionnée due_date = django_filters.DateFilter(field_name='due_date', lookup_expr='lt', label='À terminer avant', widget=forms.DateInput(attrs={'type': 'date', 'title': 'Date de fin', 'placeholder': "..."})) #Liason pour le statut de la tache status = django_filters.ModelMultipleChoiceFilter(queryset=Status.objects.all(), field_name='status', label='Statut') #La priorité peut etre cherché de plusieures façons: exacte, superieur, inferieur à un certain nombre priority = django_filters.LookupChoiceFilter(field_name='priority', lookup_choices=[('exact', 'Égale à'), ('gte', 'Supérieure ou égale à'), ('lte', 'Inférieure ou égale à')], field_class=forms.IntegerField, label='Priorité', validators=[MinValueValidator(1), MaxValueValidator(10)], widget=forms.TextInput(attrs={'min': 1, 'max': 10, 'type': 'number'}) ) #Le progrès peut etre cherché de plusieures façons: exacte, superieur, inferieur à un certain nombre progress = django_filters.LookupChoiceFilter(field_name='progress', lookup_choices=[('exact', 'Égal à'), ('gte', 'Supérieur ou égal à'), ('lte', 'Inférieur ou égal à')], field_class=forms.IntegerField, label='Progrès', validators=[MinValueValidator(0), MaxValueValidator(100)], widget=forms.TextInput(attrs={'min': 0, 'max': 100, 'type': 'number'}) ) #Les choix servent pour diversifier le type de tri CHOICES = ( ('priority descending', 'Priorité haute'), ('priority ascending', 'Priorité basse'), ('progress descending', 'Progrès élevé'), ('progress ascending', 'Progrès bas'), ('due_date closer', 'Date de fin proche'), ('due_date further', 'Date de fin lointaine') ) #Le tri est atteint par un ChoiceFilter avec une methode definie dessous task_ordering = django_filters.ChoiceFilter(label='Trier par', choices=CHOICES, method='filter_by_order') def filter_by_order(selfself, queryset, name, value): """ This function defines the way the queryset is gonna be sorted by specifying an expression linked to the fields expressed in CHOICES :param selfself: the funciton itself :param queryset: the queryset to sort :param name : :param value: the link with the fields in CHOICES """ if value == 'priority ascending': expression = 'priority' elif value == 'priority descending': expression = '-priority' elif value == 'progress ascending': expression = 'progress' elif value == 'progress descending': expression = '-progress' elif value == 'due_date closer': expression = 'due_date' elif value == 'due_date further': expression = '-due_date' else: value == 'priority' return queryset.order_by(expression)
class EbayItemsFilter(filters.FilterSet): """ Model filter which defines the filter fields and lookup rules. """ class Meta: # pylint: disable=too-few-public-methods """ Meta """ model = EbayItem fields = { 'item_no': ['exact'], 'item_id': ['exact'], 'auction_id': ['exact'], 'country': ['exact'] } item_status = django_filters.LookupChoiceFilter( field_class=forms.CharField, field_name='item_status', lookup_choices=[('exact', 'Equals'), ('startswith', 'Startswith')]) rank = django_filters.LookupChoiceFilter(field_class=forms.IntegerField, field_name='item_ranking_today', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ]) sales_l7 = django_filters.LookupChoiceFilter( field_class=forms.FloatField, field_name='sales_goal_reached_in_last7days', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ]) sales_l14 = django_filters.LookupChoiceFilter( field_class=forms.FloatField, field_name='sales_goal_reached_in_last14days', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ]) sales_mtd = django_filters.LookupChoiceFilter( field_class=forms.FloatField, field_name='sales_goal_reached_mtd', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ]) fc = django_filters.LookupChoiceFilter(field_class=forms.IntegerField, field_name='fc', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ]) stock = django_filters.LookupChoiceFilter(field_class=forms.IntegerField, field_name='stock', lookup_choices=[ ('exact', 'Equals'), ('gt', 'Greater than'), ('lt', 'Less than'), ])