class ProjectFilter(django_filters.FilterSet): """ Filter :model:`rolodex.Project` model. **Fields** ``start_date`` Date filter for ``start_date`` values greater than provided value ``end_date`` Date filter for ``end_date`` values less than provided value ``start_date_range`` Date range filter for retrieving entries with matching ``start_date`` values ``complete`` Boolean field for filtering incomplete projects based on the ``complete`` field ``codename`` Case insensitive search of the model's ``codename`` field ``client`` Case insensitive search of the model's ``client`` field """ client = django_filters.CharFilter( lookup_expr="name__icontains", widget=TextInput( attrs={ "placeholder": "Part of Client Name", "autocomplete": "off", } ), ) codename = django_filters.CharFilter( lookup_expr="icontains", widget=TextInput( attrs={ "placeholder": "Part of Codename", "autocomplete": "off", } ), ) start_date = django_filters.DateFilter( lookup_expr="gte", field_name="start_date", label="Start Date", widget=forms.DateInput(attrs={"type": "date", "class": "dateinput form-control"}), ) end_date = django_filters.DateFilter( lookup_expr="lte", field_name="end_date", label="End Date", widget=forms.DateInput(attrs={"type": "date", "class": "dateinput form-control"}), ) start_date_range = django_filters.DateRangeFilter( field_name="start_date", empty_label="-- Relative Start Date --" ) STATUS_CHOICES = ( (0, "Active"), (1, "Completed"), ) complete = django_filters.ChoiceFilter( choices=STATUS_CHOICES, empty_label="All Projects", label="Project status" ) class Meta: model = Project fields = [ "complete", ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Div( Row( Column( PrependedText("client", '<i class="fas fa-filter"></i>'), css_class="form-group col-md-4 mb-0", ), Column( PrependedText("codename", '<i class="fas fa-filter"></i>'), css_class="form-group col-md-4 mb-0", ), Column("complete", css_class="form-group col-md-4 mb-0"), ), Row( Column("start_date_range", css_class="form-group col-md-4 mb-0"), Column( PrependedText( "start_date", '<i class="fas fa-hourglass-start"></i>' ), css_class="form-group col-md-4 mb-0", ), Column( PrependedText( "end_date", '<i class="fas fa-hourglass-end"></i>', ), css_class="form-group col-md-4 mb-0", ), css_class="form-row", ), ButtonHolder( HTML( """ <a class="btn btn-info col-md-2" role="button" href="{% url 'rolodex:project_create_no_client' %}">Create</a> """ ), Submit("submit_btn", "Filter", css_class="btn btn-primary col-md-2"), HTML( """ <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'rolodex:projects' %}">Reset</a> """ ), ), css_class="justify-content-center", ), )
class BillFilter(django_filters.FilterSet): entry_date = django_filters.DateRangeFilter(name='entry_date', label='Date (Between)') class Meta: model = Bill fields = ['bill_num', 'provider', 'service', 'district', 'entry_date']
class productlineoperator_filter(django_filters.FilterSet): Date_word = django_filters.DateRangeFilter(label=u'Дата записи') class Meta: model = product_line_operator fields = ['Date_word']
class F(django_filters.FilterSet): published = django_filters.DateRangeFilter() class Meta: model = Article
class productpackingequipmentadjuster_filter(django_filters.FilterSet): Date_word = django_filters.DateRangeFilter(label=u'Дата записи') class Meta: model = product_packing_equipment_adjuster fields = ['Date_word']
class productequipmentbreakdownrepair_filter(django_filters.FilterSet): Date_word = django_filters.DateRangeFilter(label=u'Дата записи') class Meta: model = product_equipment_breakdown_repair fields = ['Date_word']
class ObservationFilter(mixins.CustomIsoDateTimeFilterMixin, django_filters.FilterSet): site = django_filters.MultipleChoiceFilter( choices=sorted(configdb.get_site_tuples())) enclosure = django_filters.MultipleChoiceFilter( choices=sorted(configdb.get_enclosure_tuples())) telescope = django_filters.MultipleChoiceFilter( choices=sorted(configdb.get_telescope_tuples())) time_span = django_filters.DateRangeFilter(field_name='start', label='Time Span') start_after = django_filters.IsoDateTimeFilter( field_name='start', lookup_expr='gte', label='Start After (Inclusive)', widget=forms.TextInput(attrs={ 'class': 'input', 'type': 'date' })) start_before = django_filters.IsoDateTimeFilter( field_name='start', lookup_expr='lt', label='Start Before', widget=forms.TextInput(attrs={ 'class': 'input', 'type': 'date' })) end_after = django_filters.IsoDateTimeFilter( field_name='end', lookup_expr='gte', label='End After (Inclusive)', widget=forms.TextInput(attrs={ 'class': 'input', 'type': 'date' })) end_before = django_filters.IsoDateTimeFilter( field_name='end', lookup_expr='lt', label='End Before', widget=forms.TextInput(attrs={ 'class': 'input', 'type': 'date' })) modified_after = django_filters.IsoDateTimeFilter( field_name='modified', lookup_expr='gte', label='Modified After (Inclusive)', widget=forms.TextInput(attrs={ 'class': 'input', 'type': 'date' })) request_id = django_filters.NumberFilter(field_name='request__id') request_group_id = django_filters.NumberFilter( field_name='request__request_group__id', label='Request Group ID') state = django_filters.MultipleChoiceFilter( choices=Observation.STATE_CHOICES, field_name='state') observation_type = django_filters.MultipleChoiceFilter( choices=RequestGroup.OBSERVATION_TYPES, field_name='request__request_group__observation_type', label='Observation Type') request_state = django_filters.MultipleChoiceFilter( choices=Request.STATE_CHOICES, field_name='request__state', label='Request State') proposal = django_filters.CharFilter( field_name='request__request_group__proposal__id', label='Proposal') instrument_type = django_filters.MultipleChoiceFilter( choices=sorted(configdb.get_instrument_type_tuples()), label='Instrument Type', field_name='configuration_statuses__configuration__instrument_type') configuration_type = django_filters.MultipleChoiceFilter( choices=sorted(configdb.get_configuration_type_tuples()), label='Configuration Type', field_name='configuration_statuses__configuration__type') ordering = django_filters.OrderingFilter( fields=['start', 'end', 'modified', 'created', 'state'], label='Observation ordering') class Meta: model = Observation exclude = ['start', 'end', 'request', 'created', 'modified']
class ProjectFilter(django_filters.FilterSet): """ Filter :model:`rolodex.Project` model. **Fields** ``start_date`` DateFilter for start_date values greater than provided value ``end_date`` DateFilter for end_date values less than provided value ``start_date_range`` DateRangeFilter for retrieving entries with matching start_date values ``complete`` Boolean field for filtering incomplete projects. """ start_date = django_filters.DateFilter( lookup_expr="gte", field_name="start_date", label="Start Date", widget=forms.DateInput( attrs={"type": "date", "class": "dateinput form-control"} ), ) end_date = django_filters.DateFilter( lookup_expr="lte", field_name="end_date", label="End Date", widget=forms.DateInput( attrs={"type": "date", "class": "dateinput form-control"} ), ) start_date_range = django_filters.DateRangeFilter( field_name="start_date", empty_label="-- Filter by Relative Start Date --" ) STATUS_CHOICES = ( (0, "All Projects"), (1, "Completed"), ) complete = django_filters.ChoiceFilter( choices=STATUS_CHOICES, empty_label=None, label="Project status" ) class Meta: model = Project fields = [ "complete", ] def __init__(self, *args, **kwargs): super(ProjectFilter, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = "get" self.helper.form_class = "newitem" self.helper.form_show_labels = False # Layout the form for Bootstrap self.helper.layout = Layout( Div( Row( Column( PrependedText( "start_date", '<i class="fas fa-hourglass-start"></i>' ), css_class="form-group col-md-6 mb-0", ), Column("complete", css_class="form-group col-md-6 mb-0"), css_class="form-row", ), Row( Column( PrependedText( "end_date", '<i class="fas fa-hourglass-end"></i>' ), css_class="form-group col-md-6 mb-0", ), Column("start_date_range", css_class="form-group col-md-6 mb-0"), css_class="form-row", ), ButtonHolder( Submit("submit", "Filter", css_class="btn btn-primary col-md-2"), HTML( """ <a class="btn btn-outline-secondary col-md-2" role="button" href="{% url 'rolodex:projects' %}">Reset</a> """ ), ), css_class="justify-content-center", ), )
class IssueFilter(django_filters.FilterSet): status_field = django_filters.MultipleChoiceFilter( label=_('status'), widget=forms.SelectMultiple) update_time = django_filters.DateRangeFilter( label=_('data_poslednego_izmenenija')) responsible = django_filters.MultipleChoiceFilter( label=_('proverjaushij'), widget=forms.SelectMultiple) followers = django_filters.MultipleChoiceFilter( label=_('nabludateli'), widget=forms.SelectMultiple) students = django_filters.MultipleChoiceFilter(name="student", label=_('studenty'), widget=forms.SelectMultiple) seminars = django_filters.MultipleChoiceFilter(name="task__parent_task", label=_('uroki'), widget=forms.SelectMultiple) task = django_filters.MultipleChoiceFilter(label=_('zadacha'), widget=forms.SelectMultiple) def set_course(self, course, user): default_choices = {} lang = user.get_profile().language for field in self.filters: self.filters[field].field.label = u'<strong>{0}</strong>'.format( self.filters[field].field.label) teacher_choices = [] for teacher in course.get_teachers(): teacher_choices.append((teacher.id, teacher.get_full_name())) if teacher.id == user.id: default_choices['responsible'] = [str(teacher.id)] self.filters['responsible'].field.choices = tuple(teacher_choices) self.filters['followers'].field.choices = tuple(teacher_choices) students_choices = [(teacher.id, teacher.get_full_name()) for teacher in course.get_students()] self.filters['students'].field.choices = tuple(students_choices) tasks_all = Task.objects\ .filter(course=course)\ .exclude(type=Task.TYPE_MATERIAL)\ .distinct() seminars = tasks_all.filter(type=Task.TYPE_SEMINAR) task_choices = [(task.id, task.get_title(lang)) for task in seminars] self.filters['seminars'].field.choices = tuple(task_choices) tasks = tasks_all.exclude(type=Task.TYPE_SEMINAR) task_choices = [(task.id, task.get_title(lang)) for task in tasks] self.filters['task'].field.choices = tuple(task_choices) status_choices = [] for status in course.issue_status_system.statuses.exclude( tag=IssueStatus.STATUS_SEMINAR): status_choices.append((status.id, status.get_name(lang))) if status.tag == Issue.STATUS_VERIFICATION and default_choices: default_choices['status_field'] = [str(status.id)] for status_id in sorted(IssueStatus.HIDDEN_STATUSES.values(), reverse=True): status_field = IssueStatus.objects.get(pk=status_id) status_choices.insert( 0, (status_field.id, status_field.get_name(lang))) self.filters['status_field'].field.choices = tuple(status_choices) return default_choices def set_data(self, data): self.data_full = data @property def qs(self): issues = super(IssueFilter, self).qs issues_count = len(issues) lang = self.data_full.get('lang', settings.LANGUAGE_CODE) timezone = self.data_full.get('timezone', settings.TIME_ZONE) start = int(self.data_full.get('start', 0)) end = start + int(self.data_full.get('length', 50)) data = [] issues = issues[start:end] for issue in issues: student = issue.student responsible = issue.responsible data.append({ "start": start, "has_issue_access": issue.task.has_issue_access(), "issue_url": issue.get_absolute_url(), "student_url": student.get_absolute_url(), "student_name": u'%s %s' % (student.last_name, student.first_name), "task_title": issue.task.get_title(lang), "update_time": issue.update_time.astimezone( timezone_pytz(timezone)).strftime('%d-%m-%Y %H:%M'), "mark": float(issue.score()), "status_name": issue.status_field.get_name(lang), "status_color": issue.status_field.color, "responsible_url": responsible.get_absolute_url() if responsible else "", "responsible_name": u'%s %s' % (responsible.last_name, responsible.first_name) if responsible else "", "DT_RowId": "row_issue_" + str(issue.id), "DT_RowData": { "id": issue.id }, }) self.response = { 'draw': self.data_full.get('draw', None), 'recordsTotal': issues_count, 'recordsFiltered': issues_count, 'data': data, 'url': "queue?" + self.data_full.get('filter', ''), } return Issue.objects.none() class Meta: model = Issue fields = [ 'students', 'responsible', 'followers', 'seminars', 'task', 'status_field', 'update_time' ]
class WeeklyFilter(django_filters.FilterSet): Date_Received = django_filters.DateRangeFilter() class Meta: model = Rentals fields = ['Date_Received']
class StrainerFilter(df.FilterSet): change_date = df.DateRangeFilter(label='Выберите период', choices=None) class Meta: model = StrainerChange fields = ['title', 'location', 'maker']
class AdviceFilter(CrispyFilterMixin, django_filters.FilterSet): subject = django_filters.CharFilter(label=_("Subject"), lookup_expr="icontains") advicer = UserChoiceFilter(label=_("Advicer")) created_by = UserChoiceFilter(label=_("Created by")) created_on = django_filters.DateRangeFilter(label=_("Created on")) community = AreaFilter( label=_("Community"), widget=autocomplete.ModelSelect2(url="teryt:community-autocomplete"), ) class Meta: model = Advice fields = [ "advicer", "created_by", "created_on", "area", "issues", "person_kind", "institution_kind", "helped", "subject", ] order_by = ( ("created_on", _("Creation date")), ("modified_on", _("Modification date")), ("id", _("ID")), ("advicer", _("Advicer")), ("person_kind", _("Person kind")), ("institution_kind", _("Institution kind")), ) @property def form(self): self._form = super(CrispyFilterMixin, self).form self._form.helper = FormHelper(self._form) self._form.helper.form_method = "get" self._form.helper.form_class = "form-inline" self._form.helper.include_media = False self._form.helper.layout = Layout( Fieldset( _("Statistic data"), Div( Div("area", css_class="col-sm-12 col-md-4"), Div("issues", css_class="col-sm-12 col-md-4"), Div("person_kind", css_class="col-sm-12 col-md-4"), css_class="row", ), Div( Div("institution_kind", css_class="col-sm-12 col-md-3"), Div("helped", css_class="col-sm-12 col-md-3"), Div("community", css_class="col-sm-12 col-md-3"), css_class="row", ), ), Fieldset(_("Details"), "advicer", "created_by", "created_on", "subject"), ) self._form.helper.add_input(Submit("filter", _("Filter"))) return self._form
class WarFilter(django_filters.FilterSet): date = django_filters.DateRangeFilter() class Meta: model = War fields = ['date']