<commit_before>import django_filters

from brambling.forms.organizer import AttendeeFilterSetForm
from brambling.models import Attendee, ItemOption, Discount, Order


class AttendeeFilterSet(django_filters.FilterSet):
    """
    FilterSet for attendees of an event. Requires the event as its first argument.

    """

    def __init__(self, event, *args, **kwargs):
        "Limit the Item Option list to items belonging to this event."

        super(AttendeeFilterSet, self).__init__(*args, **kwargs)
        self.event = event
        self.filters['bought_items__item_option'].extra.update({
            'queryset': ItemOption.objects.filter(item__event=self.event),
            'empty_label': 'Any Items',
        })
        self.filters['bought_items__discounts__discount'].extra.update({
            'queryset': Discount.objects.filter(event=self.event),
            'empty_label': 'Any Discounts',
        })
        if not event.collect_housing_data:
            del self.filters['housing_status']

    @property
    def form(self):
        if not hasattr(self, '_form'):
            if self.is_bound:
                self._form = AttendeeFilterSetForm(self.data, prefix=self.form_prefix)
            else:
                self._form = AttendeeFilterSetForm(prefix=self.form_prefix)
        return self._form

    class Meta:
        model = Attendee
        fields = ['bought_items__item_option', 'housing_status',
                  'bought_items__discounts__discount']
        order_by = ['surname', '-surname', 'given_name', '-given_name']


class OrderFilterSet(django_filters.FilterSet):
    class Meta:
        model = Order
        fields = ['providing_housing', 'send_flyers']
<commit_msg>Implemented basic FloppyFilterSet. Resolved #144. Related: alex/django-filter#161<commit_after>import copy

from django.db import models
import django_filters
import floppyforms.__future__ as forms
from floppyforms.__future__.models import FORMFIELD_OVERRIDES

from brambling.forms.organizer import AttendeeFilterSetForm
from brambling.models import Attendee, ItemOption, Discount, Order


FILTER_FIELD_OVERRIDES = copy.deepcopy(FORMFIELD_OVERRIDES)
FILTER_FIELD_OVERRIDES[models.BooleanField] = {'form_class': forms.NullBooleanField}


class FloppyFilterSet(django_filters.FilterSet):
    class Meta:
        form = forms.Form

    @classmethod
    def filter_for_field(cls, f, name):
        filter_ = super(FloppyFilterSet, cls).filter_for_field(f, name)
        filter_.field_class = FILTER_FIELD_OVERRIDES[f.__class__]['form_class']
        return filter_


class AttendeeFilterSet(django_filters.FilterSet):
    """
    FilterSet for attendees of an event. Requires the event as its first argument.

    """

    def __init__(self, event, *args, **kwargs):
        "Limit the Item Option list to items belonging to this event."

        super(AttendeeFilterSet, self).__init__(*args, **kwargs)
        self.event = event
        self.filters['bought_items__item_option'].extra.update({
            'queryset': ItemOption.objects.filter(item__event=self.event),
            'empty_label': 'Any Items',
        })
        self.filters['bought_items__discounts__discount'].extra.update({
            'queryset': Discount.objects.filter(event=self.event),
            'empty_label': 'Any Discounts',
        })
        if not event.collect_housing_data:
            del self.filters['housing_status']

    @property
    def form(self):
        if not hasattr(self, '_form'):
            if self.is_bound:
                self._form = AttendeeFilterSetForm(self.data, prefix=self.form_prefix)
            else:
                self._form = AttendeeFilterSetForm(prefix=self.form_prefix)
        return self._form

    class Meta:
        model = Attendee
        fields = ['bought_items__item_option', 'housing_status',
                  'bought_items__discounts__discount']
        order_by = ['surname', '-surname', 'given_name', '-given_name']


class OrderFilterSet(FloppyFilterSet):
    class Meta:
        model = Order
        fields = ['providing_housing', 'send_flyers']
        form = forms.Form

{'fraction_non_alphanumeric': 0.09968392900559203, 'fraction_numerical': 0.0014587892049598833, 'mean_word_length': 3.0372914622178606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1637273', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1191, 'n_words': 256}